using System; using System.Windows.Forms; using System.Drawing; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.PublicMethod; using UAS_MES_NEW.Entity; using System.Text; using System.Data; namespace UAS_MES_NEW.Make { public partial class Make_CheckNoRelpace : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); public Make_CheckNoRelpace() { InitializeComponent(); } private void Make_CheckNoRelpace_Load(object sender, EventArgs e) { dh = SystemInf.dh; } private void ReplaceCheckNo_Click(object sender, EventArgs e) { if (dh.CheckExist("makeserial", "ms_sncode='" + old_sncode.Text + "'")) { if (new_sncode.Text != "") { //更新序列号,利用了回滚机制,要么全部执行成功,要么不执行 string UpdateMakeSerial = "update makeserial set ms_sncode='" + new_sncode.Text + "',ms_beforesn='" + old_sncode.Text + "' where ms_sncode='" + old_sncode.Text + "'"; string UpdateCraftMaterial = "update CraftMaterial set cm_sncode='" + new_sncode.Text + "' where cm_sncode='" + old_sncode.Text + "'"; dh.ExecuteSQLTran(UpdateMakeSerial, UpdateCraftMaterial); //复制之前的日志,保证使用之前的序列号也能够找到操作记录 DataTable dt = (DataTable)dh.ExecuteSql("select mp_result,mp_makecode,mp_inman from makeprocess where mp_sncode='" + old_sncode.Text + "'", "select"); if (dt.Rows.Count > 0) { string[] sncode = new string[dt.Rows.Count]; string[] makecode = new string[dt.Rows.Count]; string[] result = new string[dt.Rows.Count]; string[] inman = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { sncode[i] = new_sncode.Text; makecode[i] = dt.Rows[i]["mp_makecode"].ToString(); result[i] = dt.Rows[i]["mp_result"].ToString(); inman[i] = dt.Rows[i]["mp_inman"].ToString(); } sql.Clear(); sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,"); sql.Append("mp_craftcode,mp_craftname,mp_kind,mp_result,mp_indate,mp_inman,mp_wccode,mp_linecode,mp_sourcecode) "); sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,mcd_stepcode,mcd_stepname,"); sql.Append("ma_craftcode,ma_craftname,ma_kind,:result,sysdate,:inman,ma_wccode,ma_linecode,''"); sql.Append("from make left join makecraftdetail on mcd_macode=ma_code left join makeserial on ms_makecode=ma_code "); sql.Append("where ms_sncode=:sncode and ma_code=:makecode"); dh.BatchInsert(sql.GetString(), new string[] { "result", "inman", "sncode", "makecode" }, result, inman, sncode, makecode); } //记录MakeProcess和一般的操作日志 LogicHandler.InsertMakeProcess(new_sncode.Text, dh.getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_sncode='" + new_sncode.Text + "'").ToString(),User.UserSourceCode,"序列号转换操作", "变更序列号成功,备注:" + ReplaceReason.Text, User.UserName); OperateResult.AppendText(">>序列号" + old_sncode.Text + "已成功替换为" + new_sncode.Text + "\n", Color.Green); } else { OperateResult.AppendText(">>新序列号不能为空\n", Color.Red); } } else { OperateResult.AppendText(">>序列号" + old_sncode.Text + "不存在\n", Color.Red); } } private void Clean_Click(object sender, EventArgs e) { OperateResult.Clear(); } } }