版博士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.
 
 
 
 

240 lines
10 KiB

  1. using ProductionControl.Utils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace ProductionControl
  14. {
  15. public partial class FrmProductInfo2 : Form
  16. {
  17. Service.ProductService service = new Service.ProductService();
  18. Models.Product model = new Models.Product();
  19. public FrmProductInfo2(Models.Product m=null)
  20. {
  21. InitializeComponent();
  22. this.dgvBatchList.AutoGenerateColumns = false;
  23. if (m!=null)
  24. {
  25. model = m;
  26. this.txtCode.Text = m.Code;
  27. this.txtName.Text = m.Name;
  28. this.txtSpec.Text = m.Spec;
  29. this.txtBatchId.Text = m.BatchId;
  30. this.numTargetCount.Value = m.TargetCount;
  31. this.toolTip1.SetToolTip(this.numTargetCount,"已完成:"+m.CompleteCount);
  32. this.numTensionBaseValue.Value = (decimal)m.TensionBaseValue;
  33. this.numTensionUpFloatValue.Value = (decimal)m.TensionUpFloatValue;
  34. this.numTensionDownFloatValue.Value = (decimal)m.TensionDownFloatValue;
  35. this.numHeightBaseValue.Value = (decimal)m.HeightBaseValue;
  36. this.numHeightUpFloatValue.Value = (decimal)m.HeightUpFloatValue;
  37. this.numHeightDownFloatValue.Value = (decimal)m.HeightDownFloatValue;
  38. this.txtHeightBaseDec.Text = m.HeightBaseDec;
  39. this.numLineWidthBaseValue.Value = (decimal)m.LineWidthBaseValue;
  40. this.numLineWidthUpFloatValue.Value = (decimal)m.LineWidthUpFloatValue;
  41. this.numLineWidthDownFloatValue.Value = (decimal)m.LineWidthDownFloatValue;
  42. this.numPTBaseValue.Value = (decimal)m.PTBaseValue;
  43. this.numPTUpFloatValue.Value = (decimal)m.PTUpFloatValue;
  44. this.numPTDownFloatValue.Value = (decimal)m.PTDownFloatValue;
  45. //if (m.Type > 0)
  46. //{
  47. // this.txtCode.Enabled = false;
  48. // this.txtName.Width = this.txtCode.Width;
  49. // this.txtSpec.Enabled = false;
  50. //}
  51. this.tsbtnAddFile.Enabled = true;
  52. this.tsbtnNewBatchId.Enabled = true;
  53. this.dgvBatchList.DataSource = new BindingSource(m.BatchHistoryList, null);
  54. if(model.AttachmentList.Count > 0)
  55. {
  56. this.btnOpenFile.Text = model.AttachmentList[0].Name;
  57. this.btnOpenFile.Visible = true;
  58. }
  59. }
  60. }
  61. private void FrmProductInfo_Load(object sender, EventArgs e)
  62. {
  63. }
  64. private void btnSave_Click(object sender, EventArgs e)
  65. {
  66. try
  67. {
  68. string szCode = this.txtCode.Text.Trim();
  69. string szName = this.txtName.Text.Trim();
  70. string szSpec = this.txtSpec.Text.Trim();
  71. string szBatchId = this.txtBatchId.Text.Trim();
  72. int liTargetCount = (int)this.numTargetCount.Value;
  73. string szHeightBaseDec=this.txtHeightBaseDec.Text.Trim().Trim(new char[] { ';', ',' });
  74. if (szCode == "" || szName == "")
  75. throw new Exception("请填写编号和名称!");
  76. if (szBatchId == "" || liTargetCount < 1)
  77. throw new Exception("请填写批次号和批次目标数量!");
  78. if (szHeightBaseDec != "")
  79. {
  80. double num;
  81. string[] szs= szHeightBaseDec.Split(new char[] { ';',','});
  82. foreach(string s in szs)
  83. {
  84. if (!double.TryParse(s, out num))
  85. throw new Exception(s+" 非数值!");
  86. }
  87. }
  88. model.Code = szCode;
  89. model.Name = szName;
  90. model.Spec = szSpec;
  91. model.TensionBaseValue= (double)this.numTensionBaseValue.Value;
  92. model.TensionUpFloatValue = (double)this.numTensionUpFloatValue.Value;
  93. model.TensionDownFloatValue = (double)this.numTensionDownFloatValue.Value;
  94. model.HeightBaseValue = (double)this.numHeightBaseValue.Value;
  95. model.HeightUpFloatValue = (double)this.numHeightUpFloatValue.Value;
  96. model.HeightDownFloatValue = (double)this.numHeightDownFloatValue.Value;
  97. model.HeightBaseDec = szHeightBaseDec;
  98. model.LineWidthBaseValue = (double)this.numPTBaseValue.Value;
  99. model.LineWidthUpFloatValue = (double)this.numLineWidthUpFloatValue.Value;
  100. model.LineWidthDownFloatValue = (double)this.numLineWidthDownFloatValue.Value;
  101. model.PTBaseValue = (double)this.numPTBaseValue.Value;
  102. model.PTUpFloatValue = (double)this.numPTUpFloatValue.Value;
  103. model.PTDownFloatValue = (double)this.numPTDownFloatValue.Value;
  104. model.ModifyUserCode = Config.loginUser.Code;
  105. model.ModifyTime = DateTime.Now;
  106. bool result;
  107. if (model.Id == 0)
  108. {
  109. model.BatchId = szBatchId;
  110. model.TargetCount = liTargetCount;
  111. model.CompleteCount = 0;
  112. model.CreateUserCode = Config.loginUser.Code;
  113. model.CreateTime = DateTime.Now;
  114. result = service.InsertNav(model);
  115. }
  116. else
  117. {
  118. if (model.BatchId != szBatchId && !string.IsNullOrEmpty(model.BatchId))
  119. {
  120. if (model.CompleteCount<model.TargetCount
  121. && MessageBox.Show($"本批次完成数量未达到目标数量,确定更换批次号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  122. return;
  123. if (model.BatchHistoryList.FirstOrDefault(m => m.BatchId == szBatchId) != null)
  124. throw new Exception("当前批次号与历史中所用批次号重复,请重新填写!");
  125. model.BatchHistoryList.Add(new Models.BatchHistory()
  126. {
  127. BatchId = model.BatchId,
  128. TargetCount = model.TargetCount,
  129. CompleteCount = model.CompleteCount,
  130. CreateUserCode = Config.loginUser.Code,
  131. ModifyUserCode = Config.loginUser.Code
  132. });
  133. model.CompleteCount = 0;
  134. }
  135. model.BatchId = szBatchId;
  136. model.TargetCount = liTargetCount;
  137. result = service.UpdateNav(model);
  138. }
  139. if (!result)
  140. throw new Exception("保存失败!");
  141. this.tsbtnAddFile.Enabled = true;
  142. this.tsbtnNewBatchId.Enabled = true;
  143. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  144. this.DialogResult = DialogResult.OK;
  145. this.Close();
  146. }
  147. catch (Exception ex)
  148. {
  149. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  150. }
  151. }
  152. private void btnCancel_Click(object sender, EventArgs e)
  153. {
  154. this.Close();
  155. }
  156. private void tsbtnNewBatchId_Click(object sender, EventArgs e)
  157. {
  158. tabControl1.SelectedIndex = 2;
  159. Application.DoEvents();
  160. }
  161. private void btnAddFile_Click(object sender, EventArgs e)
  162. {
  163. try
  164. {
  165. //.dwg /.dxf /.dws /.dwt
  166. string filePath = FileUtil.selectFile("dwg文件|*.dwg|dxf文件|*.dxf|dws文件|*.dws|dwt文件|*.dwt");
  167. if (string.IsNullOrEmpty(filePath))
  168. return;
  169. string fileName=Path.GetFileName(filePath);
  170. string fileExtend=Path.GetExtension(filePath);
  171. long nameTimestamp=DateTime.Now.Ticks;
  172. //未删除原文件,保留记录
  173. string targFilePath = Application.StartupPath + "\\Attachment\\Product\\";
  174. if (!Directory.Exists(targFilePath))
  175. Directory.CreateDirectory(targFilePath);
  176. targFilePath += nameTimestamp + fileExtend;
  177. //File.Copy(res.file_path, defectFileName + ".bmp", true);
  178. bool result = API.CopyFile(filePath, targFilePath, false);//更快 //false-覆盖
  179. if (!result)
  180. throw new Exception("移动文件失败!");
  181. //
  182. if (model.AttachmentList.Count > 0)
  183. {
  184. model.AttachmentList[0].NameTimestamp= nameTimestamp;
  185. model.AttachmentList[0].Name = fileName;
  186. model.AttachmentList[0].ExtendName = fileExtend;
  187. }
  188. else
  189. {
  190. model.AttachmentList.Add(new Models.Attachment()
  191. {
  192. TBName = "product",
  193. NameTimestamp = nameTimestamp,
  194. Name = fileName,
  195. ExtendName = fileExtend,
  196. });
  197. }
  198. if (!service.UpdateNav(model))
  199. throw new Exception("保存文件失败!");
  200. model=service.GetModelNav(model.Code);
  201. this.btnOpenFile.Text = model.AttachmentList[0].Name;
  202. this.btnOpenFile.Visible = true;
  203. }
  204. catch (Exception ex)
  205. {
  206. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  207. }
  208. }
  209. private void btnOpenFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  210. {
  211. if (model.AttachmentList.Count < 1)
  212. MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  213. string filePath = Application.StartupPath + "\\Attachment\\Product\\" + model.AttachmentList[0].Id + model.AttachmentList[0].ExtendName;
  214. Process.Start(filePath);
  215. }
  216. }
  217. }