RecordForm.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using DevExpress.XtraEditors;
  2. using DevExpress.XtraPrinting;
  3. using GCAS.Code;
  4. using GCAS.Dto;
  5. using GCAS.Localization;
  6. using GCAS.Model;
  7. using GCAS.Record;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Threading;
  14. using System.Windows.Forms;
  15. namespace GCAS
  16. {
  17. public partial class RecordForm : XtraForm
  18. {
  19. private List<NameValue> L;
  20. private RecordRepository recordRepository;
  21. private DeviceRepository deviceRepository;
  22. public OperatorModel currentUser;
  23. private EntranceRepository entranceRepository;
  24. private TeamRepository teamRepository;
  25. private ActionsRepository actionsRepository;
  26. public RecordForm()
  27. {
  28. InitializeComponent();
  29. L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
  30. }
  31. private void RecordForm_Load(object sender, EventArgs e)
  32. {
  33. //date_start.EditValue = DateTime.Today;
  34. //date_end.EditValue = DateTime.Today.AddDays(1).AddSeconds(-1);
  35. date_start.EditValue = DateTime.Now;
  36. date_end.EditValue = DateTime.Today.AddDays(1).AddSeconds(-1);
  37. recordRepository = new RecordRepository();
  38. deviceRepository = new DeviceRepository();
  39. actionsRepository = new ActionsRepository();
  40. entranceRepository = new EntranceRepository();
  41. teamRepository = new TeamRepository();
  42. BindDevice();
  43. BindEntrance();
  44. BindTeam();
  45. BindGrid();
  46. }
  47. private void btn_search_Click(object sender, EventArgs e)
  48. {
  49. BindGrid();
  50. }
  51. private void BindDevice()
  52. {
  53. var list = deviceRepository.GetList().Select(c => new KeyValuePair<int, string>(c.Id, c.Name)).ToList();
  54. list.Insert(0, new KeyValuePair<int, string>(0, L.GetString("All")));
  55. cb_device.Properties.DataSource = list;
  56. cb_device.Properties.DisplayMember = "Value";
  57. cb_device.Properties.ValueMember = "Key";
  58. cb_device.ItemIndex = 0;
  59. cb_device.Properties.ShowHeader = false;
  60. cb_device.Properties.ShowFooter = false;
  61. }
  62. private void BindEntrance()
  63. {
  64. var list = entranceRepository.GetList().Select(c => new KeyValuePair<int, string>(c.Id, c.Name)).ToList();
  65. list.Insert(0, new KeyValuePair<int, string>(0, L.GetString("All")));
  66. cb_entrance.Properties.DataSource = list;
  67. cb_entrance.Properties.DisplayMember = "Value";
  68. cb_entrance.Properties.ValueMember = "Key";
  69. cb_entrance.ItemIndex = 0;
  70. cb_entrance.Properties.ShowHeader = false;
  71. cb_entrance.Properties.ShowFooter = false;
  72. }
  73. private void BindTeam()
  74. {
  75. var list = teamRepository.GetList().Select(c => new KeyValuePair<int, string>(c.Id, c.Name)).ToList();
  76. list.Insert(0, new KeyValuePair<int, string>(0, L.GetString("All")));
  77. cb_team.Properties.DataSource = list;
  78. cb_team.Properties.DisplayMember = "Value";
  79. cb_team.Properties.ValueMember = "Key";
  80. cb_team.ItemIndex = 0;
  81. cb_team.Properties.ShowHeader = false;
  82. cb_team.Properties.ShowFooter = false;
  83. }
  84. private async void BindGrid()
  85. {
  86. gridView1.LoadingPanelVisible = true;
  87. var list = await recordRepository.GetList(
  88. text_key.Text,
  89. cb_device.EditValue == null ? 0 : (int)cb_device.EditValue,
  90. cb_entrance.EditValue == null ? 0 : (int)cb_entrance.EditValue,
  91. cb_team.EditValue == null ? 0 : (int)cb_team.EditValue,
  92. (DateTime)date_start.EditValue,
  93. (DateTime)date_end.EditValue);
  94. gridControl1.DataSource = list;
  95. gridView1.FocusedRowHandle = -1;
  96. gridView1.LoadingPanelVisible = false;
  97. }
  98. private void gridControl1_Load(object sender, EventArgs e)
  99. {
  100. if (File.Exists(Application.StartupPath + @"\" + Text + ".xml"))
  101. {
  102. gridView1.RestoreLayoutFromXml(Application.StartupPath + @"\" + Text + ".xml"); //加载布局
  103. }
  104. }
  105. private void gridView1_Layout(object sender, EventArgs e)
  106. {
  107. gridView1.SaveLayoutToXml(Application.StartupPath + @"\" + Text + ".xml");//保存布局
  108. }
  109. private void btn_export_Click(object sender, EventArgs e)
  110. {
  111. SaveFileDialog fileDialog = new SaveFileDialog
  112. {
  113. Title = "Export Excel",
  114. Filter = "Excel 97-2003 (*.xls)|*.xls|Excel (*.xlsx)|*.xlsx"
  115. };
  116. fileDialog.FileName = L.GetString("WeighingRecords") + ".xls";
  117. if (fileDialog.ShowDialog() == DialogResult.OK)
  118. {
  119. try
  120. {
  121. gridControl1.ExportToXls(fileDialog.FileName);
  122. XtraMessageBox.Show(L.GetString("ExportSucceeded"), L.GetString("notification"), MessageBoxButtons.OK, MessageBoxIcon.Information);
  123. }
  124. catch (Exception ex)
  125. {
  126. XtraMessageBox.Show(L.GetString("WeighingFailed") + " Info:" + ex.Message, L.GetString("notification"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  127. }
  128. }
  129. }
  130. private void text_key_Click(object sender, EventArgs e)
  131. {
  132. SoftKeyboard.ActiveSoftKeyboard(sender);
  133. }
  134. private void gridView1_MouseDown(object sender, MouseEventArgs e)
  135. {
  136. }
  137. private void btn_print_Click(object sender, EventArgs e)
  138. {
  139. PrintableComponentLink link = new PrintableComponentLink(new PrintingSystem())
  140. {
  141. Component = gridControl1,
  142. Landscape = true,
  143. PaperKind = System.Drawing.Printing.PaperKind.A4,
  144. };
  145. link.CreateMarginalHeaderArea += new CreateAreaEventHandler(Link_CreateMarginalHeaderArea);
  146. link.CreateDocument();
  147. link.ShowPreview();
  148. }
  149. private void Link_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
  150. {
  151. PageInfoBrick brickTitle = e.Graph.DrawPageInfo(PageInfo.None, "称重记录", Color.Black, new RectangleF(0, 0, 100, 30), BorderSide.None);
  152. brickTitle.LineAlignment = BrickAlignment.Center;
  153. brickTitle.Alignment = BrickAlignment.Center;
  154. brickTitle.AutoWidth = true;
  155. brickTitle.Font = new Font("Tahoma", 16f, FontStyle.Bold);
  156. PageInfoBrick brickSubtitle = e.Graph.DrawPageInfo(PageInfo.None, L.GetString("dateRange") + date_start.Text + " 00:00 - " + date_end.Text + " 23:59", Color.Black, new RectangleF(0, 10, 100, 20), BorderSide.None);
  157. brickSubtitle.LineAlignment = BrickAlignment.Far;
  158. brickSubtitle.Alignment = BrickAlignment.Far;
  159. brickSubtitle.AutoWidth = true;
  160. brickSubtitle.Font = new Font("Tahoma", 9f, FontStyle.Regular);
  161. PageInfoBrick brickType = e.Graph.DrawPageInfo(PageInfo.None, "设备:" + cb_device.Text + " 料口:" + cb_entrance.Text + " 班组:" + cb_device.Text, Color.Black, new RectangleF(0, 0, 100, 20), BorderSide.None);
  162. brickType.LineAlignment = BrickAlignment.Near;
  163. brickType.Alignment = BrickAlignment.Near;
  164. brickType.AutoWidth = true;
  165. brickType.Font = new Font("Tahoma", 9f, FontStyle.Regular);
  166. }
  167. }
  168. }