protected void btnTransfer_Click(object sender, EventArgs e) { btnTransfer.Enabled = false; btnReset.Enabled = false; if (txtSerialNew.Text.Trim().Length >= 11 && txtSerialOld.Text.Trim().Length >= 11) { DataTable dtHead = new DataTable(); SqlCommand sql = new SqlCommand(); string strSQL = @"SELECT HoldNbr, LotUnholdNbr, LotNbr, prd_serial, prd_line, prd_model_code, prd_model, pl_no, prd_pipe_no, HoldBy, HoldDate, prd_status, RequestBy, RequestDate, AllowBy, AllowDate, Location, remark1, remark2, remark3 FROM PD_Hold WHERE prd_serial=@prd_serial ORDER BY HoldDate DESC "; sql.CommandText = strSQL; sql.Parameters.Add(new SqlParameter("@prd_serial", txtSerialOld.Text.Trim())); dtHead = oConDCI.Query(sql); if (dtHead.Rows.Count > 0) { if (isCanTransferLabel(txtSerialOld.Text.Trim())) { foreach (DataRow drHead in dtHead.Rows) { string HoldNbr = oPrdSrv.GetRunningNumber("HOLD_HEAD"); string StrInsert = @"INSERT INTO PD_Hold (HoldNbr,LotUnholdNbr,LotNbr,prd_serial, prd_line,prd_model_code,prd_model,pl_no,prd_pipe_no,HoldBy,HoldDate,prd_status, RequestBy,RequestDate,AllowBy,AllowDate,Location,remark1,remark2,remark3) VALUES (@HoldNbr, @LotUnholdNbr, @LotNbr, @prd_serial, @prd_line, @prd_model_code, @prd_model, @pl_no, @prd_pipe_no, @HoldBy, @HoldDate, @prd_status, @RequestBy, @RequestDate, @AllowBy, @AllowDate,@Location, @remark1, @remark2, @remark3) "; SqlCommand cmdInsert = new SqlCommand(); cmdInsert.CommandText = StrInsert; cmdInsert.CommandTimeout = 180; cmdInsert.Parameters.Add(new SqlParameter("@HoldNbr", HoldNbr)); cmdInsert.Parameters.Add(new SqlParameter("@LotUnholdNbr", drHead["LotUnholdNbr"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@LotNbr", drHead["LotNbr"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@prd_serial", txtSerialNew.Text.Trim())); cmdInsert.Parameters.Add(new SqlParameter("@prd_line", drHead["prd_line"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@prd_model_code", drHead["prd_model_code"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@prd_model", drHead["prd_model"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@pl_no", drHead["pl_no"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@prd_pipe_no", drHead["prd_pipe_no"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@HoldBy", drHead["HoldBy"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@HoldDate", drHead["HoldDate"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@prd_status", drHead["prd_status"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@RequestBy", drHead["RequestBy"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@RequestDate", drHead["RequestDate"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@AllowBy", drHead["AllowBy"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@AllowDate", drHead["AllowDate"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@Location", drHead["Location"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@remark1", drHead["remark1"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@remark2", drHead["remark2"].ToString())); cmdInsert.Parameters.Add(new SqlParameter("@remark3", drHead["remark3"].ToString())); oConDCI.ExecuteCommand(cmdInsert); //************** Hold Detail ***************** DataTable dtLineDet = new DataTable(); string StrLineDet = @"SELECT Nbr, HoldNbr, ProcessCode, ProcessStatus, ProcessDate, UpdateBy, UpdateDate, remark1, remark2, remark3 FROM PD_Hold_Detail WHERE HoldNbr=@HoldNbr "; SqlCommand cmdLineDet = new SqlCommand(); cmdLineDet.CommandText = StrLineDet; cmdLineDet.CommandTimeout = 180; cmdLineDet.Parameters.Add(new SqlParameter("@HoldNbr", drHead["HoldNbr"].ToString())); dtLineDet = oConDCI.Query(cmdLineDet); //******** LineOut Detial ******** foreach (DataRow drDet in dtLineDet.Rows) { string Nbr = oPrdSrv.GetRunningNumber("HOLD_DETAIL"); string StrInsertDet = @"INSERT INTO PD_Hold_Detail (Nbr,HoldNbr,ProcessCode, ProcessStatus,ProcessDate,UpdateBy,UpdateDate,remark1,remark2,remark3) VALUES (@Nbr,@HoldNbr,@ProcessCode,@ProcessStatus,@ProcessDate,@UpdateBy, @UpdateDate,@remark1,@remark2,@remark3) "; SqlCommand cmdInsertDet = new SqlCommand(); cmdInsertDet.CommandText = StrInsertDet; cmdInsertDet.CommandTimeout = 180; cmdInsertDet.Parameters.Add(new SqlParameter("@Nbr", Nbr)); cmdInsertDet.Parameters.Add(new SqlParameter("@HoldNbr", HoldNbr)); cmdInsertDet.Parameters.Add(new SqlParameter("@ProcessCode", drDet["ProcessCode"].ToString())); cmdInsertDet.Parameters.Add(new SqlParameter("@ProcessStatus", drDet["ProcessStatus"].ToString())); cmdInsertDet.Parameters.Add(new SqlParameter("@ProcessDate", drDet["ProcessDate"].ToString())); cmdInsertDet.Parameters.Add(new SqlParameter("@UpdateBy", drDet["UpdateBy"].ToString())); cmdInsertDet.Parameters.Add(new SqlParameter("@UpdateDate", drDet["UpdateDate"].ToString())); cmdInsertDet.Parameters.Add(new SqlParameter("@remark1", drDet["remark1"].ToString())); cmdInsertDet.Parameters.Add(new SqlParameter("@remark2", drDet["remark2"].ToString())); cmdInsertDet.Parameters.Add(new SqlParameter("@remark3", drDet["remark3"].ToString())); oConDCI.ExecuteCommand(cmdInsertDet); } // end foreach detail try { string StrUpdateHeadOld = "UPDATE PD_Hold SET prd_status = @prd_status WHERE HoldNbr = @HoldNbr "; SqlCommand cmdUpdateHeadOld = new SqlCommand(); cmdUpdateHeadOld.CommandText = StrUpdateHeadOld; cmdUpdateHeadOld.CommandTimeout = 180; cmdUpdateHeadOld.Parameters.Add(new SqlParameter("@prd_status", "RELABEL")); cmdUpdateHeadOld.Parameters.Add(new SqlParameter("@HoldNbr", drHead["HoldNbr"].ToString())); oConDCI.ExecuteCommand(cmdUpdateHeadOld); } catch { } } // end foreach head // Reload Data TableDataNew.Text = GetProcessData(txtSerialNew.Text.Trim()); } else { lblError.Text = "Serial นี้ถูก Packing ไปแล้วไม่สามารถทำการโอนถ่ายข้อมูลได้"; } } else { lblError.Text = "ไม่พบข้อมูลที่จะทำการโอนถ่ายข้อมูล"; } }// end if check else { lblError.Text = "กรุณาระบบหมายเลข Serial ที่ถูกต้อง"; } btnTransfer.Enabled = false; btnReset.Enabled = true; }