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

124 строки
5.2 KiB

  1. using Models;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace ProductionControl
  13. {
  14. public partial class FrmOrderList : Form
  15. {
  16. Service.OrderService service = new Service.OrderService();
  17. public FrmOrderList()
  18. {
  19. InitializeComponent();
  20. dataGridView1.AutoGenerateColumns = false;
  21. //控制日期或时间的显示格式
  22. this.dateTimePicker1.CustomFormat = this.dateTimePicker2.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  23. //使用自定义格式
  24. this.dateTimePicker1.Format = this.dateTimePicker2.Format = DateTimePickerFormat.Custom;
  25. //时间控件的启用
  26. this.dateTimePicker1.ShowUpDown = this.dateTimePicker2.ShowUpDown = true;
  27. dateTimePicker1.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
  28. dateTimePicker2.Value = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
  29. }
  30. private void initDataView()
  31. {
  32. //显示的数据
  33. this.cobProductList.DisplayMember = "Name";
  34. this.cobProductList.ValueMember = "Id";
  35. var lstProduct = service.GetProductList();
  36. lstProduct.Insert(0, new Product() { Name = "全部", Code = "", CreateUserCode = "", ModifyUserCode = "" });
  37. this.cobProductList.DataSource = lstProduct;
  38. this.cobStepList.DisplayMember = "Name";
  39. this.cobStepList.ValueMember = "Id";
  40. var listStep = service.GetStepList();
  41. listStep.Insert(0, new Step() { Name = "全部", Code = "", CreateUserCode = "", ModifyUserCode = "" });
  42. this.cobStepList.DataSource = listStep;
  43. }
  44. private void queryData()
  45. {
  46. //创建表达式
  47. var exp1 = Expressionable.Create<Order>()
  48. .AndIF((int)cobProductList.SelectedValue>0, it => it.ProductId == (int)cobProductList.SelectedValue)
  49. .AndIF((int)cobStepList.SelectedValue > 0, it => it.StepId == (int)cobStepList.SelectedValue)
  50. .AndIF(dateTimePicker1.Checked, it => it.CreateTime >= dateTimePicker1.Value)
  51. .AndIF(dateTimePicker2.Checked, it => it.CreateTime < dateTimePicker2.Value)
  52. .ToExpression();//注意 这一句 不能少
  53. int liTotalCount = 0;
  54. var list = service.GetListNav(this.uiPagination1.CurrentPage, this.uiPagination1.PageSize, ref liTotalCount, exp1);
  55. this.uiPagination1.TotalCount = liTotalCount;
  56. dataGridView1.DataSource = new BindingSource(list, null);
  57. }
  58. private void FrmProductList_Load(object sender, EventArgs e)
  59. {
  60. initDataView();
  61. queryData();
  62. }
  63. private void tsbtnQuery_Click(object sender, EventArgs e)
  64. {
  65. queryData();
  66. }
  67. private void tsbtnDel_Click(object sender, EventArgs e)
  68. {
  69. //try
  70. //{
  71. // if (this.dataGridView1.CurrentRow == null)
  72. // return;
  73. // if (MessageBox.Show($"确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  74. // {
  75. // var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  76. // int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  77. // if (!service.DelNav(list[liIndex]))
  78. // throw new Exception("删除失败!");
  79. // MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  80. // initDataView();
  81. // }
  82. //}
  83. //catch (Exception ex)
  84. //{
  85. // MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  86. //}
  87. }
  88. private void tsbtnClose_Click(object sender, EventArgs e)
  89. {
  90. this.Close();
  91. }
  92. private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  93. {
  94. //var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  95. //int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  96. //FrmProductInfo frm = new FrmProductInfo(list[liIndex]);
  97. //frm.ShowDialog(this);
  98. //initDataView();
  99. }
  100. private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
  101. {
  102. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Order>;
  103. for (int i = 0; i < dataGridView1.Rows.Count; i++)
  104. {
  105. if (list[i].ProductInfo != null) dataGridView1.Rows[i].Cells["colProductName"].Value = list[i].ProductInfo.Name;
  106. if (list[i].StepInfo != null) dataGridView1.Rows[i].Cells["colStepName"].Value = list[i].StepInfo.Name;
  107. }
  108. }
  109. }
  110. }