ShowDataForm.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 Uninpho.Tools.components.MTLFF;
  12. using Uninpho.DBOperation.Operation;
  13. using System.Reflection;
  14. using System.IO;
  15. namespace Uninpho.Tools.components.XXXW
  16. {
  17. public partial class ShowDataForm : DevExpress.XtraEditors.XtraForm
  18. {
  19. //grid1.FocusedView.CloseEditor();
  20. //grid1.FocusedView.UpdateCurrentRow();
  21. string UUID;
  22. List<string[]> undataarr = new List<string[]>();
  23. List<DBOperation.Model.T_xxxw_csvdata> csvdataold;
  24. string nowtime = String.Empty;//记录修改时间
  25. List<StaticLogClass> newlogs = new List<StaticLogClass>();
  26. public ShowDataForm(string ID)
  27. {
  28. InitializeComponent();
  29. this.UUID = ID;
  30. gridControl1.DataSource = DataAnalysisToPG.getfilexxxwD(ID);
  31. csvdataold = DataAnalysisToPG.getfilexxxwD(ID);
  32. }
  33. private void bandedGridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  34. {
  35. DataAnalysis.DACommon.addXuHao(e);
  36. }
  37. /// <summary>
  38. /// 导出
  39. /// </summary>
  40. private void saveBtn_Click(object sender, EventArgs e)
  41. {
  42. SaveFileDialog saveFileDialog = new SaveFileDialog();
  43. saveFileDialog.Filter = "csv文件(*.scv)|*.csv|txt文件(*.txt)|*.txt";
  44. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  45. {
  46. StreamWriter sw = new StreamWriter(saveFileDialog.FileName,false, Encoding.GetEncoding("gb2312"));
  47. //sw.WriteLine("主要参数,,横杠采点,,理论调整量,,,,高低,,,,轨向,,,,导向轨,模拟调整量,,,,模拟调整后的剩余调整量,,,,,,,,附加参数,,,,,,,,,,,,,");
  48. //sw.WriteLine("测量点,轨枕ID号,内插.,里程,高程,平面位置,水平/超高,轨距,点号.,\"高低[短波,5m]\",点号.,\"高低[长波,150m]\",点号.,\"轨向[短波,5m]\",点号.,\"轨向[长波,150m]\",导向轨,左轨高程,右轨高程,左轨平面,右轨平面,高程,\"高低[短波,5m]\",\"高低[长波,150m]\",平面位置,\"轨向[短波,5m]\",\"轨向[长波,150m]\",水平/超高,轨距,注解,ID号,设计超高,实测超高,设计轨距,实测轨距,设计5m高低,实测高低5m,设计150m高低,实测150m高低,设计5m轨向,实测5m轨向,设计150m轨向,实测150m轨向,轨向");
  49. sw.WriteLine("主要参数,,横杠采点,,理论调整量,,,,高低,,,,轨向,,,,导向轨,附加参数,");
  50. sw.WriteLine("测量点,轨枕ID号,内插.,里程,高程,平面位置,水平/超高,轨距,点号.,\"高低[短波,5m]\",点号.,\"高低[长波,150m]\",点号.,\"轨向[短波,5m]\",点号.,\"轨向[长波,150m]\",导向轨,注解,ID号");
  51. var resdata = DataAnalysisToPG.getfilexxxwD(UUID);
  52. foreach (var item in resdata)
  53. {
  54. //string strone = String.Empty;
  55. //Type t = item.GetType();//获得该类的Type
  56. //foreach (PropertyInfo pi in t.GetProperties())
  57. //{
  58. // if (pi.Name != "Id" && pi.Name != "Listid")
  59. // {
  60. // string sp = pi.GetValue(item) as string;
  61. // strone += sp + ",";
  62. // }
  63. //}
  64. //strone = strone.Remove(strone.Length - 1);
  65. //sw.WriteLine(strone);
  66. sw.WriteLine(
  67. item.Cld + "," + item.Gzidh + "," + item.Nc + "," + item.Lc + "," + item.Gc + "," + item.Pmwz + "," +
  68. item.Spcg + "," + item.Gj + "," + item.Gddhdb + "," + item.Gddb + "," + item.Gddhcb + "," + item.Gdcb + "," +
  69. item.Gxdhdb + "," + item.Gxdb + "," + item.Gxdhcb + "," + item.Gxcb + "," +
  70. item.Dxg + "," + item.Fjzj + "," + item.Fjidh
  71. );
  72. }
  73. sw.Close();
  74. XtraMessageBox.Show("导出成功");
  75. }
  76. }
  77. /// <summary>
  78. /// 启用编辑
  79. /// </summary>
  80. private void simpleButton1_Click(object sender, EventArgs e)
  81. {
  82. if (!bandedGridView1.OptionsBehavior.Editable)
  83. {
  84. if (UserInform.userinf.Pow == 0)
  85. {
  86. XtraMessageBox.Show("您没有权限执行编辑操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  87. }
  88. else
  89. {
  90. GengxinrenForm GX = new GengxinrenForm();
  91. if (GX.ShowDialog() == DialogResult.OK)
  92. {
  93. bandedGridView1.OptionsBehavior.Editable = true;
  94. nowtime = DateTime.Now.ToString();
  95. EditBtn.Text = "结束编辑";
  96. XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已启用编辑!再次点击结束编辑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  97. }
  98. }
  99. }
  100. else
  101. {
  102. bandedGridView1.OptionsBehavior.Editable = false;
  103. EditBtn.Text = "编辑";
  104. XtraMessageBox.Show("用户:" + UserInform.userinf.Username + " 已结束编辑!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  105. }
  106. }
  107. /// <summary>
  108. /// 添加行
  109. /// </summary>
  110. private void AddRowBtn_Click(object sender, EventArgs e)
  111. {
  112. if (!bandedGridView1.OptionsBehavior.Editable)
  113. {
  114. XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  115. }
  116. else
  117. {
  118. DataAnalysisToPG.Insertdata_CsvData(new List<DBOperation.Model.T_xxxw_csvdata>()
  119. {
  120. new DBOperation.Model.T_xxxw_csvdata()
  121. {
  122. Listid = UUID
  123. }
  124. });
  125. DataAnalysisToPG.UpdataToPGXXXWL(UserInform.userinf.Username, DateTime.Now.ToString(), UUID);
  126. csvdataold = DataAnalysisToPG.getfilexxxwD(UUID);
  127. gridControl1.DataSource = DataAnalysisToPG.getfilexxxwD(UUID);
  128. }
  129. }
  130. /// <summary>
  131. /// 实时更新数据库
  132. /// </summary>
  133. private async void bandedGridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
  134. {
  135. await Task.Run(() =>
  136. {
  137. //收集变化的值
  138. string nana = bandedGridView1.FocusedColumn.FieldName;
  139. string Caption = bandedGridView1.FocusedColumn.Caption;
  140. string val = bandedGridView1.GetRowCellValue(e.RowHandle, nana).ToString();
  141. string uuid = bandedGridView1.GetRowCellValue(e.RowHandle, "Id").ToString();
  142. undataarr.Add(new string[]
  143. {
  144. nana,val,uuid
  145. });
  146. //DataAnalysisToPG.UpdataToPGXXXWD(nana.ToLower(), val, uuid);
  147. //判断这个变化的cell之前是否记录过
  148. List<StaticLogClass> isExitLog = newlogs.FindAll(delegate (StaticLogClass log)
  149. {
  150. return log.Row == uuid.ToString() && log.Column == Caption;
  151. });
  152. if (isExitLog.Count > 0)
  153. {
  154. //记录过
  155. var changedd = newlogs.Where(c => c.Column == Caption && c.Row == uuid).First();
  156. if (changedd.Oldvalue == val)
  157. {
  158. //如果新值与原始的值相等,则相当于没变化,删除这条记录
  159. newlogs.Remove(changedd);
  160. }
  161. else
  162. {
  163. //不相等则更新新值
  164. changedd.Newvalue = val;
  165. }
  166. }
  167. else
  168. {
  169. //没记录过,新建
  170. StaticLogClass sc = new StaticLogClass();
  171. sc.Column = Caption;
  172. sc.Row = uuid;
  173. sc.Username = UserInform.userinf.Username;
  174. sc.Newvalue = val;
  175. //获取数据库中变化的这条数据
  176. var oneoldvalue = csvdataold.Find(delegate (DBOperation.Model.T_xxxw_csvdata ones)
  177. {
  178. return ones.Id == uuid;
  179. });
  180. //通过filedname获取变化的属性
  181. Type t = oneoldvalue.GetType();//获得该类的Type
  182. foreach (PropertyInfo pi in t.GetProperties())
  183. {
  184. if (pi.Name == nana)
  185. {
  186. //记录旧值
  187. sc.Oldvalue = pi.GetValue(oneoldvalue) as string;
  188. break;
  189. }
  190. }
  191. sc.Date = nowtime;
  192. newlogs.Add(sc);
  193. }
  194. });
  195. }
  196. /// <summary>
  197. /// 删除行
  198. /// </summary>
  199. private void delrowBTN_Click(object sender, EventArgs e)
  200. {
  201. if (UserInform.userinf.Pow == 0)
  202. {
  203. XtraMessageBox.Show("您没有权限执行删除操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  204. }
  205. else
  206. {
  207. if (!bandedGridView1.OptionsBehavior.Editable)
  208. {
  209. XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  210. }
  211. else
  212. {
  213. int rowhandle = bandedGridView1.GetFocusedDataSourceRowIndex();
  214. string uuid = bandedGridView1.GetRowCellValue(rowhandle, "Id").ToString();
  215. if (XtraMessageBox.Show("是否删除所选?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  216. {
  217. DataAnalysisToPG.DelToPGXXXWD(uuid);
  218. gridControl1.DataSource = DataAnalysisToPG.getfilexxxwD(UUID);
  219. DataAnalysisToPG.UpdataToPGXXXWL(UserInform.userinf.Username, DateTime.Now.ToString(), UUID);
  220. bandedGridView1.OptionsBehavior.Editable = true;
  221. XtraMessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  222. }
  223. }
  224. }
  225. }
  226. private void ShowDataForm_FormClosed(object sender, FormClosedEventArgs e)
  227. {
  228. ExcelTools.gridControl03.DataSource = DataAnalysisToPG.getfilexxxwL();
  229. }
  230. private void ShowDataForm_FormClosing(object sender, FormClosingEventArgs e)
  231. {
  232. undataarr.Clear();
  233. }
  234. /// <summary>
  235. /// 保存
  236. /// </summary>
  237. private void updataBtn_Click(object sender, EventArgs e)
  238. {
  239. if (!bandedGridView1.OptionsBehavior.Editable)
  240. {
  241. XtraMessageBox.Show("请先启用编辑模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  242. }
  243. else
  244. {
  245. for (int i = 0; i < undataarr.Count; i++)
  246. {
  247. DataAnalysisToPG.UpdataToPGXXXWD(undataarr[i][0].ToLower(), undataarr[i][1], undataarr[i][2]);
  248. }
  249. DataAnalysisToPG.UpdataToPGXXXWL(UserInform.userinf.Username, DateTime.Now.ToString(), UUID);
  250. undataarr.Clear();
  251. LogGeneratorFun.WriteLogJT(newlogs, Application.StartupPath + "//log//xx_" + UUID + ".log");
  252. newlogs.Clear();
  253. bandedGridView1.OptionsBehavior.Editable = false;
  254. EditBtn.Text = "编辑";
  255. XtraMessageBox.Show("保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  256. }
  257. }
  258. private void XGJLBtn_Click(object sender, EventArgs e)
  259. {
  260. LoggingForm frm = new LoggingForm(Application.StartupPath + "//log//xx_" + UUID + ".log",true, csvdataold);
  261. frm.StartPosition = FormStartPosition.CenterParent;
  262. frm.Show(this);
  263. }
  264. }
  265. }