using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Grid; using Uninpho.Tools.components.DataManager; using Uninpho.DBOperation.Operation; using Uninpho.DBOperation.Model; using DevExpress.XtraGrid.Localization; using Uninpho.Tools.components; using Uninpho.Railway.Waveform; using System.Linq; namespace Uninpho.Tools { public partial class DMCtrl : DevExpress.XtraEditors.XtraUserControl { List colums = new List(); object dataSource = null; bool Init = false; Dictionary filterCondition = new Dictionary(); public GridView gridView { get { return this.dmGrid1.gridView; } } public DMCtrl() { InitializeComponent(); } #region 事件 /// /// 趋势分析 /// /// /// private void simpleButton1_Click(object sender, EventArgs e) { if (this.gridView.SelectedRowsCount >= 2) { int[] idx = this.gridView.GetSelectedRows(); List rows = new List(); foreach (var item in idx) { //string rq = this.gridView.GetRowCellDisplayText(item, "jcrq"); //if (string.IsNullOrEmpty(rq)) //{ // XtraMessageBox.Show("检测日期为空", "提示"); // return; //} //else rows.Add(this.gridView.GetRow(item)); } List pzlgl = new List(); List pzjh = new List(); var lglMeta = MetaDataCtrl.GetMetaData("t_lunguili_account"); var jhfxMeta = MetaDataCtrl.GetMetaData("t_jihefenxi_account"); List listarr = new List(); List listarr1 = new List(); fillDataqs(lglMeta, rows, ref pzlgl, ref listarr); fillDataqs(jhfxMeta, rows,ref pzjh,ref listarr1); listarr = listarr.Union(listarr1).ToList(); //var pzda = pzlgl.Union(pzjh).ToList(); List pzda = null; QSFXForm frm = new QSFXForm(ConvDict(listarr), pzda); frm.StartPosition = FormStartPosition.CenterParent; frm.ShowDialog(); //FrmAnalyze frm = new FrmAnalyze("趋势分析"); //frm.LoadQSFXData(rows); //frm.StartPosition = FormStartPosition.CenterParent; //frm.ShowDialog(this); } else { XtraMessageBox.Show("请选择两条以上需要分析的数据", "提示"); } } /// /// 把List转为Dictionary<> /// private Dictionary ConvDict(List listdata) { Dictionary dict = new Dictionary(); for (int i = 0; i < listdata.Count; i++) { if (!dict.ContainsKey(listdata[i].ListId)) { dict.Add(listdata[i].ListId, listdata[i]); } } return dict; } /// /// /// /// /// private void fillDataqs(List dataMeta, List rows,ref List pzdada ,ref List coorlist) { List listarr = new List(); List pzda = new List(); dataMeta.ForEach(column => { if (column.ttype == "number" && column.chname != "序号") { CoorListClass newlist = new CoorListClass(); newlist.ListId = column.name; newlist.ListName = column.chname; pzda.Add(new PZClass() { Id= newlist.ListId, Name = newlist.ListName }); newlist.Scale = 1; newlist.Width = 5; newlist.Offset = 0.001; newlist.RGBA = new int[] { 0, 200, 255, 255 }; newlist.CoorList = new List(); newlist.qsfxXstring = new List(); float i = 1.0F; foreach (var row in rows) { string riqi = getRowData(row, "jcrq").ToString(); newlist.qsfxXstring.Add(riqi); object objVal = getRowData(row, column.name); if (objVal != null && objVal.ToString() != "") { newlist.CoorList.Add(new PointF(i, (float)Convert.ToDecimal(objVal.ToString()))); } i = i + 1.0F; } if (newlist.CoorList.Count != 0) { listarr.Add(newlist); } } }); coorlist = listarr; pzdada = pzda; } private object getRowData(object row, string column) { object val = ""; foreach (var item in (IDictionary)row) { if (column.ToLower() == item.Key.ToLower()) { val = item.Value; break; } } return val; } private bool isEqual(int[] rowIds, string name) { bool isEqual = false; for (int i=0;i< rowIds.Length-1;i++) { isEqual = this.gridView.GetRowCellDisplayText(rowIds[i], name) == this.gridView.GetRowCellDisplayText(rowIds[i + 1], name); } return isEqual; } /// /// 查看波形图 /// /// /// private void repositoryItemHyperLinkEdit1_Click(object sender, EventArgs e) { int[] rowhandles = this.gridView.GetSelectedRows(); int rowhandle = this.gridView.FocusedRowHandle; String yswjm_lgl = this.gridView.GetRowCellDisplayText(rowhandle, "yswjm"); String yswjm_jhfx = this.gridView.GetRowCellDisplayText(rowhandle, "yswjm_jhfx"); if (string.IsNullOrEmpty(yswjm_lgl) && string.IsNullOrEmpty(yswjm_lgl)) { XtraMessageBox.Show("波形数据为空!", "提示"); return; } else { FrmAnalyze anaFrm = new FrmAnalyze("波形查看"); anaFrm.StartPosition = FormStartPosition.CenterParent; anaFrm.LoadBXZSData(new List() { yswjm_lgl }, new List() { yswjm_jhfx }); anaFrm.ShowDialog(this); } } /// /// 波形分析 /// /// /// private void simpleButton3_Click(object sender, EventArgs e) { if (this.gridView.SelectedRowsCount == 2) { int[] idx = this.gridView.GetSelectedRows(); List yswjm_jhfx = new List(); List yswjm_lgl = new List(); //string rq1 = this.gridView.GetRowCellDisplayText(idx[0], "jcrq"); //string rq2 = this.gridView.GetRowCellDisplayText(idx[1], "jcrq"); //if (string.IsNullOrEmpty(rq1)|| string.IsNullOrEmpty(rq2)) //{ // XtraMessageBox.Show("提示", "检测日期为空"); // return; //} string jcrq=""; if (isEqual(idx, "xlm") && isEqual(idx, "xingbie") && isEqual(idx, "dcbh")) { foreach (int id in idx) { string val = this.gridView.GetRowCellDisplayText(id, "yswjm_jhfx"); if (!string.IsNullOrEmpty(val)) yswjm_jhfx.Add(val); val = this.gridView.GetRowCellDisplayText(id, "yswjm"); if (!string.IsNullOrEmpty(val)) { yswjm_lgl.Add(val); } else { } if (string.IsNullOrEmpty(jcrq)) jcrq += this.gridView.GetRowCellDisplayText(id, "jcrq"); else jcrq += " , " + this.gridView.GetRowCellDisplayText(id, "jcrq"); } if (yswjm_jhfx.Count == 2 || yswjm_lgl.Count == 2) { BXDBFrom frm = new BXDBFrom(yswjm_lgl, yswjm_jhfx); frm.StartPosition = FormStartPosition.CenterParent; frm.ShowDialog(); //FrmAnalyze frm = new FrmAnalyze("波形分析"); //frm.LoadBXZSData(yswjm_lgl, yswjm_jhfx); //frm.SetJCRQ(string.Format("检测日期:{0}",jcrq)); //frm.StartPosition = FormStartPosition.CenterParent; //frm.ShowDialog(this); } else { XtraMessageBox.Show( "波形数据为空,请重新选择两条需要分析的数据", "提示"); } } else { XtraMessageBox.Show("线路名 行别 道岔编号不一致,请重新选择两条需要分析的数据", "提示"); } } else { XtraMessageBox.Show("选择的数据不符合分析条件,请重新选择两条需要分析的数据", "提示"); } } /// /// 阈值设置 /// /// /// private void btn_dm_settting_Click(object sender, EventArgs e) { FrmSetting frm = new FrmSetting(filterCondition); frm.StartPosition = FormStartPosition.CenterParent; if (frm.ShowDialog(this) == DialogResult.OK) { this.FilterData(frm.Condition); } } /// /// 导出Excel /// /// /// private void simpleButton2_Click(object sender, EventArgs e) { int[] rowhandles = this.gridView.GetSelectedRows(); if (rowhandles.Length > 0) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { this.gridView.OptionsPrint.PrintSelectedRowsOnly = true; DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions(); this.gridView.ExportToXls(saveFileDialog.FileName, options); XtraMessageBox.Show("导出成功"); this.gridView.OptionsPrint.PrintSelectedRowsOnly = false; } } else { XtraMessageBox.Show("请勾选数据"); } } /// /// 查询 /// /// /// private void btn_dm_query_Click(object sender, EventArgs e) { this.dmGrid1.FilterDate(this.dateEdit1.DateTime, this.dateEdit2.DateTime); } /// /// 重置 /// /// /// private void simpleButton4_Click(object sender, EventArgs e) { this.dateEdit1.EditValue = null; this.dateEdit2.EditValue = null; this.dmGrid1.resetTable(); } /// /// 数据阈值过滤 /// /// private void FilterData(Dictionary condition) { string strSQL = ""; filterCondition = condition; foreach (KeyValuePair kvp in condition) { if (string.IsNullOrEmpty(strSQL)) strSQL = string.Format("[{0}] <= {1} or [{0}] >= {2}", kvp.Key, kvp.Value - 2 * kvp.Value, kvp.Value); else { strSQL += string.Format(" And [{0}] <= {1} or [{0}] >= {2}", kvp.Key, kvp.Value - 2 * kvp.Value, kvp.Value); } } this.gridView.ActiveFilterString = strSQL;// "[cxsd] != 30.0m"; } private void InverseSelection() { int count = this.gridView.RowCount; for (int i = 0; i < count; i++) { this.gridView.InvertRowSelection(i); } } private void checkEdit1_CheckedChanged(object sender, EventArgs e) { if (checkEdit1.Checked) { this.gridView.SelectAll(); } else { this.gridView.SelectRows(0, 0); } } private void checkEdit2_CheckedChanged(object sender, EventArgs e) { InverseSelection(); } #endregion private void dmGrid1_Load(object sender, EventArgs e) { } private void btn_dm_ref_Click(object sender, EventArgs e) { this.dmGrid1.LoadData(); } /// /// 删除 /// private void delBtn_Click(object sender, EventArgs e) { if (UserInform.userinf.Pow == 0) { XtraMessageBox.Show("您无权删除数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int[] rowhandles = this.gridView.GetSelectedRows(); if (rowhandles.Length == 0) { XtraMessageBox.Show("请选中删除的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (XtraMessageBox.Show("是否删除所选?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { foreach (int item in rowhandles) { string jhbxids = this.gridView.GetRowCellDisplayText(item, "yswjm_jhfx"); string lglbxids = this.gridView.GetRowCellDisplayText(item, "yswjm"); string xlm = this.gridView.GetRowCellDisplayText(item, "xlm"); string hangbie = this.gridView.GetRowCellDisplayText(item, "xingbie"); string jgjlc = this.gridView.GetRowCellDisplayText(item, "jgjlc"); //string glgid = this.gridView.GetRowCellDisplayText(item, "lgl_id"); //string jhid = this.gridView.GetRowCellDisplayText(item, "jhfx_id"); DataAnalysisToPG.DelSJZS(lglbxids, jhbxids, xlm, hangbie, jgjlc); } this.dmGrid1.LoadData(); XtraMessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } }