Make_CheckNoRelpace.cs 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using UAS_MES_NEW.DataOperate;
  5. using UAS_MES_NEW.PublicMethod;
  6. using UAS_MES_NEW.Entity;
  7. using System.Text;
  8. using System.Data;
  9. namespace UAS_MES_NEW.Make
  10. {
  11. public partial class Make_CheckNoRelpace : Form
  12. {
  13. DataHelper dh;
  14. LogStringBuilder sql = new LogStringBuilder();
  15. public Make_CheckNoRelpace()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Make_CheckNoRelpace_Load(object sender, EventArgs e)
  20. {
  21. dh = SystemInf.dh;
  22. }
  23. private void ReplaceCheckNo_Click(object sender, EventArgs e)
  24. {
  25. if (dh.CheckExist("makeserial", "ms_sncode='" + old_sncode.Text + "'"))
  26. {
  27. if (new_sncode.Text != "")
  28. {
  29. //更新序列号,利用了回滚机制,要么全部执行成功,要么不执行
  30. string UpdateMakeSerial = "update makeserial set ms_sncode='" + new_sncode.Text + "',ms_beforesn='" + old_sncode.Text + "' where ms_sncode='" + old_sncode.Text + "'";
  31. string UpdateCraftMaterial = "update CraftMaterial set cm_sncode='" + new_sncode.Text + "' where cm_sncode='" + old_sncode.Text + "'";
  32. dh.ExecuteSQLTran(UpdateMakeSerial, UpdateCraftMaterial);
  33. //复制之前的日志,保证使用之前的序列号也能够找到操作记录
  34. DataTable dt = (DataTable)dh.ExecuteSql("select mp_result,mp_makecode,mp_inman from makeprocess where mp_sncode='" + old_sncode.Text + "'", "select");
  35. if (dt.Rows.Count > 0)
  36. {
  37. string[] sncode = new string[dt.Rows.Count];
  38. string[] makecode = new string[dt.Rows.Count];
  39. string[] result = new string[dt.Rows.Count];
  40. string[] inman = new string[dt.Rows.Count];
  41. for (int i = 0; i < dt.Rows.Count; i++)
  42. {
  43. sncode[i] = new_sncode.Text;
  44. makecode[i] = dt.Rows[i]["mp_makecode"].ToString();
  45. result[i] = dt.Rows[i]["mp_result"].ToString();
  46. inman[i] = dt.Rows[i]["mp_inman"].ToString();
  47. }
  48. sql.Clear();
  49. sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,");
  50. sql.Append("mp_craftcode,mp_craftname,mp_kind,mp_result,mp_indate,mp_inman,mp_wccode,mp_linecode,mp_sourcecode) ");
  51. sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,mcd_stepcode,mcd_stepname,");
  52. sql.Append("ma_craftcode,ma_craftname,ma_kind,:result,sysdate,:inman,ma_wccode,ma_linecode,''");
  53. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code left join makeserial on ms_makecode=ma_code ");
  54. sql.Append("where ms_sncode=:sncode and ma_code=:makecode");
  55. dh.BatchInsert(sql.GetString(), new string[] { "result", "inman", "sncode", "makecode" }, result, inman, sncode, makecode);
  56. }
  57. //记录MakeProcess和一般的操作日志
  58. LogicHandler.InsertMakeProcess(new_sncode.Text, dh.getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_sncode='" + new_sncode.Text + "'").ToString(),User.UserSourceCode,"序列号转换操作", "变更序列号成功,备注:" + ReplaceReason.Text, User.UserName);
  59. OperateResult.AppendText(">>序列号" + old_sncode.Text + "已成功替换为" + new_sncode.Text + "\n", Color.Green);
  60. }
  61. else
  62. {
  63. OperateResult.AppendText(">>新序列号不能为空\n", Color.Red);
  64. }
  65. }
  66. else
  67. {
  68. OperateResult.AppendText(">>序列号" + old_sncode.Text + "不存在\n", Color.Red);
  69. }
  70. }
  71. private void Clean_Click(object sender, EventArgs e)
  72. {
  73. OperateResult.Clear();
  74. }
  75. }
  76. }