using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; using Uninpho.Tools.components.MTLFF; using Uninpho.DBOperation.Operation; using System.Reflection; using System.IO; namespace Uninpho.Tools.components.XXXW { public partial class ShowDataForm : DevExpress.XtraEditors.XtraForm { //grid1.FocusedView.CloseEditor(); //grid1.FocusedView.UpdateCurrentRow(); string UUID; List undataarr = new List(); List csvdataold; string nowtime = String.Empty;//记录修改时间 List newlogs = new List(); public ShowDataForm(string ID) { InitializeComponent(); this.UUID = ID; gridControl1.DataSource = DataAnalysisToPG.getfilexxxwD(ID); csvdataold = DataAnalysisToPG.getfilexxxwD(ID); } private void bandedGridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { DataAnalysis.DACommon.addXuHao(e); } /// /// 导出 /// private void saveBtn_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "csv文件(*.scv)|*.csv|txt文件(*.txt)|*.txt"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { StreamWriter sw = new StreamWriter(saveFileDialog.FileName,false, Encoding.GetEncoding("gb2312")); //sw.WriteLine("主要参数,,横杠采点,,理论调整量,,,,高低,,,,轨向,,,,导向轨,模拟调整量,,,,模拟调整后的剩余调整量,,,,,,,,附加参数,,,,,,,,,,,,,"); //sw.WriteLine("测量点,轨枕ID号,内插.,里程,高程,平面位置,水平/超高,轨距,点号.,\"高低[短波,5m]\",点号.,\"高低[长波,150m]\",点号.,\"轨向[短波,5m]\",点号.,\"轨向[长波,150m]\",导向轨,左轨高程,右轨高程,左轨平面,右轨平面,高程,\"高低[短波,5m]\",\"高低[长波,150m]\",平面位置,\"轨向[短波,5m]\",\"轨向[长波,150m]\",水平/超高,轨距,注解,ID号,设计超高,实测超高,设计轨距,实测轨距,设计5m高低,实测高低5m,设计150m高低,实测150m高低,设计5m轨向,实测5m轨向,设计150m轨向,实测150m轨向,轨向"); sw.WriteLine("主要参数,,横杠采点,,理论调整量,,,,高低,,,,轨向,,,,导向轨,附加参数,"); sw.WriteLine("测量点,轨枕ID号,内插.,里程,高程,平面位置,水平/超高,轨距,点号.,\"高低[短波,5m]\",点号.,\"高低[长波,150m]\",点号.,\"轨向[短波,5m]\",点号.,\"轨向[长波,150m]\",导向轨,注解,ID号"); var resdata = DataAnalysisToPG.getfilexxxwD(UUID); foreach (var item in resdata) { //string strone = String.Empty; //Type t = item.GetType();//获得该类的Type //foreach (PropertyInfo pi in t.GetProperties()) //{ // if (pi.Name != "Id" && pi.Name != "Listid") // { // string sp = pi.GetValue(item) as string; // strone += sp + ","; // } //} //strone = strone.Remove(strone.Length - 1); //sw.WriteLine(strone); sw.WriteLine( item.Cld + "," + item.Gzidh + "," + item.Nc + "," + item.Lc + "," + item.Gc + "," + item.Pmwz + "," + item.Spcg + "," + item.Gj + "," + item.Gddhdb + "," + item.Gddb + "," + item.Gddhcb + "," + item.Gdcb + "," + item.Gxdhdb + "," + item.Gxdb + "," + item.Gxdhcb + "," + item.Gxcb + "," + item.Dxg + "," + item.Fjzj + "," + item.Fjidh ); } sw.Close(); XtraMessageBox.Show("导出成功"); } } /// /// 启用编辑 /// private void simpleButton1_Click(object sender, EventArgs e) { if (!bandedGridView1.OptionsBehavior.Editable) { if (UserInform.userinf.Pow == 0) { XtraMessageBox.Show("您没有权限执行编辑操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { GengxinrenForm GX = new GengxinrenForm(); if (GX.ShowDialog() == DialogResult.OK) { bandedGridView1.OptionsBehavior.Editable = true; nowtime = DateTime.Now.ToString(); EditBtn.Text = "结束编辑"; XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已启用编辑!再次点击结束编辑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { bandedGridView1.OptionsBehavior.Editable = false; EditBtn.Text = "编辑"; XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已结束编辑!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } /// /// 添加行 /// private void AddRowBtn_Click(object sender, EventArgs e) { if (!bandedGridView1.OptionsBehavior.Editable) { XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DataAnalysisToPG.Insertdata_CsvData(new List() { new DBOperation.Model.T_xxxw_csvdata() { Listid = UUID } }); DataAnalysisToPG.UpdataToPGXXXWL(UserInform.userinf.Username, DateTime.Now.ToString(), UUID); csvdataold = DataAnalysisToPG.getfilexxxwD(UUID); gridControl1.DataSource = DataAnalysisToPG.getfilexxxwD(UUID); } } /// /// 实时更新数据库 /// private async void bandedGridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { await Task.Run(() => { //收集变化的值 string nana = bandedGridView1.FocusedColumn.FieldName; string Caption = bandedGridView1.FocusedColumn.Caption; string val = bandedGridView1.GetRowCellValue(e.RowHandle, nana).ToString(); string uuid = bandedGridView1.GetRowCellValue(e.RowHandle, "Id").ToString(); undataarr.Add(new string[] { nana,val,uuid }); //DataAnalysisToPG.UpdataToPGXXXWD(nana.ToLower(), val, uuid); //判断这个变化的cell之前是否记录过 List isExitLog = newlogs.FindAll(delegate (StaticLogClass log) { return log.Row == uuid.ToString() && log.Column == Caption; }); if (isExitLog.Count > 0) { //记录过 var changedd = newlogs.Where(c => c.Column == Caption && c.Row == uuid).First(); if (changedd.Oldvalue == val) { //如果新值与原始的值相等,则相当于没变化,删除这条记录 newlogs.Remove(changedd); } else { //不相等则更新新值 changedd.Newvalue = val; } } else { //没记录过,新建 StaticLogClass sc = new StaticLogClass(); sc.Column = Caption; sc.Row = uuid; sc.Username = UserInform.userinf.Username; sc.Newvalue = val; //获取数据库中变化的这条数据 var oneoldvalue = csvdataold.Find(delegate (DBOperation.Model.T_xxxw_csvdata ones) { return ones.Id == uuid; }); //通过filedname获取变化的属性 Type t = oneoldvalue.GetType();//获得该类的Type foreach (PropertyInfo pi in t.GetProperties()) { if (pi.Name == nana) { //记录旧值 sc.Oldvalue = pi.GetValue(oneoldvalue) as string; break; } } sc.Date = nowtime; newlogs.Add(sc); } }); } /// /// 删除行 /// private void delrowBTN_Click(object sender, EventArgs e) { if (UserInform.userinf.Pow == 0) { XtraMessageBox.Show("您没有权限执行删除操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (!bandedGridView1.OptionsBehavior.Editable) { XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int rowhandle = bandedGridView1.GetFocusedDataSourceRowIndex(); string uuid = bandedGridView1.GetRowCellValue(rowhandle, "Id").ToString(); if (XtraMessageBox.Show("是否删除所选?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { DataAnalysisToPG.DelToPGXXXWD(uuid); gridControl1.DataSource = DataAnalysisToPG.getfilexxxwD(UUID); DataAnalysisToPG.UpdataToPGXXXWL(UserInform.userinf.Username, DateTime.Now.ToString(), UUID); bandedGridView1.OptionsBehavior.Editable = true; XtraMessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } private void ShowDataForm_FormClosed(object sender, FormClosedEventArgs e) { ExcelTools.gridControl03.DataSource = DataAnalysisToPG.getfilexxxwL(); } private void ShowDataForm_FormClosing(object sender, FormClosingEventArgs e) { undataarr.Clear(); } /// /// 保存 /// private void updataBtn_Click(object sender, EventArgs e) { if (!bandedGridView1.OptionsBehavior.Editable) { XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { for (int i = 0; i < undataarr.Count; i++) { DataAnalysisToPG.UpdataToPGXXXWD(undataarr[i][0].ToLower(), undataarr[i][1], undataarr[i][2]); } DataAnalysisToPG.UpdataToPGXXXWL(UserInform.userinf.Username, DateTime.Now.ToString(), UUID); undataarr.Clear(); LogGeneratorFun.WriteLogJT(newlogs, Application.StartupPath + "//log//xx_" + UUID + ".log"); newlogs.Clear(); bandedGridView1.OptionsBehavior.Editable = false; EditBtn.Text = "编辑"; XtraMessageBox.Show("保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void XGJLBtn_Click(object sender, EventArgs e) { LoggingForm frm = new LoggingForm(Application.StartupPath + "//log//xx_" + UUID + ".log",true, csvdataold); frm.StartPosition = FormStartPosition.CenterParent; frm.Show(this); } } }