1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using UAS_MES.DataOperate;
- namespace UAS_MES.PublicMethod
- {
- class LogicHandler
- {
- public LogicHandler() { }
- static DataHelper dh = new DataHelper();
- //用于拼接SQL
- static StringBuilder sql = new StringBuilder();
- //用于存放批量执行的SQL
- static List<string> sqls = new List<string>();
- /// <summary>
- /// 检测当前工序是否正确,如果是第一道工序则进行插入MakeSerial表
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iSourceCode"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public static bool CheckCurrentStepAndIfFirst(string iSnCode, string iMakeCode, string iSourceCode, string iCaller, out bool oIfFirst, out string oErrorMessage)
- {
- oErrorMessage = "";
- oIfFirst = false;
- if (iSnCode == "")
- {
- oErrorMessage = "序列号不能为空值";
- return false;
- }
- string StepCode = "";
- string StepName = "";
- string LineCode = "";
- //如果传入的工单为空的话
- if (iMakeCode == "")
- if (!GetMakeInfo(iSnCode, out iMakeCode, out oErrorMessage))
- return false;
- string cd_ifinput = "";
- string cr_code = "";
- //获取岗位资源对应的工序编号和名称
- GetStepCodeAndNameAndLineBySource(iSourceCode, ref StepCode, ref StepName, ref LineCode);
- string fo_class = dh.getFieldDataByCondition("cs_form", "fo_class", "fo_caller='" + iCaller + "'").ToString();
- if (fo_class != "")
- {
- DataTable dt1 = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_makecode", "ms_status" }, "ms_sncode='" + iSnCode + "'");
- if (dt1.Rows.Count > 0)
- {
- string macode = dt1.Rows[0]["ms_makecode"].ToString();
- if (macode == "")
- {
- oErrorMessage = "序列号" + iSnCode + "未绑定工单";
- return false;
- }
- if (dt1.Rows[0]["ms_status"].ToString() == "2")
- {
- oErrorMessage = "序列号" + iSnCode + "对应工单已完工";
- return false;
- }
- if (macode != iMakeCode)
- {
- oErrorMessage = "该序列号已绑定到工单" + macode;
- return false;
- }
- }
- sql.Clear();
- sql.Append("select " + fo_class + ",cd_ifinput ifinput,cr_code from make left join craft on cr_code=ma_craftcode left join craftdetail on cd_crid=cr_id ");
- sql.Append("where ma_code='" + iMakeCode + "' and cd_stepcode='" + StepCode + "'");
- //获取的行号不等于0,存在记录检测通过
- dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- if (dt1.Rows.Count > 0)
- {
- cd_ifinput = dt1.Rows[0]["ifinput"].ToString();
- cr_code = dt1.Rows[0]["cr_code"].ToString();
- if (dt1.Rows[0][fo_class].ToString() != "-1")
- {
- //返回具体的工单信息
- string serial = "";
- switch (fo_class)
- {
- case "cd_ifinput":
- serial = "上料采集";
- break;
- case "cd_ifoqc":
- serial = "OQC";
- break;
- case "cd_ifpack":
- serial = "包装采集";
- break;
- case "cd_ifsnchange":
- serial = "序列转换";
- break;
- case "cd_iftest":
- serial = "测试采集";
- break;
- default:
- break;
- }
- oErrorMessage = "当前岗位对应的工序不是" + serial + "工序";
- return false;
- }
- }
- else
- {
- oErrorMessage = "当前岗位资源对应的工序不属于工单号" + iMakeCode;
- return false;
- }
- }
- if (!CheckMakeStatus(iMakeCode, out oErrorMessage))
- {
- return false;
- }
- //验证当前执行的工序是否正确
- DataTable dt = (DataTable)dh.ExecuteSql("select ms_nextstepcode,ms_stepcode from makeserial where ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- string CurrentStep = dt.Rows[0]["ms_nextstepcode"].ToString();
- string LastStepCode = dt.Rows[0]["ms_stepcode"].ToString();
- if (CurrentStep != "")
- {
- //工序不等于上一工序和本工序
- if (CurrentStep != StepCode && LastStepCode != StepCode)
- {
- oErrorMessage = "序列号" + iSnCode + "的当前工序是" + CurrentStep + ",当前岗位的工序是" + StepName;
- return false;
- }
- }
- else
- {
- oErrorMessage = "序列号" + iSnCode + "无可继续执行工序(已完工或者序列号不存在)";
- return false;
- }
- }
- //判断是否是第一道工序
- 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='" + StepCode + "' and mcd_macode='" + iMakeCode + "' and mcd_detno ='" + detno + "'") > 0)
- {
- if (!dh.CheckExist("MakeSerial", "ms_sncode='" + iSnCode + "'"))
- {
- //判断当前工单的数量是否已经超出了完工数量
- int ma_qty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code='" + iMakeCode + "'").ToString());
- //查询除了报废的之外的记录数量
- int ms_sncodecount = int.Parse(dh.getFieldDataByCondition("makeserial", "count(ms_sncode)", "ms_makecode='" + iMakeCode + "' and ms_status<>3").ToString());
- //如果MakeSerial表的记录数已经达到了工单数量
- if (ma_qty > ms_sncodecount)
- {
- 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,'" + StepCode + "',1,ma_code ");
- sql.Append("from make left join makecraftdetail on ma_code =mcd_macode where ma_code='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "'");
- dh.ExecuteSql(sql.ToString(), "insert");
- oErrorMessage = "获取序列号" + iSnCode + "成功,";
- oIfFirst = true;
- }
- else
- {
- oErrorMessage = "当前生产数量已达到完工数量";
- return false;
- }
- }
- }
- //判断岗位备料是否足够
- string Yes_No = dh.GetConfig("BatchNumber", "MESSetting").ToString();
- if (cd_ifinput != "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;
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 检测当前的岗位资源对应的工序
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iSource"></param>
- /// <param name="oErrMessage"></param>
- /// <returns></returns>
- public static bool CheckCurrentStep(string iSnCode, string iMakeCode, string iSource, out string oErrMessage)
- {
- if (GetMakeInfo(iSnCode, out iMakeCode, out oErrMessage))
- {
- 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;
- }
- }
- else return false;
- }
- /// <summary>
- /// 判断工单是否已经下放
- /// </summary>
- /// <param name="iMaCode"></param>
- /// <returns></returns>
- public static bool CheckMakeStatus(string iMaCode, out string ErrorMessage)
- {
- string ma_statuscode = dh.getFieldDataByCondition(" make ", "ma_statuscode", "ma_code='" + iMaCode + "' ").ToString();
- ErrorMessage = "";
- if (ma_statuscode == "")
- {
- ErrorMessage = "工单号" + iMaCode + "不存在";
- return false;
- }
- if (ma_statuscode == "STARTED")
- return true;
- else
- {
- ErrorMessage = "工单必须是已下放状态";
- return false;
- }
- }
- /// <summary>
- /// 判断当前工序是否是第一道工序
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakecode"></param>
- /// <param name="iSourceCode"></param>
- /// <returns></returns>
- public static 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 static 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 static 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 static 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;
- }
- public static bool CheckStepAttribute(string iCaller, string iSource, out string oErrorMessage)
- {
- oErrorMessage = "";
- string[] param = new string[] { iCaller, iSource, oErrorMessage };
- dh.CallProcedure("CS_CHECKSTEPATTRIBUTE", ref param);
- if (oErrorMessage == "" || oErrorMessage == null)
- return true;
- else
- return false;
- }
- public static bool CheckStepSNAndMacode(string iMakeCode, string iSource, string iSN, string iUserCode, out string oMakeCode, out string oMsID, out string oErrorMessage)
- {
- oErrorMessage = "";
- oMakeCode = "";
- oMsID = "";
- string[] param = new string[] { iMakeCode, iSource, iSN, iUserCode, oMakeCode, oMsID, oErrorMessage };
- dh.CallProcedure("CS_CHECKSTEPSNANDMACODE", ref param);
- oMakeCode = param[4];
- oMsID = param[5];
- oErrorMessage = param[6];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
- return true;
- else
- 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 static 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 static 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 static 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>
- /// 获取送检批次,根据不同的iOQCStep执行不同的操作,查询到有具体的信息时返回Form和Detail的两个DataTable
- /// iOQCStep 有四个固定参数
- /// OQCSENDCHECK 生成送检批
- /// OQCPLANMAINTAIN 抽样计划维护
- /// OQCDATACOLLECTION 抽样数据采集
- /// OQCRESULTDETERMINE 批结果判定
- /// </summary>
- /// <returns></returns>
- public static DataTable[] GetOQCBatch(string iSnCode, string iOutBoxCode, string iCheckNo, string iOQCStep, out string oErrorMessage)
- {
- oErrorMessage = "";
- string SQL = "";
- string ms_checkno = "";
- DataTable dt = new DataTable();
- if (iCheckNo != "")
- return GetBatch(iCheckNo, iOQCStep, out oErrorMessage);
- else if (iSnCode != "")
- {
- SQL = "select ms_checkno from makeserial where ms_sncode='" + iSnCode + "' or ms_psn='" + iSnCode + "'";
- dt = (DataTable)dh.ExecuteSql(SQL, "select");
- if (dt.Rows.Count == 0)
- {
- oErrorMessage = "序列号" + iSnCode + "不存在";
- return null;
- }
- else
- {
- if (dt.Rows[0]["ms_checkno"].ToString() == "")
- {
- oErrorMessage = "该序列号没有送检批次号";
- return null;
- }
- else
- ms_checkno = dt.Rows[0]["ms_checkno"].ToString();
- }
- }
- else if (iOutBoxCode != "")
- {
- SQL = "select ms_checkno from MES_PACKAGE_VIEW left join makeserial on v_barcode=ms_sncode where v_outboxcode='" + iOutBoxCode + "' ";
- dt = (DataTable)dh.ExecuteSql(SQL, "select");
- if (dt.Rows.Count == 0)
- {
- oErrorMessage = "该箱号不存在";
- return null;
- }
- else
- {
- if (dt.Rows[0]["ms_checkno"].ToString() == "")
- {
- oErrorMessage = "该箱号没有送检批次号";
- return null;
- }
- else
- ms_checkno = dt.Rows[0]["ms_checkno"].ToString();
- }
- }
- if (ms_checkno != "")
- {
- return GetBatch(ms_checkno, iOQCStep, out oErrorMessage);
- }
- else
- {
- oErrorMessage = "送检批次不存在";
- return null;
- }
- }
- /// <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 static 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>
- /// 第一个是Form的主表信息,第二个是Grid的信息
- /// </summary>
- /// <param name="iCheckNo"></param>
- /// <returns></returns>
- private static DataTable[] GetBatch(string iCheckNo, string iOQCStep, out string oErrorMessage)
- {
- DataTable Form = new DataTable();
- DataTable Grid = new DataTable();
- oErrorMessage = "";
- switch (iOQCStep.ToUpper())
- {
- case "OQCSENDCHECK":
- sql.Clear();
- sql.Append("select count(1) ob_batchqty,obd_outboxcode,obd_makecode ma_code, obd_id from OQCBatchdetail ");
- sql.Append("where obd_checkno = '" + iCheckNo + "' group by obd_outboxcode,obd_makecode ,obd_id");
- Grid = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- Form = (DataTable)dh.ExecuteSql("select ob_id,ob_status,ob_prodcode,ob_batchqty,ob_source,ob_checkno from OQCBatch where ob_checkno='" + iCheckNo + "'", "select");
- if (Form.Rows.Count > 0)
- {
- if (Form.Rows[0]["ob_source"].ToString() == "新增" && Form.Rows[0]["ob_status"].ToString() == "ENTERING")
- {
- sql.Clear();
- sql.Append("select ob_id,ob_status,ob_prodcode ma_prodcode,ob_batchqty,ob_source,ob_checkno,obd_id,obd_outboxcode,obd_makecode ma_code,count(1) cn from OQCBatch left join OQCBatchdetail ");
- sql.Append("on obd_obid = ob_id where ob_checkno ='" + iCheckNo + "' group by ob_id,ob_status,ob_prodcode,ob_batchqty,ob_source,ob_checkno,obd_outboxcode,obd_makecode,obd_id");
- Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- }
- else
- oErrorMessage = "自动生成的抽检批次号不允许在该页面操作,或者该抽检批次号不是在录入状态";
- }
- else
- oErrorMessage = "该送检批次不存在";
- break;
- case "OQCPLANMAINTAIN":
- sql.Clear();
- sql.Append("select ob_prodcode,ob_id,ob_checkno,ob_projectcode,ob_batchqty,ob_source,ob_remark,");
- sql.Append("ob_status,pr_id,pr_detail,pr_kind,pr_manutype,pr_qualmethod,nvl(ob_aqlcode,pr_aql)ob_aqlcode from OQCBatch left join product on ");
- sql.Append("pr_code=ob_prodcode where ob_checkno='" + iCheckNo + "'");
- Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- sql.Clear();
- if (Form.Rows.Count > 0)
- {
- string pr_id;
- //判断状态是否是待检验
- if (Form.Rows[0]["ob_status"].ToString() == "UNCHECK")
- {
- //判断送检方案是否为空
- if (Form.Rows[0]["ob_projectcode"].ToString() == "")
- {
- //第一原则送检方案为空
- string qualmethod = "";
- if (Form.Rows[0]["pr_qualmethod"].ToString() == "")
- {
- //判读第二原则送检方案为空
- string pr_qualmethod = dh.getFieldDataByCondition("product left join productkind on pr_kind=pk_name", "pk_qualmethod", "pr_code='" + Form.Rows[0]["ob_prodcode"] + "'").ToString();
- if (pr_qualmethod == "" || pr_qualmethod == null)
- oErrorMessage = "该物料或者物料种类未维护检验方案,物料号:" + Form.Rows[0]["ob_prodcode"] + ",请先维护检验方案";
- //判读第二原则送检方案为空
- else
- qualmethod = pr_qualmethod;
- }
- //第一原则送检方案不为空
- else
- {
- qualmethod = Form.Rows[0]["pr_qualmethod"].ToString();
- }
- Form.Rows[0]["ob_projectcode"] = qualmethod;
- pr_id = dh.getFieldDataByCondition("QUA_Project", "pr_id", "pr_code = '" + qualmethod + "'").ToString();
- sql.Clear();
- sql.Append("select 1 choose,nvl(max(oi_id),0) oi_id,max(ci_kind) ci_kind,max(oi_sampleqty) oi_sampleqty from ");
- sql.Append("QUA_PROJECT left join QUA_ProjectDetail on pd_prid=pr_id left join QUA_CheckItem on ");
- sql.Append("pd_ciid=ci_id left join OQCITEMS on oi_projectcode=pr_code and oi_checkkind=ci_kind ");
- sql.Append("where oi_checkno='" + iCheckNo + "' and oi_projectcode='" + qualmethod + "' group by ci_kind ");
- Grid = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- if (Grid.Rows.Count == 0)
- {
- sql.Clear();
- Grid = (DataTable)dh.ExecuteSql("select distinct 0 choose,ci_kind,0 oi_id,0 oi_sampleqty from QUA_ProjectDetail left join QUA_CheckItem on pd_ciid=ci_id where pd_prid='" + pr_id + "'", "select");
- if (Grid.Rows.Count == 0)
- oErrorMessage = "检验方案:" + qualmethod + "无检验项目";
- }
- }
- else
- {
- pr_id = dh.getFieldDataByCondition("QUA_Project", "pr_id", "pr_code = '" + Form.Rows[0]["pr_qualmethod"] + "'").ToString();
- Grid = (DataTable)dh.ExecuteSql("select distinct ci_kind ,0 oi_id , 0 oi_sampleqty from QUA_ProjectDetail left join QUA_CheckItem on pd_ciid=ci_id where pd_prid='" + pr_id + "'", "select");
- }
- }
- else
- oErrorMessage = "只有待检验的批次才允许维护抽样计划";
- }
- else
- oErrorMessage = "该抽检批次不存在";
- break;
- case "OQCDATACOLLECTION":
- sql.Clear();
- sql.Append("select ob_checkno,ob_makecode,ob_prodcode,ob_batchqty,pr_detail,ob_ngqty,ob_okqty,oi_checkqty,");
- sql.Append("ob_remark,ob_makecode,ob_status,ob_projectcode from OQCBatch left join product on ");
- sql.Append("pr_code=ob_prodcode left join oqcitems on oi_checkno =ob_checkno and oi_projectcode =ob_projectcode where ob_checkno='" + iCheckNo + "'");
- Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- //状态为UNCHECK或者CHECKING并且有抽样计划的才能操作
- if (Form.Rows.Count > 0)
- {
- if (Form.Rows[0]["ob_projectcode"].ToString() == "" || !(Form.Rows[0]["ob_status"].ToString() != "UNCHECK" || Form.Rows[0]["ob_status"].ToString() != "CHECKING"))
- {
- oErrorMessage = "状态为未检验或者送检中并且有抽样计划的才能操作";
- }
- }
- else
- {
- oErrorMessage = "抽检批次不存在";
- }
- break;
- case "OQCRESULTDETERMINE":
- //更新合格数和不合格数
- sql.Clear();
- sql.Append("update OQCBATCH set (ob_ngqty,ob_okqty)=(select nvl(max(oi_ngqty), 0),max(oi_checkqty)-nvl(max(oi_ngqty) ");
- sql.Append(",0) from OQCItems where oi_checkno='" + iCheckNo + "') where ob_checkno='" + iCheckNo + "'");
- dh.ExecuteSql(sql.ToString(), "update");
- //查询Form数据
- sql.Clear();
- sql.Append("select ob_id,ob_makecode,ob_status,ob_prodcode,(select max(oi_checkqty) oi_checkqty from OQCItems where oi_checkno='" + iCheckNo + "'),");
- sql.Append("ob_batchqty,ob_okqty,ob_ngqty,ob_maxngacceptqty,ob_source,ob_checkno,ob_result from OQCBatch where ob_checkno='" + iCheckNo + "'");
- Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- if (Form.Rows.Count == 0)
- {
- oErrorMessage = "该抽检批次不存在";
- }
- break;
- default:
- break;
- }
- return new DataTable[] { Form, Grid };
- }
- /// <summary>
- /// 记录操作日志
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iMaKind"></param>
- /// <param name="result"></param>
- /// <param name="iUserName"></param>
- public static void InsertMakeProcess(string iSnCode, string iMakeCode, string iMaKind, 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,'" + iMaKind + "','" + 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 static 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 static 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);
- DataTable dt = (DataTable)dh.ExecuteSql("select si_sn from SnInfo where si_sn='" + iSN + "' or si_sn in (select sn from makesnrelation where firstsn='" + iSN + "' or sn='" + iSN + "')", "select");
- if (dt.Rows.Count > 0)
- {
- sql = "update SnInfo set si_mac=:iMac,si_bt=:iBT,si_othcode1=:iCode1,si_othcode2=:iCode2,si_othcode3=:iCode3 where si_sn='" + dt.Rows[0]["si_sn"].ToString() + "'";
- 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;
- }
- public static bool SetStepFinish(string iMakeCode, string iSource, string iSN, string iUserCode, out string oErrorMessage)
- {
- oErrorMessage = "";
- string[] param = new string[] { iMakeCode, iSource, iSN, iUserCode, oErrorMessage };
- dh.CallProcedure("CS_SETSTEPFINISH", ref param);
- if (oErrorMessage == "" || oErrorMessage == null)
- 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 static 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 static 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 static bool SetTestNGDetail(string iSnCode, string iMakeCode, string iUserName, string iSourceCode, string iResult, string[] iBadGroupCode, 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_bgcode,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,:bg_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", "bg_code", "bc_remark" }, iBadCode, iBadGroupCode, 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 则为扣料工序
- SetStepFinish(iMakeCode, iSourceCode, iSnCode, iUserName, out oErrorMessage);
- //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 static 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 craftdetail on cd_crid=cr_id ");
- sql.Append("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("select 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 < dt1.Rows.Count; j++)
- {
- //外层循环的值dt
- double baseqty = (double)dt.Rows[i]["baseqty"];
- //内层循环的值dt1
- double dsl_remainqty = (double)dt1.Rows[j]["dsl_remainqty"];
- 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 end),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_INVALIDTIME=(case when");
- sql.Append("dsl_validtime is null then sysdate else dsl_validtime end) where dsl_id=" + dsl_id);
- dh.ExecuteSql(sql.ToString(), "update");
- baseqty = 0;
- }
- }
- else
- dh.ExecuteSql("update devsmtlocation set DSL_INVALIDTIME=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 static 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 static 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 static bool UpdateMakeMessage(string iSnCode, string iMakeCode, string iMaKind, string iSourceCode, string iUserName, string iResult, out string oErrorMessage)
- {
- InsertMakeProcess(iSnCode, iMakeCode, iMaKind, iResult, iUserName);
- return SetStepFinish(iMakeCode, iSourceCode, iSnCode, iUserName, out 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-mss_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_stepcode='" + 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);
- }
- /// <summary>
- /// 获取执行步骤代码,名称和线别
- /// </summary>
- /// <param name="Source"></param>
- /// <param name="StepCode"></param>
- /// <param name="StepName"></param>
- /// <param name="LineCode"></param>
- private static 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 static 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 static string GetStepCodeBySource(string Source)
- {
- return dh.getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
- }
- private static string lpad(int length, string number)
- {
- while (number.Length < length)
- {
- number = "0" + number;
- }
- number = number.Substring(number.Length - length, length);
- return number;
- }
- /// <summary>
- /// 获取箱号
- /// </summary>
- /// <param name="pr_id">物料主表的ID</param>
- /// <param name="kind">管控类型</param>
- /// <returns></returns>
- public static string GetOutBoxCode(string pr_id, string kind)
- {
- StringBuilder code = new StringBuilder();
- object pr_kind = dh.getFieldDataByCondition("product", "pr_tracekind", "pr_id=" + pr_id);
- if (pr_kind.ToString() != "")
- {
- if ((kind.Equals("1") && pr_kind.ToString() == "1") || (kind.Equals("2") && pr_kind.ToString() == "2"))
- {
- // 单间管控或者批管控
- DataTable dt = dh.getFieldsDataByCondition("barcodeSet", new string[] { "bs_id ,bs_lenprid,bs_lennum,bs_maxnum" }, "bs_type='PACK'");
- if (dt.Rows.Count > 0)
- {
- code.Append(lpad(int.Parse(dt.Rows[0]["bs_lenprid"].ToString()), pr_id));// PR_ID物料ID的长度
- code.Append(lpad(int.Parse(dt.Rows[0]["bs_lennum"].ToString()), dt.Rows[0]["bs_maxnum"].ToString()));// 当前流水号
- dh.UpdateByCondition("barcodeSet", "bs_maxnum=bs_maxnum+1", "bs_type='PACK' and bs_id=" + dt.Rows[0]["bs_id"]);// 流水号增加1
- }
- else
- BaseUtil.ShowError("未定义包装箱号产生规则或规则未审核");
- }
- else
- BaseUtil.ShowError("物料管控类型错误!该物料管控类型为不管控");
- }
- return code.ToString();
- }
- }
- }
|