123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- 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<GridColumn> colums = new List<GridColumn>();
- object dataSource = null;
- bool Init = false;
- Dictionary<string, decimal> filterCondition = new Dictionary<string, decimal>();
- public GridView gridView { get { return this.dmGrid1.gridView; } }
- public DMCtrl()
- {
- InitializeComponent();
- }
-
-
- #region 事件
- /// <summary>
- /// 趋势分析
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void simpleButton1_Click(object sender, EventArgs e)
- {
- if (this.gridView.SelectedRowsCount >= 2)
- {
- int[] idx = this.gridView.GetSelectedRows();
- List<object> rows = new List<object>();
- 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<PZClass> pzlgl = new List<PZClass>();
- List<PZClass> pzjh = new List<PZClass>();
- var lglMeta = MetaDataCtrl.GetMetaData("t_lunguili_account");
- var jhfxMeta = MetaDataCtrl.GetMetaData("t_jihefenxi_account");
- List<CoorListClass> listarr = new List<CoorListClass>();
- List<CoorListClass> listarr1 = new List<CoorListClass>();
- 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<PZClass> 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("请选择两条以上需要分析的数据", "提示");
- }
- }
- /// <summary>
- /// 把List<CoorListClass>转为Dictionary<>
- /// </summary>
- private Dictionary<string,CoorListClass> ConvDict(List<CoorListClass> listdata)
- {
- Dictionary<string, CoorListClass> dict = new Dictionary<string, CoorListClass>();
- for (int i = 0; i < listdata.Count; i++)
- {
- if (!dict.ContainsKey(listdata[i].ListId))
- {
- dict.Add(listdata[i].ListId, listdata[i]);
- }
- }
- return dict;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="dataMeta"></param>
- /// <param name="rows"></param>
- private void fillDataqs(List<T_metadata_account> dataMeta, List<object> rows,ref List<PZClass> pzdada ,ref List<CoorListClass> coorlist)
- {
- List<CoorListClass> listarr = new List<CoorListClass>();
- List<PZClass> pzda = new List<PZClass>();
- 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<PointF>();
- newlist.qsfxXstring = new List<string>();
- 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<string, object>)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;
- }
- /// <summary>
- /// 查看波形图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<string>() { yswjm_lgl }, new List<string>() { yswjm_jhfx });
- anaFrm.ShowDialog(this);
- }
- }
-
- /// <summary>
- /// 波形分析
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void simpleButton3_Click(object sender, EventArgs e)
- {
- if (this.gridView.SelectedRowsCount == 2)
- {
- int[] idx = this.gridView.GetSelectedRows();
- List<string> yswjm_jhfx = new List<string>();
- List<string> yswjm_lgl = new List<string>();
- //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("选择的数据不符合分析条件,请重新选择两条需要分析的数据", "提示");
- }
- }
- /// <summary>
- /// 阈值设置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
-
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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("请勾选数据");
- }
-
- }
- /// <summary>
- /// 查询
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_dm_query_Click(object sender, EventArgs e)
- {
- this.dmGrid1.FilterDate(this.dateEdit1.DateTime, this.dateEdit2.DateTime);
- }
- /// <summary>
- /// 重置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void simpleButton4_Click(object sender, EventArgs e)
- {
- this.dateEdit1.EditValue = null;
- this.dateEdit2.EditValue = null;
- this.dmGrid1.resetTable();
- }
-
- /// <summary>
- /// 数据阈值过滤
- /// </summary>
- /// <param name="condition"></param>
- private void FilterData(Dictionary<string,decimal> condition)
- {
- string strSQL = "";
- filterCondition = condition;
- foreach (KeyValuePair<string, decimal> 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();
- }
- /// <summary>
- /// 删除
- /// </summary>
- 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);
- }
- }
- }
- }
- }
- }
|