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 DevExpress.XtraGrid.Views.Grid; using Uninpho.DBOperation.Operation; using System.IO; using DevExpress.Spreadsheet; namespace Uninpho.Tools.components.MTLFF { public partial class LookDataFromMTLF : DevExpress.XtraEditors.XtraForm { string url; string uuid; int row; GridView gv; string nowtime = String.Empty;//记录修改时间 List newlogs = new List(); public LookDataFromMTLF(string url, GridView gv, int row) { InitializeComponent(); this.url = url; this.uuid = gv.GetRowCellValue(row, "Id").ToString(); this.row = row; this.gv = gv; sheetControl01.LoadDocument(url); sheetControl01.ReadOnly = true; } private void simpleButton1_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "xlsx files(*.xlsx)|*.xlsx|xlsx files(*.xlsx)|*.xlsx|All files(*.*)|*.*"; sfd.FileName = "道岔全面检查记录表";//道岔全面检查记录表 if (sfd.ShowDialog() == DialogResult.OK) { sheetControl01.SaveDocument(sfd.FileName); XtraMessageBox.Show("导出完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.Close(); } } /// /// 开始编辑 /// private void EditBtn_Click(object sender, EventArgs e) { if (UserInform.userinf.Pow == 0) { XtraMessageBox.Show("您没有权限执行删除操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (sheetControl01.ReadOnly) { GengxinrenForm GX = new GengxinrenForm(); if (GX.ShowDialog() == DialogResult.OK) { sheetControl01.ReadOnly = false; nowtime = DateTime.Now.ToString(); EditBtn.Text = "结束编辑"; XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已启用编辑!再次点击结束编辑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { sheetControl01.ReadOnly = true; EditBtn.Text = "编辑"; XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已结束编辑!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } /// /// 保存 /// private void reKeepBtn_Click(object sender, EventArgs e) { if (sheetControl01.ReadOnly) { XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { sheetControl01.SaveDocument(url); string btyearr = ExcelTools.GetFileData(url); string datee = DateTime.Now.ToString(); DBOperation.Model.T_mitielifeng_filelist tm = MTLFCommon.updataListMessage(gv, url, row); gv.SetRowCellValue(row, "Excelbytearr", btyearr); gv.SetRowCellValue(row, "Gengxinren", UserInform.userinf.Username); gv.SetRowCellValue(row, "Gengxinriqi", datee); tm.Id = uuid; tm.Excelbytearr = btyearr; tm.Gengxinren = UserInform.userinf.Username; tm.Gengxinriqi = datee; DataAnalysisToPG.UpdataToPGMTLF(tm); LogGeneratorFun.WriteLogJT(newlogs, Application.StartupPath + "//log//mt_" + uuid + ".log"); newlogs.Clear(); sheetControl01.ReadOnly = true; EditBtn.Text = "编辑"; XtraMessageBox.Show("保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private async void sheetControl01_CellValueChanged(object sender, DevExpress.XtraSpreadsheet.SpreadsheetCellEventArgs e) { await Task.Run(() => { List isExitLog = newlogs.FindAll(delegate (StaticLogClass log) { return int.Parse(log.Row) == e.RowIndex && int.Parse(log.Column) == e.ColumnIndex; }); if (isExitLog.Count > 0) { var changedd = newlogs.Where(c => int.Parse(c.Column) == e.ColumnIndex && int.Parse(c.Row) == e.RowIndex).First(); changedd.Newvalue = e.Value.ToString(); } else { StaticLogClass sc = new StaticLogClass(); sc.Column = e.ColumnIndex.ToString(); sc.Row = e.RowIndex.ToString(); sc.Username = UserInform.userinf.Username; sc.Newvalue = e.Value.ToString(); sc.Oldvalue = e.OldValue.ToString(); sc.Date = nowtime; newlogs.Add(sc); } }); } private void XGJLBtn_Click(object sender, EventArgs e) { LoggingForm frm = new LoggingForm(Application.StartupPath + "//log//mt_" + uuid + ".log"); frm.StartPosition = FormStartPosition.CenterParent; frm.Show(this); } } }