版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

300 строки
12 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace ProductionControl
  12. {
  13. public partial class FrmStepInfo : Form
  14. {
  15. Service.StepService service = new Service.StepService();
  16. Models.Step model=new Models.Step();
  17. public FrmStepInfo(Models.Step m=null)
  18. {
  19. InitializeComponent();
  20. dataGridView1.AutoGenerateColumns = false;
  21. dataGridView2.AutoGenerateColumns = false;
  22. //显示行号与列宽度自动调整
  23. dataGridView2.RowHeadersVisible = true;
  24. dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
  25. dataGridView2.RowPostPaint += (sender, e) =>
  26. {
  27. Utils.Util.showRowNum_onDataGrid_RowPostPaint(this.dataGridView2, sender, e);
  28. };
  29. if (m == null)
  30. model.ProcessList = new List<Models.StepProcess>();
  31. else
  32. model = m;
  33. }
  34. private void initDataView()
  35. {
  36. dataGridView1.Columns.Add("colCode", "code");
  37. dataGridView1.Columns.Add("colName", "工序");
  38. dataGridView1.Columns[0].Visible = false;
  39. dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
  40. foreach (var item in Config.dicDevType)
  41. dataGridView1.Rows.Add(item.Key, item.Value);
  42. //
  43. this.txtCode.Text = model.Code;
  44. this.txtName.Text = model.Name;
  45. this.numStartTimeIndex.Value = model.StartTimeIndex;
  46. if (model.ProcessList!=null)
  47. dataGridView2.DataSource = new BindingSource(model.ProcessList, null);
  48. }
  49. private class Process
  50. {
  51. public Process(string code, string name)
  52. {
  53. Code = code;
  54. Name = name;
  55. }
  56. public string Code { get; set; }
  57. public string Name { get; set; }
  58. }
  59. private void FrmStepInfo_Load(object sender, EventArgs e)
  60. {
  61. initDataView();
  62. }
  63. #region private
  64. private void reOrderProcess()
  65. {
  66. for (int i = 0; i < model.ProcessList.Count; i++)
  67. model.ProcessList[i].Order = i;
  68. }
  69. private void refreshDataGridView()
  70. {
  71. dataGridView2.DataSource = null;
  72. dataGridView2.DataSource = new BindingSource(model.ProcessList, null);
  73. }
  74. #endregion
  75. private bool saveExit=false;
  76. private void tsbtnSave_Click(object sender, EventArgs e)
  77. {
  78. try
  79. {
  80. string szCode = this.txtCode.Text.Trim();
  81. string szName = this.txtName.Text.Trim();
  82. if (szCode == "" || szName == "")
  83. throw new Exception("请填写编号和名称!");
  84. if (model.ProcessList == null || model.ProcessList.Count == 0)
  85. throw new Exception("请添加流程工序!");
  86. foreach(var item in model.ProcessList)
  87. {
  88. if (string.IsNullOrWhiteSpace(item.ProcessParams))
  89. throw new Exception($"{Config.dicDevType[item.ProcessCode]} 配方未设置!");
  90. }
  91. model.Code = szCode;
  92. model.Name = szName;
  93. model.StartTimeIndex = (int)numStartTimeIndex.Value;
  94. model.ModifyUserCode = Config.loginUser.Code;
  95. bool result;
  96. if (model.Id == 0)
  97. {
  98. model.CreateUserCode=Config.loginUser.Code;
  99. result = service.InsertNav(model);
  100. }
  101. else
  102. result = service.UpdateNav(model);
  103. if (!result)
  104. throw new Exception("保存失败!");
  105. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  106. saveExit=true;
  107. this.Close();
  108. }
  109. catch (Exception ex)
  110. {
  111. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  112. }
  113. }
  114. private void btnAdd_Click(object sender, EventArgs e)
  115. {
  116. try
  117. {
  118. if (this.dataGridView1.SelectedRows.Count != 1)
  119. throw new Exception("请选择要插入的工序!");
  120. string processCode = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
  121. model.ProcessList.Add(new Models.StepProcess()
  122. {
  123. ProcessCode = processCode,
  124. ProcessName= Config.dicDevType[processCode],
  125. ModifyUserCode = Config.loginUser.Code,
  126. CreateUserCode = Config.loginUser.Code
  127. });
  128. reOrderProcess();
  129. this.refreshDataGridView();
  130. this.dataGridView2.Rows[this.dataGridView2.Rows.Count-1].Selected = true;
  131. dataGridView2.CurrentCell = dataGridView2.Rows[this.dataGridView2.Rows.Count - 1].Cells[1];
  132. }
  133. catch (Exception ex)
  134. {
  135. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  136. }
  137. }
  138. private void btnInsert_Click(object sender, EventArgs e)
  139. {
  140. try
  141. {
  142. if (this.dataGridView1.SelectedRows.Count != 1)
  143. throw new Exception("请选择要插入的工序!");
  144. string processCode= this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
  145. int liInsertIndex = this.dataGridView2.Rows.Count;
  146. if (this.dataGridView2.SelectedRows.Count > 0)
  147. liInsertIndex = this.dataGridView2.SelectedRows[0].Index;
  148. model.ProcessList.Insert(liInsertIndex, new Models.StepProcess()
  149. {
  150. ProcessCode = processCode,
  151. ProcessName = Config.dicDevType[processCode],
  152. Order = liInsertIndex,
  153. ModifyUserCode=Config.loginUser.Code,
  154. CreateUserCode=Config.loginUser.Code
  155. });
  156. reOrderProcess();
  157. this.refreshDataGridView();
  158. this.dataGridView2.Rows[liInsertIndex].Selected = true;
  159. dataGridView2.CurrentCell = dataGridView2.Rows[liInsertIndex].Cells[1];
  160. }
  161. catch (Exception ex)
  162. {
  163. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  164. }
  165. }
  166. private void btnDel_Click(object sender, EventArgs e)
  167. {
  168. try
  169. {
  170. if (this.dataGridView2.SelectedRows.Count != 1)
  171. throw new Exception("请选择要删除的工序!");
  172. int liRowIndex = this.dataGridView2.SelectedRows[0].Index;
  173. model.ProcessList.RemoveAt(liRowIndex);
  174. if(liRowIndex>= dataGridView2.Rows.Count-1)
  175. liRowIndex= dataGridView2.Rows.Count-1;
  176. dataGridView2.CurrentCell = dataGridView2.Rows[liRowIndex].Cells[1];
  177. //reOrderProcess();
  178. this.refreshDataGridView();
  179. if (dataGridView2.Rows.Count < 1)
  180. return;
  181. if (liRowIndex >= dataGridView2.Rows.Count)
  182. liRowIndex = dataGridView2.Rows.Count - 1;
  183. dataGridView2.CurrentCell = dataGridView2.Rows[liRowIndex].Cells[1];
  184. }
  185. catch (Exception ex)
  186. {
  187. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  188. }
  189. }
  190. private void btnUp_Click(object sender, EventArgs e)
  191. {
  192. try
  193. {
  194. if (this.dataGridView2.SelectedRows.Count != 1)
  195. throw new Exception("请选择要调整顺序的工序!");
  196. int liSelIndex = this.dataGridView2.SelectedRows[0].Index;
  197. if (liSelIndex == 0)
  198. return;
  199. model.ProcessList.Insert(liSelIndex - 1, model.ProcessList[liSelIndex]);
  200. model.ProcessList.RemoveAt(liSelIndex + 1);
  201. reOrderProcess();
  202. this.refreshDataGridView();
  203. this.dataGridView2.Rows[liSelIndex-1].Selected = true;
  204. dataGridView2.CurrentCell = dataGridView2.Rows[liSelIndex - 1].Cells[1];
  205. }
  206. catch (Exception ex)
  207. {
  208. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  209. }
  210. }
  211. private void btnDown_Click(object sender, EventArgs e)
  212. {
  213. try
  214. {
  215. if (this.dataGridView2.SelectedRows.Count != 1)
  216. throw new Exception("请选择要调整顺序的工序!");
  217. int liSelIndex = this.dataGridView2.SelectedRows[0].Index;
  218. if (liSelIndex == this.dataGridView2.Rows.Count-1)
  219. return;
  220. model.ProcessList.Insert(liSelIndex +2, model.ProcessList[liSelIndex]);
  221. model.ProcessList.RemoveAt(liSelIndex);
  222. reOrderProcess();
  223. this.refreshDataGridView();
  224. this.dataGridView2.Rows[liSelIndex+1].Selected = true;
  225. dataGridView2.CurrentCell = dataGridView2.Rows[liSelIndex + 1].Cells[1];
  226. }
  227. catch (Exception ex)
  228. {
  229. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  230. }
  231. }
  232. private void tsbtnDebug_Click(object sender, EventArgs e)
  233. {
  234. }
  235. private void dataGridView2_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
  236. {
  237. for(int i=0;i< dataGridView2.Rows.Count;i++)
  238. {
  239. dataGridView2.Rows[i].Cells["colTypeName"].Value = Config.dicDevType[dataGridView2.Rows[i].Cells[0].Value.ToString()];
  240. }
  241. }
  242. private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
  243. {
  244. int Index = this.dataGridView2.CurrentRow.Index;//获取当前选中行的索引
  245. if (Index < this.dataGridView2.Rows.Count && this.dataGridView2.CurrentCell.Value.ToString() == "设置")
  246. {
  247. string processCode = this.dataGridView2.Rows[Index].Cells["colProcessCode"].Value.ToString();
  248. string processParams="";
  249. if(this.dataGridView2.Rows[Index].Cells["colProcessParams"].Value!=null)
  250. processParams=this.dataGridView2.Rows[Index].Cells["colProcessParams"].Value.ToString();
  251. FrmSetParams frm=new FrmSetParams(processCode, processParams);
  252. if (frm.ShowDialog() == DialogResult.OK)
  253. this.dataGridView2.Rows[Index].Cells["colProcessParams"].Value = frm.ParamsData;
  254. }
  255. }
  256. private void tsbtnClose_Click(object sender, EventArgs e)
  257. {
  258. this.Close();
  259. }
  260. //单元格编译完成
  261. private void dataGridView2_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  262. {
  263. var value = dataGridView2.Rows[e.RowIndex].Cells["colProcessName"].Value;
  264. if (value==null || value.ToString().Trim() == "")
  265. {
  266. dataGridView2.Rows[e.RowIndex].Cells["colProcessName"].Value = dataGridView2.Rows[e.RowIndex].Cells["colTypeName"].Value;
  267. }
  268. }
  269. private void FrmStepInfo_FormClosing(object sender, FormClosingEventArgs e)
  270. {
  271. if (!saveExit && MessageBox.Show($"确认修改已保存,是否退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  272. {
  273. e.Cancel = true;
  274. return;
  275. }
  276. }
  277. }
  278. }