LookDataFromMTLF.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.Grid;
  12. using Uninpho.DBOperation.Operation;
  13. using System.IO;
  14. using DevExpress.Spreadsheet;
  15. namespace Uninpho.Tools.components.MTLFF
  16. {
  17. public partial class LookDataFromMTLF : DevExpress.XtraEditors.XtraForm
  18. {
  19. string url;
  20. string uuid;
  21. int row;
  22. GridView gv;
  23. string nowtime = String.Empty;//记录修改时间
  24. List<StaticLogClass> newlogs = new List<StaticLogClass>();
  25. public LookDataFromMTLF(string url, GridView gv, int row)
  26. {
  27. InitializeComponent();
  28. this.url = url;
  29. this.uuid = gv.GetRowCellValue(row, "Id").ToString();
  30. this.row = row;
  31. this.gv = gv;
  32. sheetControl01.LoadDocument(url);
  33. sheetControl01.ReadOnly = true;
  34. }
  35. private void simpleButton1_Click(object sender, EventArgs e)
  36. {
  37. SaveFileDialog sfd = new SaveFileDialog();
  38. sfd.Filter = "xlsx files(*.xlsx)|*.xlsx|xlsx files(*.xlsx)|*.xlsx|All files(*.*)|*.*";
  39. sfd.FileName = "道岔全面检查记录表";//道岔全面检查记录表
  40. if (sfd.ShowDialog() == DialogResult.OK)
  41. {
  42. sheetControl01.SaveDocument(sfd.FileName);
  43. XtraMessageBox.Show("导出完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  44. //this.Close();
  45. }
  46. }
  47. /// <summary>
  48. /// 开始编辑
  49. /// </summary>
  50. private void EditBtn_Click(object sender, EventArgs e)
  51. {
  52. if (UserInform.userinf.Pow == 0)
  53. {
  54. XtraMessageBox.Show("您没有权限执行删除操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  55. }
  56. else
  57. {
  58. if (sheetControl01.ReadOnly)
  59. {
  60. GengxinrenForm GX = new GengxinrenForm();
  61. if (GX.ShowDialog() == DialogResult.OK)
  62. {
  63. sheetControl01.ReadOnly = false;
  64. nowtime = DateTime.Now.ToString();
  65. EditBtn.Text = "结束编辑";
  66. XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已启用编辑!再次点击结束编辑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  67. }
  68. }
  69. else
  70. {
  71. sheetControl01.ReadOnly = true;
  72. EditBtn.Text = "编辑";
  73. XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已结束编辑!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// 保存
  79. /// </summary>
  80. private void reKeepBtn_Click(object sender, EventArgs e)
  81. {
  82. if (sheetControl01.ReadOnly)
  83. {
  84. XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  85. }
  86. else
  87. {
  88. sheetControl01.SaveDocument(url);
  89. string btyearr = ExcelTools.GetFileData(url);
  90. string datee = DateTime.Now.ToString();
  91. DBOperation.Model.T_mitielifeng_filelist tm = MTLFCommon.updataListMessage(gv, url, row);
  92. gv.SetRowCellValue(row, "Excelbytearr", btyearr);
  93. gv.SetRowCellValue(row, "Gengxinren", UserInform.userinf.Username);
  94. gv.SetRowCellValue(row, "Gengxinriqi", datee);
  95. tm.Id = uuid;
  96. tm.Excelbytearr = btyearr;
  97. tm.Gengxinren = UserInform.userinf.Username;
  98. tm.Gengxinriqi = datee;
  99. DataAnalysisToPG.UpdataToPGMTLF(tm);
  100. LogGeneratorFun.WriteLogJT(newlogs, Application.StartupPath + "//log//mt_" + uuid + ".log");
  101. newlogs.Clear();
  102. sheetControl01.ReadOnly = true;
  103. EditBtn.Text = "编辑";
  104. XtraMessageBox.Show("保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  105. }
  106. }
  107. private async void sheetControl01_CellValueChanged(object sender, DevExpress.XtraSpreadsheet.SpreadsheetCellEventArgs e)
  108. {
  109. await Task.Run(() =>
  110. {
  111. List<StaticLogClass> isExitLog = newlogs.FindAll(delegate (StaticLogClass log)
  112. {
  113. return int.Parse(log.Row) == e.RowIndex && int.Parse(log.Column) == e.ColumnIndex;
  114. });
  115. if (isExitLog.Count > 0)
  116. {
  117. var changedd = newlogs.Where(c => int.Parse(c.Column) == e.ColumnIndex && int.Parse(c.Row) == e.RowIndex).First();
  118. changedd.Newvalue = e.Value.ToString();
  119. }
  120. else
  121. {
  122. StaticLogClass sc = new StaticLogClass();
  123. sc.Column = e.ColumnIndex.ToString();
  124. sc.Row = e.RowIndex.ToString();
  125. sc.Username = UserInform.userinf.Username;
  126. sc.Newvalue = e.Value.ToString();
  127. sc.Oldvalue = e.OldValue.ToString();
  128. sc.Date = nowtime;
  129. newlogs.Add(sc);
  130. }
  131. });
  132. }
  133. private void XGJLBtn_Click(object sender, EventArgs e)
  134. {
  135. LoggingForm frm = new LoggingForm(Application.StartupPath + "//log//mt_" + uuid + ".log");
  136. frm.StartPosition = FormStartPosition.CenterParent;
  137. frm.Show(this);
  138. }
  139. }
  140. }