版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

131 lines
5.1 KiB

  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace AssistClient
  12. {
  13. public partial class FrmProductList : Form
  14. {
  15. Service.ProductService service = new Service.ProductService();
  16. public Models.Product Product { get; private set; }
  17. public FrmProductList()
  18. {
  19. InitializeComponent();
  20. dataGridView1.AutoGenerateColumns = false;
  21. }
  22. private void initDataView()
  23. {
  24. Product = null;
  25. var list = service.GetListNav();
  26. tsslCount.Text = $"共 {list.Count} 条记录";
  27. dataGridView1.DataSource = new BindingSource(list, null);
  28. }
  29. private void FrmProductList_Load(object sender, EventArgs e)
  30. {
  31. initDataView();
  32. }
  33. private void tsbtnAdd_Click(object sender, EventArgs e)
  34. {
  35. //FrmProductInfo frm = new FrmProductInfo();
  36. //frm.ShowDialog();
  37. //initDataView();
  38. }
  39. private void tsbtnDel_Click(object sender, EventArgs e)
  40. {
  41. try
  42. {
  43. if (this.dataGridView1.CurrentRow == null)
  44. return;
  45. if (MessageBox.Show($"确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  46. {
  47. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  48. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  49. if (!service.DelNav(list[liIndex]))
  50. throw new Exception("删除失败!");
  51. MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  52. initDataView();
  53. }
  54. }
  55. catch (Exception ex)
  56. {
  57. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  58. }
  59. }
  60. private void tsbtnSetting_Click(object sender, EventArgs e)
  61. {
  62. if(this.dataGridView1.CurrentRow == null) return;
  63. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  64. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  65. FrmProductStep frm = new FrmProductStep(list[liIndex]);
  66. frm.ShowDialog();
  67. initDataView();
  68. }
  69. private void tsbtnRevise_Click(object sender, EventArgs e)
  70. {
  71. try
  72. {
  73. if (this.dataGridView1.CurrentRow == null)
  74. throw new Exception("请选择要校正的产品!");
  75. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  76. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  77. if (list[liIndex].ReviseStepId==null || list[liIndex].ReviseStepId<1)
  78. throw new Exception("此产品未设置校正流程!");
  79. if (MessageBox.Show($"确认执行校正产品流程?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  80. {
  81. Product=list[liIndex];
  82. this.DialogResult = DialogResult.Yes;
  83. this.Close();
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  89. }
  90. }
  91. private void tsbtnClose_Click(object sender, EventArgs e)
  92. {
  93. this.Close();
  94. }
  95. private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  96. {
  97. //if (!this.tsbtnAdd.Enabled) return;
  98. //var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  99. //int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  100. //FrmProductInfo frm = new FrmProductInfo(list[liIndex]);
  101. //frm.ShowDialog(this);
  102. //initDataView();
  103. }
  104. private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
  105. {
  106. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  107. for (int i = 0; i < dataGridView1.Rows.Count; i++)
  108. {
  109. if (list[i].StepInfo != null)
  110. dataGridView1.Rows[i].Cells["colStepName"].Value = list[i].StepInfo.Name;
  111. //if (list[i].ReviseStepInfo != null)
  112. // dataGridView1.Rows[i].Cells["colReviseStepName"].Value = list[i].ReviseStepInfo.Name;
  113. if (list[i].AssistStepInfo != null)
  114. dataGridView1.Rows[i].Cells["colAssistStepName"].Value = list[i].AssistStepInfo.Name;
  115. }
  116. }
  117. }
  118. }