| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052 |
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- namespace MES_Interface
- {
- public class LogicHandler
- {
- public LogicHandler(string Environment)
- {
- dh = new DataHelper(Environment);
- }
- DataHelper dh;
- //用于拼接SQL
- StringBuilder sql = new StringBuilder();
- //用于存放批量执行的SQL
- List<string> sqls = new List<string>();
- /// <summary>
- /// 检测当前的岗位资源对应的工序
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iSource"></param>
- /// <param name="oErrMessage"></param>
- /// <returns></returns>
- private bool CheckCurrentStep(string iSnCode, string iMakeCode, string iSource, out string oErrMessage)
- {
- oErrMessage = "";
- if (iMakeCode == "")
- {
- if (!GetMakeInfo(iSnCode, out iMakeCode, out oErrMessage))
- return false;
- }
- string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'").ToString();
- string sourcestepcode = GetStepCodeBySource(iSource);
- if (nextstepcode == "")
- {
- oErrMessage = "当前序列号已无可执行工序";
- return false;
- }
- if (nextstepcode == sourcestepcode)
- return true;
- else {
- oErrMessage = "资源" + iSource + "对应的工序是" + sourcestepcode + ",序列号" + iSnCode + "当前工序是" + nextstepcode;
- return false;
- }
- }
- private bool CheckMakeStatus(string iMaCode)
- {
- if (dh.getFieldDataByCondition(" make ", "ma_statuscode", "ma_code='" + iMaCode + "' ").ToString() == "STARTED")
- return true;
- else
- return false;
- }
- /// <summary>
- /// 判断当前工序是否是第一道工序
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakecode"></param>
- /// <param name="iSourceCode"></param>
- /// <returns></returns>
- public bool CheckIfFirstMakeSerial(string iSnCode, string iMakecode, string iSourceCode)
- {
- //选取当前的最小的执行顺序
- string CurrentStep = GetStepCodeBySource(iSourceCode);
- DataTable dt = (DataTable)dh.ExecuteSql("select min(mcd_detno) detno from makecraftdetail where mcd_macode='" + iMakecode + "'", "select");
- string detno = dt.Rows[0]["detno"].ToString();
- //判断当前最小的执行顺序是否有记录
- if (dh.getRowCount("makecraftdetail", "mcd_stepcode='" + CurrentStep + "' and mcd_macode='" + iMakecode + "' and mcd_detno ='" + detno + "'") > 0)
- {
- if (!dh.CheckExist("MakeSerial", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakecode + "'"))
- {
- sql.Clear();
- sql.Append("Insert into MakeSerial (ms_id, ms_code, ms_sncode ,ms_prodcode, ms_indate,");
- sql.Append("ms_wccode,ms_craftcode,ms_craftname,ms_nextstepcode,ms_status,ms_makecode) select MAKESERIAL_SEQ.NEXTVAL,");
- sql.Append("'" + iSnCode + "','" + iSnCode + "',ma_prodcode,sysdate,ma_wccode,ma_craftcode,ma_craftname,'" + CurrentStep + "',0,ma_code ");
- sql.Append("from make left join makecraftdetail on ma_code =mcd_macode where ma_code='" + iMakecode + "' and mcd_stepcode='" + CurrentStep + "'");
- dh.ExecuteSql(sql.ToString(), "insert");
- }
- return true;
- }
- else
- return false;
- }
- /// <summary>
- /// 判断下一工序是否是送检工序
- /// </summary>
- /// <returns></returns>
- public bool CheckNextStepIfQC(string iSnCode, string iMakeCode, string iStepCode, string iCraftCode, string iUserName, out string oErrorMessage)
- {
- oErrorMessage = "";
- string IfQC = dh.getFieldDataByCondition("craft left join craftdetail on cd_crid=cr_id", "cd_ifoqc", "cr_code='" + iCraftCode + "' and cd_stepcode='" + iStepCode + "'").ToString();
- if (IfQC != "0" && IfQC != "")
- {
- DataTable dt = dh.getFieldsDataByCondition("make left join product on ma_prodcode=pr_code", new string[] { "ma_nowcheckqty", "pr_qcbatchqty", "ma_checkno", "ma_prodcode", "pr_qualmethod" }, "ma_code='" + iMakeCode + "'");
- if (dt.Rows.Count > 0)
- {
- string ma_nowcheckqty = dt.Rows[0]["ma_nowcheckqty"].ToString();
- string pr_qcbatchqty = dt.Rows[0]["pr_qcbatchqty"].ToString();
- string ma_checkno = dt.Rows[0]["ma_checkno"].ToString();
- string ma_prodcode = dt.Rows[0]["ma_prodcode"].ToString();
- string pr_qualmethod = dt.Rows[0]["pr_qualmethod"].ToString();
- if (pr_qcbatchqty != "" && pr_qcbatchqty != "0")
- {
- //当前批次的送检批数量大于物料资料中的抽检批数或者当前批次编号为空
- string checkno = "";
- if (int.Parse(ma_nowcheckqty == "" ? "0" : ma_nowcheckqty) >= int.Parse(pr_qcbatchqty) || ma_checkno == "")
- {
- //原有的抽检批次插入OQCBatch
- string ob_id = dh.GetSEQ("OQCBatch_SEQ");
- checkno = dh.GetSerialNumberByCaller("Make!CheckQC");
- sql.Clear();
- sql.Append("insert into OQCBatch (ob_id, ob_checkno,ob_makecode,ob_source,ob_indate,ob_checkman,ob_batchqty,ob_status,ob_prodcode,ob_projectcode)");
- sql.Append(" values('" + ob_id + "','" + checkno + "','" + iMakeCode + "', '工序',sysdate, '" + iUserName + "','" + ma_nowcheckqty + "','UNCHECK','" + ma_prodcode + "','" + pr_qualmethod + "')");
- sqls.Add(sql.ToString());
- sqls.Add("update makeserial set ms_checkno='" + checkno + "' where ms_makecode='" + iMakeCode + "' and ms_sncode='" + iSnCode + "'");
- sqls.Add("update make set ma_checkno='" + checkno + "',ma_nowcheckqty=1 where ma_code='" + iMakeCode + "'");
- }
- else
- {
- sqls.Add("update makeserial set ms_checkno='" + ma_checkno + "' where ms_makecode='" + iMakeCode + "' and ms_sncode='" + iSnCode + "'");
- sqls.Add("update make set ma_nowcheckqty= ma_nowcheckqty+1 where ma_code='" + iMakeCode + "'");
- }
- dh.ExecuteSQLTran(sqls.ToArray());
- sqls.Clear();
- //如果制造单的ma_checkno没有值则新加入一个值
- string checkno1 = checkno == "" ? ma_checkno : checkno;
- string obd_obid = dh.getFieldDataByCondition("oqcbatch", "ob_id", "ob_checkno='" + checkno1 + "'").ToString();
- //插入抽检批次明细表
- sql.Clear();
- sql.Append("insert into OQCBatchDetail (obd_id,obd_obid,obd_sncode,obd_outboxcode,obd_makecode,obd_checkno,obd_builddate) ");
- sql.Append("select OQCBatchDetail_SEQ.nextval,'" + obd_obid + "',ms_sncode,ms_outboxcode,ms_makecode,ms_checkno,");
- sql.Append("sysdate from makeserial where ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- dh.ExecuteSql(sql.ToString(), "insert");
- return true;
- }
- else
- {
- oErrorMessage = "请维护物料资料的抽检批数";
- return false;
- }
- }
- else
- {
- oErrorMessage = "制造单号不存在";
- return false;
- }
- }
- else
- {
- oErrorMessage = "当前工序的下一工序不是OQC检测";
- return false;
- }
- }
- /// <summary>
- /// 验证用户身份信息
- /// </summary>
- /// <param name="iUserCode"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
- {
- oErrorMessage = "";
- string SQL = "select em_code from employee where em_code=:UserName and em_password =:PassWord";
- DataTable dt;
- dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode, iPassWord);
- if (dt.Rows.Count > 0)
- return true;
- else
- {
- oErrorMessage = "用户名或者密码不正确!";
- return false;
- }
- }
- /// <summary>
- /// 验证用户身份信息和岗位资源
- /// </summary>
- /// <param name="iUserCode"></param>
- /// <param name="iPassWord"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool CheckUserAndSourcePassed(string iUserCode, string iSourceCode, out string oErrorMessage)
- {
- oErrorMessage = "";
- string SQL = "select em_code,em_type,em_name from employee where em_code=:UserName ";
- DataTable dt;
- dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode);
- if (dt.Rows.Count > 0)
- {
- string em_name = dt.Rows[0]["em_name"].ToString();
- if (dt.Rows[0]["em_type"].ToString() == "admin" && iSourceCode == "")
- {
- return true;
- }
- dt = dh.getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "ur_resourcecode" }, "eg_emcode = '" + iUserCode + "' and sc_statuscode='AUDITED'");
- //如果存在该编号
- if (dt.Rows.Count > 0)
- {
- //判断如果多个岗位资源存在,用户输入的只要在其中就行
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["ur_resourcecode"].ToString() == iSourceCode)
- return true;
- }
- oErrorMessage = "岗位资源编号错误或者未审核!";
- }
- else
- oErrorMessage = "岗位资源编号错误或者未审核!";
- }
- else
- oErrorMessage = "用户不存在!";
- return false;
- }
- /// <summary>
- /// 分配Mac地址和BT地址
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="oMac"></param>
- /// <param name="oBT"></param>
- /// <param name="oID1"></param>
- /// <param name="oID2"></param>
- /// <param name="oID3"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool GetAddressRangeByMakeCode(string iSnCode, string iMakeCode, out string oMac, out string oBT, out string oID1, out string oID2, out string oID3, out string oErrorMessage)
- {
- string id = "";
- oMac = "";
- oBT = "";
- oID1 = "";
- oID2 = "";
- oID3 = "";
- oErrorMessage = "";
- if (GetMakeInfo(iSnCode, out iMakeCode, out oErrorMessage))
- {
- DataTable dt = dh.getFieldsDataByCondition("MakeSerial", new string[] { "ms_mac", "ms_bt", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["ms_mac"].ToString() != "")
- {
- id = dt.Rows[0]["ms_id"].ToString();
- oMac = dt.Rows[0]["ms_mac"].ToString();
- oBT = dt.Rows[0]["ms_bt"].ToString();
- oID1 = dt.Rows[0]["ms_othid1"].ToString();
- oID2 = dt.Rows[0]["ms_othid2"].ToString();
- oID3 = dt.Rows[0]["ms_othid3"].ToString();
- return true;
- }
- //如果没有数据则从MakeIMEIList表中查询
- else
- {
- dt = dh.getFieldsDataByCondition("MakeIMEIList", new string[] { "mil_id", "mil_mac", "mil_bt", "mil_meid", "mil_netcode", "mil_psn", "mil_imei1", "mil_imei2", "mil_imei3", "mil_othid1", "mil_othid2", "mil_othid3" }, "mil_sncode='" + iSnCode + "' and mil_makecode='" + iMakeCode + "'");
- if (dt.Rows.Count > 0)
- {
- id = dt.Rows[0]["mil_id"].ToString();
- oMac = dt.Rows[0]["mil_mac"].ToString();
- oBT = dt.Rows[0]["mil_bt"].ToString();
- oID1 = dt.Rows[0]["mil_othid1"].ToString();
- oID2 = dt.Rows[0]["mil_othid2"].ToString();
- oID3 = dt.Rows[0]["mil_othid3"].ToString();
- return true;
- }
- else
- {
- dt = dh.getFieldsDataByCondition("MakeIMEIList", new string[] { "mil_id", "mil_mac", "mil_bt", "mil_meid", "mil_netcode", "mil_psn", "mil_imei1", "mil_imei2", "mil_imei3", "mil_othid1", "mil_othid2", "mil_othid3" }, "mil_sncode is null and mil_makecode is null order by mil_sncode");
- if (dt.Rows.Count > 0)
- {
- id = dt.Rows[0]["mil_id"].ToString();
- oMac = dt.Rows[0]["mil_mac"].ToString();
- oBT = dt.Rows[0]["mil_bt"].ToString();
- oID1 = dt.Rows[0]["mil_othid1"].ToString();
- oID2 = dt.Rows[0]["mil_othid2"].ToString();
- oID3 = dt.Rows[0]["mil_othid3"].ToString();
- //将已经分配的序列号的SN和MakeCode更新到MakeIMEIList表中
- dh.UpdateByCondition("MakeIMEIList", "mil_sncode='" + iSnCode + "',mil_makecode='" + iMakeCode + "',mil_status='已使用'", "mil_id=" + id);
- return true;
- }
- else
- {
- oErrorMessage = "当前序列号无可分配地址";
- return false;
- }
- }
- }
- }
- else
- {
- oErrorMessage = "序列号" + iSnCode + "不存在";
- return false;
- }
- }
- else return false;
- }
- /// <summary>
- /// 输入的 SN 号查找在制品是否有 IMEI 信息存在,如果存在则将 IMEI 信息传出,如果没有则在该工单下未使用的 IMEI 中随机分配一组
- /// 如果iIMEI1、iNetCode不为空,则分别作为获取的附件加条件。
- /// </summary>
- /// <param name="iSN"></param>
- /// <param name="iMO"></param>
- /// <param name="iIMEI1"></param>
- /// <param name="iNetCode"></param>
- /// <param name="oIMEI1"></param>
- /// <param name="oIMEI2"></param>
- /// <param name="oIMEI3"></param>
- /// <param name="oMEID"></param>
- /// <param name="oNetCode"></param>
- /// <param name="oPSN"></param>
- /// <param name="oMac"></param>
- /// <param name="oBT"></param>
- /// <param name="oID1"></param>
- /// <param name="oID2"></param>
- /// <param name="oID3"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool GetIMEIOrNetCodeRange(string iSnCode, string iMakeCode, string iIMEI1, string iNetCode, out string oIMEI1, out string oIMEI2, out string oIMEI3, out string oMEID, out string oNetCode, out string oPSN, out string oMac, out string oBT, out string oID1, out string oID2, out string oID3, out string oErrorMessage)
- {
- string id = "";
- oBT = "";
- oMEID = "";
- oMac = "";
- oPSN = "";
- oNetCode = "";
- oIMEI1 = "";
- oIMEI2 = "";
- oIMEI3 = "";
- oID1 = "";
- oID2 = "";
- oID3 = "";
- oErrorMessage = "";
- //先判断MakeSerial表的数据,是否已经烧入了,如已经烧入直接从MakeSerial表取数据
- //condition iIMEI1,iNETCode
- if (GetMakeInfo(iSnCode, out iMakeCode, out oErrorMessage))
- {
- DataTable dt = dh.getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "' and ms_netcode like '%" + iNetCode + "%' and ms_imei1 like '%" + iIMEI1 + "%'");
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["ms_mac"].ToString() != "")
- {
- id = dt.Rows[0]["ms_id"].ToString();
- oMac = dt.Rows[0]["ms_mac"].ToString();
- oBT = dt.Rows[0]["ms_bt"].ToString();
- oPSN = dt.Rows[0]["ms_psn"].ToString();
- oNetCode = dt.Rows[0]["ms_netcode"].ToString();
- oMEID = dt.Rows[0]["ms_meid"].ToString();
- oIMEI1 = dt.Rows[0]["ms_imei1"].ToString();
- oIMEI2 = dt.Rows[0]["ms_imei2"].ToString();
- oIMEI3 = dt.Rows[0]["ms_imei3"].ToString();
- oID1 = dt.Rows[0]["ms_othid1"].ToString();
- oID2 = dt.Rows[0]["ms_othid2"].ToString();
- oID3 = dt.Rows[0]["ms_othid3"].ToString();
- return true;
- }
- //如果没有数据则从MakeIMEIList表中查询
- else
- {
- dt = dh.getFieldsDataByCondition("MakeIMEIList", new string[] { "mil_id", "mil_mac", "mil_bt", "mil_meid", "mil_netcode", "mil_psn", "mil_imei1", "mil_imei2", "mil_imei3", "mil_othid1", "mil_othid2", "mil_othid3" }, "mil_sncode='" + iSnCode + "' and mil_makecode='" + iMakeCode + "' and mil_netcode like '%" + iNetCode + "%' and mil_imei1 like '%" + iIMEI1 + "%'");
- if (dt.Rows.Count > 0)
- {
- id = dt.Rows[0]["mil_id"].ToString();
- oMac = dt.Rows[0]["mil_mac"].ToString();
- oBT = dt.Rows[0]["mil_bt"].ToString();
- oPSN = dt.Rows[0]["mil_psn"].ToString();
- oNetCode = dt.Rows[0]["mil_netcode"].ToString();
- oMEID = dt.Rows[0]["mil_meid"].ToString();
- oIMEI1 = dt.Rows[0]["mil_imei1"].ToString();
- oIMEI2 = dt.Rows[0]["mil_imei2"].ToString();
- oIMEI3 = dt.Rows[0]["mil_imei3"].ToString();
- oID1 = dt.Rows[0]["mil_othid1"].ToString();
- oID2 = dt.Rows[0]["mil_othid2"].ToString();
- oID3 = dt.Rows[0]["mil_othid3"].ToString();
- return true;
- }
- else
- {
- dt = dh.getFieldsDataByCondition("MakeIMEIList", new string[] { "mil_id", "mil_mac", "mil_bt", "mil_meid", "mil_netcode", "mil_psn", "mil_imei1", "mil_imei2", "mil_imei3", "mil_othid1", "mil_othid2", "mil_othid3" }, "mil_sncode is null and mil_makecode is null and mil_netcode like '%" + iNetCode + "%' and mil_imei1 like '%" + iIMEI1 + "%' order by mil_sncode ");
- if (dt.Rows.Count > 0)
- {
- id = dt.Rows[0]["mil_id"].ToString();
- oMac = dt.Rows[0]["mil_mac"].ToString();
- oBT = dt.Rows[0]["mil_bt"].ToString();
- oPSN = dt.Rows[0]["mil_psn"].ToString();
- oNetCode = dt.Rows[0]["mil_netcode"].ToString();
- oMEID = dt.Rows[0]["mil_meid"].ToString();
- oIMEI1 = dt.Rows[0]["mil_imei1"].ToString();
- oIMEI2 = dt.Rows[0]["mil_imei2"].ToString();
- oIMEI3 = dt.Rows[0]["mil_imei3"].ToString();
- oID1 = dt.Rows[0]["mil_othid1"].ToString();
- oID2 = dt.Rows[0]["mil_othid2"].ToString();
- oID3 = dt.Rows[0]["mil_othid3"].ToString();
- //将已经分配的序列号的SN和MakeCode更新到MakeIMEIList表中
- dh.UpdateByCondition("MakeIMEIList", "mil_sncode='" + iSnCode + "',mil_makecode='" + iMakeCode + "',mil_status='已使用'", "mil_id=" + id);
- return true;
- }
- else
- {
- oErrorMessage = "当前序列号无可分配地址";
- return false;
- }
- }
- }
- }
- else
- {
- oErrorMessage = "序列号" + iSnCode + "不存在";
- return false;
- }
- }
- else return false;
- }
- /// <summary>
- /// 获取工单的最近一条执行记录
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="oMakeCode"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool GetMakeInfo(string iSnCode, out string oMakeCode, out string oErrorMessage)
- {
- //取MakeProcess表中的执行记录ID最大的一个工单的号码
- oMakeCode = "";
- oErrorMessage = "";
- oMakeCode = dh.getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_sncode='" + iSnCode + "' and ms_indate in (select max(ms_indate) from makeserial where ms_sncode='" + iSnCode + "')").ToString();
- if (oMakeCode != "")
- return true;
- else
- {
- oErrorMessage = "当前序列号" + iSnCode + "不存在生产记录";
- return false;
- }
- }
- /// <summary>
- /// 获取序列号的所有串号信息
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="oIMEI1"></param>
- /// <param name="oIMEI2"></param>
- /// <param name="oIMEI3"></param>
- /// <param name="oMEID"></param>
- /// <param name="oNetCode"></param>
- /// <param name="oPSN"></param>
- /// <param name="oMac"></param>
- /// <param name="oBT"></param>
- /// <param name="oCode1"></param>
- /// <param name="oCode2"></param>
- /// <param name="oCode3"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool GetSNAllInfo(string iSnCode, out string oIMEI1, out string oIMEI2, out string oIMEI3, out string oMEID, out string oNetCode, out string oPSN, out string oMac, out string oBT, out string oCode1, out string oCode2, out string oCode3, out string oID1, out string oID2, out string oID3, out string oErrorMessage)
- {
- oBT = "";
- oMEID = "";
- oMac = "";
- oPSN = "";
- oNetCode = "";
- oIMEI1 = "";
- oIMEI2 = "";
- oIMEI3 = "";
- oCode1 = "";
- oCode2 = "";
- oCode3 = "";
- oID1 = "";
- oID2 = "";
- oID3 = "";
- //通过序列号获取最近操作的工单号
- string MakeCode;
- if (GetMakeInfo(iSnCode, out MakeCode, out oErrorMessage))
- {
- DataTable dt = dh.getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_sncode='" + iSnCode + "'' and ms_makecode='" + MakeCode + "' ");
- if (dt.Rows.Count > 0)
- {
- oMac = dt.Rows[0]["ms_mac"].ToString();
- oBT = dt.Rows[0]["ms_bt"].ToString();
- oPSN = dt.Rows[0]["ms_psn"].ToString();
- oNetCode = dt.Rows[0]["ms_netcode"].ToString();
- oMEID = dt.Rows[0]["ms_meid"].ToString();
- oIMEI1 = dt.Rows[0]["ms_imei1"].ToString();
- oIMEI2 = dt.Rows[0]["ms_imei2"].ToString();
- oIMEI3 = dt.Rows[0]["ms_imei3"].ToString();
- oCode1 = dt.Rows[0]["ms_othcode1"].ToString();
- oCode2 = dt.Rows[0]["ms_othcode2"].ToString();
- oCode3 = dt.Rows[0]["ms_othcode3"].ToString();
- oID1 = dt.Rows[0]["ms_othid3"].ToString();
- oID2 = dt.Rows[0]["ms_othid3"].ToString();
- oID3 = dt.Rows[0]["ms_othid3"].ToString();
- return true;
- }
- else
- {
- oErrorMessage = "序列号" + iSnCode + "不存在";
- return false;
- }
- }
- else
- return false;
- }
- /// <summary>
- /// 记录操作日志
- /// </summary>
- /// <param name="iMakeCode"></param>
- /// <param name="iSnCode"></param>
- public void InsertMakeProcess(string iSnCode, string iMakeCode, string result, string iUserName)
- {
- 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,'" + iUserName + "',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='" + iSnCode + "' and ma_code='" + iMakeCode + "'");
- //插入makeprocess
- dh.ExecuteSql(sql.ToString(), "insert");
- sql.Clear();
- }
- /// <summary>
- /// 记录一般操作日志
- /// </summary>
- /// <param name="inMan"></param>
- /// <param name="Content"></param>
- /// <param name="Result"></param>
- /// <param name="Search"></param>
- /// <param name="Code"></param>
- public void InsertMessageLog(string inMan, string Content, string Result, string Search, string Code)
- {
- sql.Clear();
- sql.Append("insert into messagelog (ml_id,ml_date,ml_man,ml_content,ml_result,ml_search,code) ");
- sql.Append("values (messagelog_seq.nextval,sysdate,'" + inMan + "','" + Content + "','" + Result + "','" + Search + "','" + Code + "')");
- dh.ExecuteSql(sql.ToString(), "insert");
- }
- /// <summary>
- /// 保存Mac地址和BT地址
- /// </summary>
- /// <param name="iSN"></param>
- /// <param name="iWIFI"></param>
- /// <param name="iBT"></param>
- /// <param name="iCode1"></param>
- /// <param name="iCode2"></param>
- /// <param name="iCode3"></param>
- /// <param name="oErrMessage"></param>
- /// <returns></returns>
- public bool SetAddressInfo(string iSN, string iWIFI, string iBT, string iCode1, string iCode2, string iCode3, out string oErrMessage)
- {
- string MakeCode = "";
- if (GetMakeInfo(iSN, out MakeCode, out oErrMessage))
- {
- string sql = "update MakeSerial set ms_mac=:iWifi,ms_bt=:iBT,ms_othcode1=:iCode1,ms_othcode2=:iCode2,ms_othcode3=:iCode3 where ms_sncode='" + iSN + "' and ms_makecode='" + MakeCode + "'";
- dh.ExecuteSql(sql, "update", iWIFI, iBT, iCode1, iCode2, iCode3);
- if (dh.CheckExist("SnInfo", "si_sn='" + iSN + "'"))
- {
- sql = "update SnInfo set si_mac=:iMac,si_bt=:iBT,si_othcode1=:iCode1,si_othcode2=:iCode2,si_othcode3=:iCode3 where si_sncode='" + iSN + "'";
- dh.ExecuteSql(sql, "update", iWIFI, iBT, iCode1, iCode2, iCode3);
- }
- else {
- sql = "insert into SnInfo(si_id,si_sn,si_mac,si_bt,si_othcode1,si_othcode2,si_othcode3) values(SnInfo_seq.nextval,:iSn,:iWifi,:iBt,:iCode1,:iCode2,:iCode3)";
- dh.ExecuteSql(sql, "insert", iSN, iWIFI, iBT, iCode1, iCode2, iCode3);
- }
- return true;
- }
- else
- return false;
- }
- /// <summary>
- /// 方法说明:测试详细信息录入系统,针对一个SN多个测试项目结果可循环调用
- /// </summary>
- /// <param name="iSnCode">序列号</param>
- /// <param name="iClass"></param>
- /// <param name="iSubClass1"></param>
- /// <param name="iSubClass2"></param>
- /// <param name="iSubClass3"></param>
- /// <param name="iMaxValue"></param>
- /// <param name="iMinValue"></param>
- /// <param name="iActualValue"></param>
- /// <param name="iValue1"></param>
- /// <param name="iValue2"></param>
- /// <param name="iValue3"></param>
- /// <param name="iTestResult"></param>
- /// <param name="oErrMessage"></param>
- /// <returns></returns>
- public bool SetTestDetail(string iSnCode, string iMakeCode, string iClass, string iSubClass1, string iSubClass2, string iSubClass3, string iMaxValue, string iMinValue, string iActualValue, string iValue1, string iValue2, string iValue3, string iTestResult, string iSourceCode, out string oErrMessage)
- {
- oErrMessage = "";
- sql.Clear();
- sql.Append("Insert into STEPTESTDETAIL (STD_ID,STD_SN,STD_MAKECODE,STD_CLASS,STD_SUBCLASS1,STD_SUBCLASS2,");
- sql.Append("STD_SUBCLASS3,STD_MAXVALUE,STD_MINVALUE,STD_ACTUALVALUE,STD_VALUE1,STD_VALUE2,STD_VALUE3,STD_TESTRESULT,");
- sql.Append("STD_DATE,STD_RESCODE) values (STEPTESTDETAIL_SEQ.nextval,:std_sn,:std_makecode,");
- sql.Append(":std_class,:std_subclass1,:std_subclass2,:std_subclass3,:std_maxvalue,:std_minvalue,:std_actualvalue,:std_value1,");
- sql.Append(":std_value2,:std_value3,:std_testresult,sysdate,:std_record)");
- dh.ExecuteSql(sql.ToString(), "select", iSnCode, iMakeCode, iClass, iSubClass1, iSubClass2, iSubClass3, iMaxValue, iMinValue, iActualValue, iValue1, iValue2, iValue3, iTestResult, iSourceCode);
- return true;
- }
- /// <summary>
- /// 作业调用该方法将确认接收SN对应的IMEI及附属信息。
- /// </summary>
- /// <param name="iSN"></param>
- /// <param name="iMO"></param>
- /// <param name="iIMEI1"></param>
- /// <param name="iIMEI2"></param>
- /// <param name="iIMEI3"></param>
- /// <param name="iMEID"></param>
- /// <param name="iNetCode"></param>
- /// <param name="iPSN"></param>
- /// <param name="iID1"></param>
- /// <param name="iBT"></param>
- /// <param name="iID1"></param>
- /// <param name="iID2"></param>
- /// <param name="iID3"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool SetIMEIInfo(string iSnCode, string iMakeCode, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iNetCode, string iPSN, string iID1, string iID2, string iID3, out string oErrorMessage)
- {
- oErrorMessage = "";
- string sql = "update MakeSerial set ms_imei1=:iIMEI1 ,ms_imei2=:iIMEI2 ,ms_imei3=:iIMEI3 ,ms_netcode=:iNetCode ,ms_psn=:iPSN ,ms_othcode1=:iCode1 ,ms_othcode2=:iCode2 ,ms_othcode3=:iCode3 where ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'";
- dh.ExecuteSql(sql, "update", iIMEI1, iIMEI2, iIMEI3, iNetCode, iPSN, iID1, iID2, iID3);
- return true;
- }
- /// <summary>
- /// 执行不良信息采集
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iUserName"></param>
- /// <param name="iSourceCode"></param>
- /// <param name="iBadCode"></param>
- /// <param name="iBadRemark"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool SetTestNGDetail(string iSnCode, string iMakeCode, string iUserName, string iSourceCode, string iResult, string[] iBadCode, string[] iBadRemark, out string oErrorMessage)
- {
- oErrorMessage = "";
- string StepCode = "";
- string StepName = "";
- if (iResult == "" || iResult == null)
- {
- iResult = "检查未通过";
- }
- GetStepCodeAndNameBySource(iSourceCode, ref StepCode, ref StepName);
- sql.Clear();
- sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,");
- sql.Append("mb_indate,mb_stepcode,mb_sourcecode,mb_badcode,mb_badtable,mb_soncode,mb_status,mb_badremark)");
- sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + iUserName + "',sysdate,'" + StepCode + "',ms_sourcecode,:bc_code,'',");
- sql.Append("sp_soncode,'0',:bc_remark from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
- sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSnCode + "'");
- dh.BatchInsert(sql.ToString(), new string[] { "bc_code", "bc_remark" }, iBadCode, iBadRemark);
- //更新序列号状态,待维修,返修工序
- string st_rstepcode = dh.getFieldDataByCondition("step", "st_rstepcode", "st_code='" + StepCode + "'").ToString();
- sql.Clear();
- sql.Append("update makeserial set ms_status = 3,ms_nextstepcode ='" + st_rstepcode + "', ");
- sql.Append("ms_stepcode ='" + StepCode + "' where ms_sncode ='" + iSnCode + "' and ms_makecode ='" + iMakeCode + "'");
- dh.ExecuteSql(sql.ToString(), "update");
- //更新makecraftdetail 工单采集记录表,根据工单号和工序编号 记录当前测试工序采集数量
- dh.UpdateByCondition("makecraftdetail", "mcd_inqty=mcd_inqty+1,mcd_outqty = mcd_outqty + 1", "mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "'");
- //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
- dh.UpdateByCondition("makeserial", "ms_paststep = ms_paststep ||'," + StepCode + "'", "ms_sncode='" + iSnCode + "'");
- //记录操作日志
- InsertMakeProcess(iSnCode, iMakeCode, iResult, iUserName);
- //判断当前采集点是否为扣料工序cd_ifreduce =-1 则为扣料工序
- SetCollectionFinish(iSnCode, iMakeCode, iUserName, iSourceCode, out oErrorMessage);
- return true;
- }
- /// <summary>
- /// 判断是否扣料工序,执行扣料,执行上料表记录
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iUserName"></param>
- /// <param name="iSourceCode"></param>
- public bool SetCollectionFinish(string iSnCode, string iMakeCode, string iUserName, string iSourceCode, out string oErrorMessage)
- {
- string StepCode = "";
- string StepName = "";
- string LineCode = "";
- oErrorMessage = "";
- GetStepCodeAndNameAndLineBySource(iSourceCode, ref StepCode, ref StepName, ref LineCode);
- if (StepCode == "" && StepName == "")
- {
- oErrorMessage = "当前岗位资源找不到对应工序,请先进行维护";
- return false;
- }
- sql.Clear();
- sql.Append("select nvl(cd_ifreduce,0) cd_ifreduce from craft left join ");
- sql.Append("craftdetail on cd_crid=cr_id where cr_code=(select ma_craftcode from makeserial left join make on ma_code = ms_makecode ");
- sql.Append("where ms_sncode = '" + iSnCode + "') and cd_stepcode='" + StepCode + "'");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- sql.Clear();
- if (dt.Rows.Count > 0)
- {
- string cd_ifreduce = dt.Rows[0][0].ToString();
- if (cd_ifreduce == "-1")
- {
- sql.Clear();
- sql.Append("select dsl_location,dsl_table, max(dsl_baseqty) baseqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and ");
- sql.Append("dsl_linecode='" + LineCode + "' and dsl_status=0 and dsl_remainqty>0 and dsl_invalidtime is null group by dsl_location,dsl_table");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- sql.Clear();
- sql.Append("selet dsl_id,dsl_remainqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and dsl_linecode='" + LineCode + "' ");
- sql.Append("and dsl_status=0 and dsl_remainqty>0 and dsl_invalidtime is null and rownum<3 order by dsl_id asc ");
- DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- for (int j = 0; j < dt.Rows.Count; j++)
- {
- //外层循环的值dt
- double baseqty = (double)dt.Rows[i]["baseqty"];
- double dsl_remainqty = (double)dt.Rows[i]["dsl_remainqty"];
- //内层循环的值dt1
- string dsl_id = dt1.Rows[j]["dsl_id"].ToString();
- if (baseqty > 0)
- {
- if (dsl_remainqty <= baseqty)
- {
- sql.Clear();
- sql.Append("update devsmtlocation set dsl_remainqty=0,dsl_invalidtime =sysdate, dsl_validtime =(case when dsl_validtime ");
- sql.Append("is null then sysdate else dsl_validtime),dsl_status=-1 where dsl_id=" + dsl_id);
- dh.ExecuteSql(sql.ToString(), "update");
- baseqty -= dsl_remainqty;
- }
- else
- {
- sql.Clear();
- sql.Append("update devsmtlocation set dsl_remainqty=dsl_remainqty-NVL(dsl_baseqty,0),dsl_efftime=(case when");
- sql.Append("dsl_validtime is null then sysdate else dsl_validtime) where dsl_id=" + dsl_id);
- dh.ExecuteSql(sql.ToString(), "update");
- baseqty = 0;
- }
- }
- else
- dh.ExecuteSql("update devsmtlocation set dsl_efftime=sysdate where dsl_id=" + dsl_id, "update");
- }
- }
- sql.Clear();
- sql.Append("insert into ReduceStepRecord (rsd_id,rsd_macode,rsd_maprodcode,rsd_table,rsd_sncode,rsd_linecode,rsd_sourcecode) select ");
- sql.Append("ReduceStepRecord_SEQ.nextval,'" + iMakeCode + "',ma_prodcode,'','" + iSnCode + "','" + LineCode + "','" + iSourceCode + "' ");
- sql.Append("from make where ma_code='" + iMakeCode + "'");
- dh.ExecuteSql(sql.ToString(), "insert");
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 上料采集
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iBarcode"></param>
- /// <param name="iSonCode"></param>
- /// <param name="iSourceCode"></param>
- /// <param name="iUserName"></param>
- /// <param name="iSonID"></param>
- /// <param name="iType"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool SetMaterialUp(string iSnCode, string iMakeCode, string iBarcode, string iSonCode, string iSourceCode, string iUserName, string iSonID, out string oErrorMessage)
- {
- oErrorMessage = "";
- string StepCode = "";
- string StepName = "";
- string iRemainQty = dh.getFieldDataByCondition("barcode", "bar_remain", "bar_code='" + iBarcode + "'").ToString();
- GetStepCodeAndNameBySource(iSourceCode, ref StepCode, ref StepName);
- DataTable dt = (DataTable)dh.ExecuteSql("select cm_id from craftmaterial where cm_sncode='" + iSnCode + "' and cm_barcode='" + iBarcode + "' and cm_soncode='" + iSonCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- oErrorMessage = "条码已经上料";
- return false;
- }
- else
- {
- sql.Clear();
- sql.Append("insert into Craftmaterial (cm_id ,cm_makecode,cm_maid,cm_maprodcode, cm_soncode, cm_mscode, cm_sncode, cm_stepcode, cm_stepname,");
- sql.Append("cm_craftcode,cm_craftname,cm_barcode,cm_inqty,cm_indate,cm_inman,cm_linecode,cm_wccode,cm_sourcecode,cm_spid)");
- sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode, sp_soncode,ms_code,ms_sncode,mcd_stepcode,");
- sql.Append("mcd_stepname,ma_craftcode,ma_craftname,'" + iBarcode + "',1,sysdate,'" + iUserName + "',ma_linecode,ma_wccode,");
- sql.Append("'" + iSourceCode + "','" + iSonID + "' from make left join makecraftdetail on mcd_macode=ma_code left join stepproduct on sp_stepcode=mcd_stepcode ");
- sql.Append("and sp_craftcode=ma_craftcode and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code ");
- sql.Append("where ma_code='" + iMakeCode + "'and sp_id=" + iSonID + " and mcd_stepcode = '" + StepCode + "' and ms_sncode='" + iSnCode + "'");
- dh.ExecuteSql(sql.ToString(), "insert");
- return true;
- }
- }
- /// <summary>
- /// 执行下料操作
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iBarCode"></param>
- /// <param name="iCurrentStep"></param>
- /// <param name="iUserName"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool SetMaterialDown(string iSnCode, string iBarCode, string iCurrentStep, string iUserName, out string oErrorMessage)
- {
- //序列号不为空的时候
- oErrorMessage = "";
- DataTable dt;
- //对序列号进行验证
- dt = (DataTable)dh.ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_sncode='" + iBarCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- string ms_status = dt.Rows[0]["ms_status"].ToString();
- string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
- string ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
- if (ms_status == "1" && ms_stepcode != iCurrentStep)
- oErrorMessage = "当前工序不是" + iCurrentStep + "\n";
- else if (ms_status == "0" && ms_stepcode != iCurrentStep)
- oErrorMessage = "当前工序不是" + iCurrentStep + "";
- else if (ms_status == "2" && ms_nextstepcode != iCurrentStep)
- oErrorMessage = "该序列号已经包装";
- else
- {
- dt = (DataTable)dh.ExecuteSql("select * from craftmaterial where cm_sncode='" + iSnCode + "'", "select");
- if (dt.Rows.Count > 0)
- oErrorMessage = "请采集需要下料的序列号";
- else
- oErrorMessage = "该序列号未上料,无需下料";
- }
- }
- if (oErrorMessage == "")
- {
- dt = (DataTable)dh.ExecuteSql("select cm_id,cm_stepcode,ms_makecode,cm_mccode from craftmaterial left join makeserial on cm_makecode=ms_makecode and cm_sncode=ms_sncode where ms_sncode='" + iSnCode + "' and cm_barcode='" + iBarCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- string cm_id = dt.Rows[0]["cm_id"].ToString();
- string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
- string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
- string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
- dh.ExecuteSql("delete from Craftmaterial where cm_id=" + cm_id, "delete");
- InsertMakeProcess(ms_macode, iSnCode, "下料成功", iUserName);
- int count = dh.getRowCount("craftMaterial", "cm_mccode='" + cm_mccode + "' and cm_stepcode='" + cm_stepcode + "' and cm_sncode='" + iSnCode + "'");
- if (count == 0)
- dh.UpdateByCondition("makecraftdetail", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1,mcd_okqty = mcd_okqty - 1", "mcd_mccode='" + cm_mccode + "' and mcd_stepcode='" + cm_stepcode + "'");
- }
- return true;
- }
- else
- return false;
- }
- /// <summary>
- /// 设置良品采集结果,iResult含有“批次通过”按抽检批次通过
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iSourceCode"></param>
- /// <param name="iUserName"></param>
- /// <param name="iResult"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public bool UpdateMakeMessage(string iSnCode, string iMakeCode, string iSourceCode, string iUserName, string iResult, out string oErrorMessage)
- {
- oErrorMessage = "";
- string StepCode = "";
- string StepName = "";
- string LineCode = "";
- if (iResult == "" || iResult == null)
- {
- iResult = "测试合格";
- }
- GetStepCodeAndNameAndLineBySource(iSourceCode, ref StepCode, ref StepName, ref LineCode);
- //判断是否上料工序,如果是的话执行该步骤
- DataTable dt = dh.getFieldsDataByCondition("make left join craft on cr_code=ma_craftcode left join craftdetail on cd_crid=cr_id", new string[] { "cd_ifinput", "cr_code" }, "ma_code='" + iMakeCode + "' and cd_stepcode='" + StepCode + "'");
- string Yes_No = dh.GetConfig("BatchNumber", "MESSetting").ToString();
- string cr_code = "";
- if (dt.Rows.Count > 0)
- {
- cr_code = dt.Rows[0]["cr_code"].ToString();
- if (dt.Rows[0]["cd_ifinput"].ToString() != "0")
- {
- sql.Clear();
- sql.Append("select wm_concat(mss_prodcode) code,count(1) cn from (select sum(nvl(mss_remain,0))remain,mss_prodcode,max(mss_baseqty) mss_baseqty ");
- sql.Append("from makesourcestock where mss_makecode='" + iMakeCode + "' and mss_stepcode='" + StepCode + "' ");
- sql.Append("and mss_linecode='" + LineCode + "' group by mss_prodcode)T where T.remain<mss_baseqty and rownum<20");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- //如果配置的是Yes
- if (Yes_No != "0")
- {
- //如果批次料不足
- if (dt.Rows.Count > 0 && int.Parse(dt.Rows[0]["cn"].ToString()) > 0)
- {
- oErrorMessage += "批次物料:" + iSnCode + "," + dt.Rows[0]["code"] + "岗位备料不足";
- return false;
- }
- }
- //如果配置的是No 或者批次料足够
- else if (Yes_No == "0" || dt.Rows.Count == 0)
- {
- //扣减批次数量,插入数据至用料表
- sql.Clear();
- sql.Append("select mss_prodcode , max(mss_baseqty) baseqty from makesourcestock ");
- sql.Append("mss_makecode='" + iMakeCode + "' and mss_stepcode='" + StepCode + "' and mss_linecode='" + LineCode + "' group by mss_prodcode");
- DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- for (int i = 0; i < dt1.Rows.Count; i++)
- {
- string prodcode = dt1.Rows[i]["mss_prodcode"].ToString();
- //本次上料需要扣除的数量
- int baseqty = int.Parse(dt1.Rows[i]["baseqty"].ToString());
- sql.Clear();
- sql.Append("select mss_remain,mss_useqty,mss_id ,mss_barcode from makesourcestock where mss_makecode='" + iMakeCode + "' and ");
- sql.Append("mss_stepcode='" + StepCode + "' and mss_prodcode='" + prodcode + "' and mss_linecode='" + LineCode + "' and mss_remain >0 order by mss_id asc");
- DataTable dt2 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- for (int j = 0; i < dt2.Rows.Count; j++)
- {
- int remain = int.Parse(dt2.Rows[j]["mss_remain"].ToString());
- int useqty = int.Parse(dt2.Rows[j]["mss_useqty"].ToString());
- string mss_id = dt2.Rows[j]["mss_id"].ToString();
- string barcode = dt2.Rows[j]["mss_barcode"].ToString();
- //如果可扣数量大于0
- if (baseqty > 0)
- {
- //并且可扣数量大于剩余数量
- if (baseqty > remain)
- {
- sql.Clear();
- sql.Append("update makesourcestock set mss_useqty=nvl(mss_useqty,0)+mss_remain,mss_remain = 0 where mss_id='" + mss_id + "' ");
- dh.ExecuteSql(sql.ToString(), "update");
- //扣减剩余数量
- baseqty -= remain;
- }
- else if (remain >= baseqty)
- {
- dh.ExecuteSql("update makesourcestock set mss_remain = mss_remain-baseqty where mss_id =" + mss_id, "select");
- baseqty = 0;
- }
- }
- }
- }
- }
- }
- }
- //查询批次和批数量
- int batchqty = 0;
- string checkno = "";
- dt = (DataTable)dh.ExecuteSql("select count(ms_checkno) count,ms_checkno from makeserial where ms_checkno=(select ms_checkno from makeserial where ms_sncode='" + iSnCode + "') group by ms_checkno", "select");
- if (dt.Rows.Count > 0)
- {
- batchqty = int.Parse(dt.Rows[0]["count"].ToString());
- checkno = dt.Rows[0]["ms_checkno"].ToString();
- }
- object nextstepcode = dh.getFieldDataByCondition("makecraftdetail", "mcd_nextstepcode", "mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "'");
- if (iResult.Contains("批次通过") && dt.Rows.Count > 0)
- {
- //更新执行的数量
- sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty+" + batchqty + ",mcd_outqty = mcd_outqty + " + batchqty + ",mcd_okqty = mcd_okqty + " + batchqty + " where mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "' ");
- //更新makeSerial 的下一工序
- sqls.Add("update makeserial set ms_paststep = ms_paststep || '," + StepCode + "',ms_nextstepcode='" + nextstepcode.ToString() + "' where ms_checkno='" + checkno + "'");
- }
- else
- {
- //更新执行的数量
- sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty+1,mcd_outqty = mcd_outqty + 1,mcd_okqty = mcd_okqty + 1 where mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "' ");
- //更新makeSerial 的下一工序
- sqls.Add("update makeserial set ms_paststep = ms_paststep || '," + StepCode + "',ms_nextstepcode='" + nextstepcode.ToString() + "' where ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- }
- //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
- dh.ExecuteSQLTran(sqls.ToArray());
- sqls.Clear();
- //记录操作日志
- InsertMakeProcess(iSnCode, iMakeCode, iResult, iUserName);
- //检测下道工序是否存在,不存在 更新状态为已完成
- if (nextstepcode == null || nextstepcode.ToString() == "")
- {
- if (iResult.Contains("批次通过"))
- {
- sqls.Add("update make set ma_madeqty=ma_madeqty+" + batchqty + " where ma_code='" + iMakeCode + "'");
- sqls.Add("update makeserial set ms_status=2 where ms_checkno='" + checkno + "'");
- }
- else
- {
- sqls.Add("update make set ma_madeqty=ma_madeqty+1 where ma_code='" + iMakeCode + "'");
- sqls.Add("update makeserial set ms_status=2 where ms_sncode='" + iSnCode + "'");
- }
- dh.ExecuteSQLTran(sqls.ToArray());
- sqls.Clear();
- }
- else
- {
- CheckNextStepIfQC(iSnCode, iMakeCode, nextstepcode.ToString(), cr_code, iUserName, out oErrorMessage);
- }
- // 将数据插入craftmaterial表
- SetCollectionFinish(iSnCode, iMakeCode, iUserName, iSourceCode, out oErrorMessage);
- return true;
- }
- /// <summary>
- /// 获取执行步骤代码,名称和线别
- /// </summary>
- /// <param name="Source"></param>
- /// <param name="StepCode"></param>
- /// <param name="StepName"></param>
- /// <param name="LineCode"></param>
- private void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
- {
- DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
- if (dt.Rows.Count > 0)
- {
- StepCode = dt.Rows[0]["sc_stepcode"].ToString();
- StepName = dt.Rows[0]["sc_stepname"].ToString();
- LineCode = dt.Rows[0]["sc_linecode"].ToString();
- }
- }
- /// <summary>
- /// 获取步骤代码和名称
- /// </summary>
- /// <param name="Source"></param>
- /// <param name="StepCode"></param>
- /// <param name="StepName"></param>
- private void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
- {
- DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
- if (dt.Rows.Count > 0)
- {
- StepCode = dt.Rows[0]["sc_stepcode"].ToString();
- StepName = dt.Rows[0]["sc_stepname"].ToString();
- }
- }
- /// <summary>
- /// 获取步骤代码
- /// </summary>
- /// <param name="Source"></param>
- /// <returns></returns>
- private string GetStepCodeBySource(string Source)
- {
- return dh.getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
- }
- }
- }
|