123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicForm;
- namespace UAS_MES_NEW.PublicMethod
- {
- class LogicHandler
- {
- public LogicHandler() { }
- static DataHelper dh = SystemInf.dh;
- //用于拼接SQL
- static StringBuilder sql = new StringBuilder();
- //用于存放批量执行的SQL
- static List<string> sqls = new List<string>();
- /// <summary>
- /// 记录复判记录
- /// </summary>
- /// <param name="iSN"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iSource"></param>
- /// <param name="iFileName"></param>
- /// <param name="iLineCode"></param>
- /// <param name="iCombine"></param>
- public static void AutoPassJudge(string iSN, string iMakeCode, string iSource, string iFileName, string iLineCode, string iCombine, string iStatus)
- {
- //插入不良判断记录
- sql.Clear();
- sql.Append("insert into AUTOSCAN_REJUDGE(asr_id,asr_indate,asr_filename,asr_combinecode,asr_sourcecode,");
- sql.Append("asr_linecode,asr_makecode,asr_rejdate,asr_sncode,asr_rejusername,asr_status) values(AUTOSCAN_REJUDGE_seq.nextval,sysdate,");
- sql.Append("'" + iFileName + "','" + iCombine + "','" + iSource + "','" + iLineCode + "','" + iMakeCode + "',sysdate,'" + iSN + "','" + User.UserName + "','" + iStatus + "')");
- dh.ExecuteSql(sql.ToString(), "insert");
- }
- /// <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", "Lower(ma_code)='" + iMaCode.ToLower() + "' ").ToString();
- ErrorMessage = "";
- if (ma_statuscode == "")
- {
- ErrorMessage = "工单号" + iMaCode + "不存在";
- return false;
- }
- if (ma_statuscode == "STARTED" || ma_statuscode == "FINISH")
- return true;
- else
- {
- ErrorMessage = "工单必须是已下放状态";
- return false;
- }
- }
- public static void GetSerialNumByCaller(string iCaller, out string SerialNum)
- {
- SerialNum = "";
- string[] param = new string[] { iCaller, "2", SerialNum };
- dh.CallProcedure("SP_GETMAXNUMBER", ref param);
- SerialNum = param[2];
- }
- /// <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 (upper(em_code)=:UserName or em_mobile=:UserName) and em_password =:PassWord";
- DataTable dt;
- dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode.ToUpper(), iUserCode.ToUpper(), iPassWord);
- if (dt.Rows.Count > 0)
- return true;
- else
- {
- oErrorMessage = "用户名或者密码不正确!";
- return false;
- }
- }
- /// <summary>
- /// 记录登陆信息
- /// </summary>
- public static void RecordLogInfo(string iUserCode, string iUserName, string iVersion, string iType, string iIP)
- {
- dh.ExecuteSql("insert into LogInfo(id,sip,usname,indate,uscode,versioncode,terminaltype) values (LogInfo_seq.nextval,'" + iIP + "','" + iUserName + "',sysdate,'" + iUserCode + "','" + iVersion + "','" + iType + "')", "insert");
- }
- /// <summary>
- /// 验证用户身份信息和岗位资源
- /// </summary>
- /// <param name="iUserCode"></param>
- /// <param name="iPassWord"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public static bool CheckUserAndResourcePassed(string iUserCode, string iSourceCode, out string oErrorMessage)
- {
- oErrorMessage = "";
- iUserCode = iUserCode.ToUpper();
- iSourceCode = iSourceCode.ToUpper();
- string SQL = "select em_code,em_type from employee where upper(em_code)=:UserName or em_mobile=:UserName";
- DataTable dt;
- dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode, iUserCode);
- if (dt.Rows.Count > 0)
- {
- iUserCode = dt.Rows[0]["em_code"].ToString();
- string em_type = dt.Rows[0]["em_type"].ToString();
- if (iSourceCode == "")
- {
- oErrorMessage = "岗位资源不允许为空";
- return false;
- }
- if (em_type == "admin")
- {
- if (dh.CheckExist("Source", "upper(sc_code)='" + iSourceCode + "' and sc_statuscode='AUDITED'"))
- {
- return true;
- }
- else
- {
- oErrorMessage = "岗位资源编号错误或者未审核!";
- return false;
- }
- }
- else
- {
- dt = dh.getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "upper(ur_resourcecode) ur_resourcecode" }, "upper(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 iSourceCode, out string oErrorMessage)
- {
- oErrorMessage = "";
- string[] param = new string[] { iCaller, iSourceCode, oErrorMessage };
- dh.CallProcedure("CS_CHECKSTEPATTRIBUTE", ref param);
- oErrorMessage = param[2];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
- return true;
- else
- return false;
- }
- public static bool CheckStepSNAndMacode(string iMakeCode, string iSourceCode, string iSN, string iUserCode, out string oMakeCode, out string oMsID, out string oErrorMessage)
- {
- oErrorMessage = "";
- oMakeCode = "";
- oMsID = "";
- string[] param = new string[] { iMakeCode, iSourceCode, 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
- {
- if (User.CurrentStepCode != "B_WEIGH")
- {
- SetCheck set = new SetCheck("NG", Color.Red);
- BaseUtil.SetFormCenter(set);
- set.ShowDialog();
- }
- return false;
- }
- }
- public static void GetQuerySql(string iCondition, out string v_sql, out string v_sql1)
- {
- v_sql = "";
- v_sql1 = "";
- string[] param = new string[] { iCondition, v_sql, v_sql1 };
- dh.CallProcedure("GetQuerySQL", ref param);
- v_sql = param[1];
- v_sql1 = param[2];
- }
- public static void DoCommandLog(string iCaller, string iUserCode, string iMakeCode, string iLineCode, string iSourceCode, string iOperate, string iResult, string iSncode, string iCheckno)
- {
- sql.Clear();
- sql.Append("insert into commandlog(cl_id,cl_caller,cl_man,cl_date,cl_linecode,cl_sourcecode,cl_makecode,cl_operate,");
- sql.Append("cl_result,cl_sncode,cl_code) values( commandlog_seq.nextval,:cl_caller,:iUserCode,sysdate,:iLineCode ,");
- sql.Append(":iSourceCode ,:iMakeCode,:iOperate,:iResult,:iSncode,:iCheckno)");
- dh.ExecuteSql(sql.ToString(), "insert", iCaller, iUserCode, iLineCode, iSourceCode, iMakeCode, iOperate, iResult, iSncode, iCheckno);
- }
- /// <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 oStatus, out string oErrorMessage)
- {
- //取MakeProcess表中的执行记录ID最大的一个工单的号码
- oMakeCode = "";
- oErrorMessage = "";
- oStatus = "";
- DataTable dt = dh.getFieldsDataByCondition("MakeSerial", new string[] { "ms_makecode", "ms_status" }, "ms_id=(select max(ms_id) from makeserial where ms_sncode='" + iSnCode + "')");
- if (dt.Rows.Count > 0)
- {
- oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
- oStatus = dt.Rows[0]["ms_status"].ToString();
- }
- if (oMakeCode != "")
- return true;
- else
- {
- dt = (DataTable)dh.ExecuteSql("select msl_makecode from makesnlist left join make on msl_makecode=ma_code where msl_sncode='" + iSnCode + "' and msl_type='before' and ma_wccode='" + User.WorkCenter + "'", "select");
- if (dt.Rows.Count > 0)
- {
- oMakeCode = dt.Rows[0]["msl_makecode"].ToString();
- return true;
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select msd_makecode from MAKESNRULEDETAIL left join make on msd_makecode=ma_code where msd_sncode='" + iSnCode + "' and msd_type='before' and ma_wccode='" + User.WorkCenter + "'", "select");
- if (dt.Rows.Count > 0)
- {
- oMakeCode = dt.Rows[0]["msd_makecode"].ToString();
- 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 nvl(MS_REWORKCHECKNO,ms_checkno)ms_checkno from makeserial where ms_id=(select max(ms_id) 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>
- /// 第一个是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 obd_outboxcode,obd_id,obd_makecode,obd_sncode from OQCBatchdetail where obd_checkno = '" + iCheckNo + "' order by obd_sncode");
- 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 = "抽检批次" + iCheckNo + "不存在";
- break;
- case "OQCPLANMAINTAIN":
- sql.Clear();
- sql.Append("select ob_reworkcode,ob_prodcode,ob_maxngacceptqty,ob_id,ob_checkno,ob_projectcode,ob_nowcheckqty,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")
- {
- //判断送检方案是否为空
- string qualmethod = "";
- //第一原则送检方案为空
- if (Form.Rows[0]["pr_qualmethod"].ToString() == "")
- {
- //判读第二原则送检方案为空
- qualmethod = dh.getFieldDataByCondition("product left join productkind on pr_kind=pk_name", "pk_qualmethod", "pr_code='" + Form.Rows[0]["ob_prodcode"] + "'").ToString();
- }
- //第一原则送检方案不为空
- 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, ci_kind,nvl(max(oi_sampleqty),0) oi_sampleqty from QUA_PROJECT left join ");
- sql.Append(" QUA_ProjectDetail on pd_prid=pr_id left join QUA_CheckItem on pd_ciid=ci_id ");
- sql.Append("left join OQCITEMS on oi_checkno ='" + iCheckNo + "' and oi_projectcode='" + qualmethod + "' ");
- sql.Append("and oi_projectcode = pr_code and oi_checkkind = ci_kind where pr_code='" + qualmethod + "' group by ci_kind");
- Grid = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- }
- else
- oErrorMessage = "只有待检验的批次才允许维护抽样计划";
- }
- else
- oErrorMessage = "抽检批次" + iCheckNo + "不存在";
- break;
- case "OQCDATACOLLECTION":
- sql.Clear();
- sql.Append("select ob_checkno,ob_makecode,ob_prodcode,ob_nowcheckqty,pr_detail,ob_ngqty,ob_okqty,");
- sql.Append("ob_remark,ob_makecode,ob_status,ob_projectcode,ob_aqlcode,ob_maxngacceptqty 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 = "抽检批次" + iCheckNo + "不存在";
- }
- break;
- case "OQCRESULTDETERMINE":
- sql.Clear();
- sql.Append("select ob_remark Remark,ob_id,ob_aqlcode,ob_makecode,ob_status,ob_prodcode,(select max(oi_checkqty)from OQCItems where oi_checkno='" + iCheckNo + "') oi_checkqty,");
- sql.Append("ob_nowcheckqty,nvl(ob_okqty,0) ob_okqty,nvl(ob_ngqty,0) 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 = "抽检批次" + iCheckNo + "不存在";
- }
- break;
- case "OQCCHECKNOSPLIT":
- sql.Clear();
- sql.Append("select ob_checkno,ob_makecode,ob_prodcode,ob_nowcheckqty,pr_detail,ob_ngqty,ob_okqty,");
- sql.Append("ob_remark,ob_makecode,ob_status,ob_projectcode,ob_aqlcode,ob_maxngacceptqty 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 + "' and ob_status='UNCHECK'");
- Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- //状态为UNCHECK或者CHECKING并且有抽样计划的才能操作
- if (Form.Rows.Count > 0)
- {
- sql.Clear();
- sql.Append("select obd_outboxcode,obd_builddate,obd_makecode,obd_sncode from oqcbatchdetail where obd_checkno='" + Form.Rows[0]["ob_checkno"].ToString() + "'");
- Grid = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- }
- else oErrorMessage = "抽检批次" + iCheckNo + "不存在或者状态不处于待检验";
- break;
- default:
- break;
- }
- return new DataTable[] { Form, Grid };
- }
- public static bool CartonBoxStepPass(string iMakeCode, string iSourceCode, string iCartonBox, string iUserCode, string iResult, out string oErrorMessage)
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select ms_status,V_BARCODE,V_MAKECODE,ms_craftcode,ms_prodcode from mes_package_view left join makeserial on V_MAKECODE=ms_makecode and v_barcode = ms_sncode where V_OUTBOXCODE='" + iCartonBox + "'", "select");
- //获取当前资源的工序
- string stepcode = dh.getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + iSourceCode + "'").ToString();
- string Prcode = dt.Rows[0]["ms_prodcode"].ToString();
- string Craftcode = dt.Rows[0]["ms_craftcode"].ToString();
- string ifoqc = dh.getFieldDataByCondition("craft left join craftdetail on cd_crid=cr_id", "nvl(cd_ifoqc,0) cd_ifoqc", "cr_prodcode='" + Prcode + "' and cr_code='" + Craftcode + "' and cd_stepcode='" + stepcode + "'").ToString();
- oErrorMessage = "";
- if (ifoqc == "0")
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- string ms_status = dt.Rows[i]["ms_status"].ToString();
- string sn = dt.Rows[i]["V_BARCODE"].ToString();
- string makecode = dt.Rows[i]["V_MAKECODE"].ToString();
- if (ms_status != "2")
- {
- CS_SetResult(makecode, iSourceCode, sn, iUserCode, iResult, out oErrorMessage);
- }
- }
- }
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
- return true;
- else
- return false;
- }
- /// <summary>
- /// 箱号过站的公用方法
- /// </summary>
- /// <param name="iOutBoxCode"></param>
- /// <param name="iSourceCode"></param>
- /// <param name="iUserCode"></param>
- /// <param name="iResult"></param>
- /// <param name="iBoxType"></param>
- public static bool OutBoxStepPass(string iOutBoxCode, string iMakeCode, string iSourceCode, string iUserCode, string iResult, string iBoxType, out string oErrorMessage)
- {
- oErrorMessage = "";
- string[] param = new string[] { iOutBoxCode, iMakeCode, iSourceCode, iUserCode, iResult, iBoxType, oErrorMessage };
- dh.CallProcedure("CS_CARTONBOXSTEPRESULT", ref param);
- oErrorMessage = param[6];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
- return true;
- else
- return false;
- }
- /// <summary>
- /// 大箱栈板解除装箱
- /// </summary>
- public static void OutBoxDrawStepPass(string iOutBoxCode, string iMakeCode, string iSourceCode)
- {
- string CurrentStep = "";
- string LineCode = "";
- string CurrentStepName = "";
- List<string> ExeSQL = new List<string>();
- GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
- //判断是否是线外采集
- string unfinpack = dh.getFieldDataByCondition("Line", "nvl(li_allowUnFinPack,0)", "li_code='" + User.UserLineCode + "'").ToString();
- //更新工序会上一执行步骤
- if (unfinpack != "" && unfinpack != "0")
- {
- sql.Clear();
- sql.Append("merge into makeserial using mes_package_view on (v_outboxcode='" + iOutBoxCode + "' and ms_sncode=");
- sql.Append("v_barcode and ms_makecode=v_makecode) when matched then update set ms_nextstepcode=ms_nextstepcode");
- sql.Append(",ms_status=1,ms_sccode='" + iSourceCode + "' ");
- }
- else
- {
- sql.Clear();
- sql.Append("merge into makeserial using mes_package_view on (v_outboxcode='" + iOutBoxCode + "' and ms_sncode=");
- sql.Append("v_barcode and ms_makecode=v_makecode) when matched then update set ms_nextstepcode=ms_stepcode");
- sql.Append(",ms_status=1,ms_sccode='" + iSourceCode + "' ");
- }
- ExeSQL.Add(sql.ToString());
- //更新完工数量
- ExeSQL.Add("update make set ma_madeqty=(select count(1) from makeserial where ms_makecode='" + iMakeCode + "' and ms_status=2) where ma_code='" + iMakeCode + "'");
- //删除StepPassed数据
- sql.Clear();
- sql.Append("delete from steppassed where sp_sncode in (select v_barcode from mes_package_view where v_outboxcode='" + iOutBoxCode + "') ");
- sql.Append("and sp_makecode='" + iMakeCode + "' and sp_stepcode='" + CurrentStep + "'");
- ExeSQL.Add(sql.ToString());
- //更新大箱或栈板的母箱编号为空
- ExeSQL.Add("update package set pa_mothercode='' where pa_outboxcode in(select PD_INNERBOXCODE from package left join packagedetail on pa_id=pd_paid where pa_outboxcode='" + iOutBoxCode + "')");
- //删除从表明细
- ExeSQL.Add("delete from packagedetail where pd_paid=(select pa_id from package where pa_outboxcode='" + iOutBoxCode + "')");
- //设置大箱或栈板的已装数量为0
- ExeSQL.Add("update package set pa_totalqty=0,pa_status=0,pa_currentqty=0,pa_packageqty=0 where pa_outboxcode='" + iOutBoxCode + "'");
- dh.ExecuteSQLTran(ExeSQL.ToArray());
- }
- /// <summary>
- /// 大箱栈板解除装箱
- /// </summary>
- public static void OutBoxDrawStepPass(string iOutBoxCode, string iInnerBoxCode, string iMakeCode, string iSourceCode)
- {
- string CurrentStep = "";
- string LineCode = "";
- string CurrentStepName = "";
- List<string> ExeSQL = new List<string>();
- GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
- //更新工序会上一执行步骤
- sql.Clear();
- sql.Append("update makeserial set ms_nextstepcode=ms_stepcode,MS_STATUS=1,ms_sccode='" + iSourceCode + "' ");
- sql.Append("where ms_sncode in (select v_barcode from mes_package_view where v_outboxcode='" + iOutBoxCode + "')");
- ExeSQL.Add(sql.ToString());
- //更新完工数量
- ExeSQL.Add("update make set ma_madeqty=(select count(1) from makeserial where ms_makecode='" + iMakeCode + "' and ms_status=2) where ma_code='" + iMakeCode + "'");
- //删除StepPassed数据
- sql.Clear();
- sql.Append("delete from steppassed where sp_sncode in (select v_barcode from mes_package_view where v_outboxcode='" + iOutBoxCode + "') ");
- sql.Append("and sp_makecode='" + iMakeCode + "' and sp_stepcode='" + CurrentStep + "'");
- ExeSQL.Add(sql.ToString());
- //更新大箱或栈板的母箱编号为空
- ExeSQL.Add("update package set pa_mothercode='' where pa_outboxcode in(select PD_INNERBOXCODE from package left join packagedetail on pa_id=pd_paid where pa_outboxcode='" + iOutBoxCode + "')");
- //删除从表明细
- ExeSQL.Add("delete from packagedetail where pd_paid=(select pa_id from package where pa_outboxcode='" + iOutBoxCode + "')");
- //设置大箱或栈板的已装数量为0
- ExeSQL.Add("update package set pa_totalqty=0,pa_status=0,pa_currentqty=0,pa_packageqty=0 where pa_outboxcode='" + iOutBoxCode + "'");
- dh.ExecuteSQLTran(ExeSQL.ToArray());
- }
- /// <summary>
- /// 记录操作日志
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iMPKind"></param>
- /// <param name="result"></param>
- /// <param name="iUserCode"></param>
- public static void InsertMakeProcess(string iSnCode, string iMakeCode, string iSourceCode, string iMPKind, string result, string iUserCode)
- {
- string CurrentStep = "";
- string LineCode = "";
- string CurrentStepName = "";
- GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
- 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,mp_snstatus,mp_sncheckno,mp_snoutboxcode)");
- sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,'" + CurrentStep + "','" + CurrentStepName + "',");
- sql.Append("ms_craftcode,cr_name,'" + iMPKind + "','" + result + "',sysdate,'" + iUserCode + "',ma_wccode,'" + LineCode + "','" + iSourceCode + "',");
- sql.Append("ms_status,ms_checkno,ms_outboxcode from make left join makeserial on ms_makecode=ma_code left join step on st_code=ms_stepcode left join craft on ms_craftcode=cr_code and cr_prodcode=ma_prodcode ");
- sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "' and st_code='" + CurrentStep + "'");
- dh.ExecuteSql(sql.ToString(), "insert");
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="iSNMakeCode">序列号的工单号</param>
- /// <param name="iMakeCode">界面上的工单号</param>
- /// <param name="ChangeMakeCodeNote">是否需要切换工单提醒</param>
- /// <returns></returns>
- public static bool CheckDiffMakeCodeBeforeStepCheck(string iSN, string iMakeCode, bool iChangeMakeCodeNote, out string oMakeCode, out string oErrorMessage)
- {
- string oStatus = "";
- GetMakeInfo(iSN, out oMakeCode, out oStatus, out oErrorMessage);
- oErrorMessage = "";
- bool NoteAlready = false;
- if (iChangeMakeCodeNote)
- {
- if (iMakeCode != oMakeCode && oMakeCode != "" && iMakeCode != "" && oStatus != "2")
- {
- string ChangeMakeCode = System.Windows.Forms.MessageBox.Show("序列号" + iSN + "所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- //如果选择不切换赋值当前界面工单
- if (ChangeMakeCode != "Yes")
- {
- oErrorMessage = "请重新采集序列号";
- NoteAlready = true;
- }
- else
- {
- NoteAlready = true;
- }
- }
- else
- {
- oMakeCode = iMakeCode;
- }
- }
- else
- {
- if (oMakeCode == "" || (oMakeCode != "" && oMakeCode == iMakeCode))
- {
- oMakeCode = iMakeCode;
- }
- }
- return (oErrorMessage == "" || oErrorMessage == null);
- }
- /// <summary>
- /// 校验方法之后的检测
- /// </summary>
- /// <param name="iSNMakecode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iChangeMakeCodeNote"></param>
- /// <param name="NoteAlready"></param>
- public static bool CheckDiffMakeCodeAfterStepCheck(string iSN, string iSNMakecode, bool iChangeMakeCodeNote, bool NoteAlready, Control ctl, out string oErrMessage)
- {
- oErrMessage = "";
- if (iChangeMakeCodeNote && !NoteAlready)
- {
- if (iSNMakecode != ctl.Text && ctl.Text != "")
- {
- string ChangeMakeCode = System.Windows.Forms.MessageBox.Show("序列号" + iSN + "所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- //如果选择不切换赋值当前界面工单
- if (ChangeMakeCode == "Yes")
- {
- ctl.Text = iSNMakecode;
- }
- else
- {
- oErrMessage = "请重新采集序列号";
- }
- }
- }
- return (oErrMessage == "" || oErrMessage == null);
- }
- public static bool OQCBatchJudge(string iCheckno, string iSourceCode, string iResult, string iRework, string iUserCode, string iRemark, out string oReworkCode, out string oErrorMessage)
- {
- oReworkCode = "";
- oErrorMessage = "";
- string[] param = new string[] { iCheckno, iSourceCode, iResult, iRework, iUserCode, iRemark, oReworkCode, oErrorMessage };
- dh.CallProcedure("CS_OQCRESULTJUDGE", ref param);
- oReworkCode = param[6];
- oErrorMessage = param[7];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
- return true;
- else
- return false;
- }
- public static String GetNextStep(string iCraftCode, string iStepCode, string iPrCode)
- {
- sql.Clear();
- sql.Append("select cd_nextstepcode from craft left join craftdetail on cr_id =cd_crid where ");
- sql.Append("cr_code='" + iCraftCode + "' and cr_prodcode='" + iPrCode + "' and cd_stepcode='" + iStepCode + "'");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- if (dt.Rows.Count > 0)
- {
- return dt.Rows[0][0].ToString();
- }
- return "";
- }
- public static bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
- {
- oErrorMessage = "";
- string StepCode = dh.getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
- string CurrentStep = GetStepCodeBySource(iSourceCode);
- if (StepCode == CurrentStep)
- {
- InsertMakeProcess(iSN, iMakeCode, iSourceCode, iMPKind, iResult, iUserCode);
- return true;
- }
- else
- {
- return CS_SetResult(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrorMessage);
- }
- }
- public static bool SetStepResult(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
- {
- bool result = CS_SetResult(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrorMessage);
- if (result)
- {
- SetCheck set = new SetCheck("OK", Color.Green);
- BaseUtil.SetFormCenter(set);
- set.ShowDialog();
- }
- else
- {
- SetCheck set = new SetCheck("NG", Color.Red);
- BaseUtil.SetFormCenter(set);
- set.ShowDialog();
- }
- return result;
- }
- public static bool CS_SetResult(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrorMessage)
- {
- oErrorMessage = "";
- string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrorMessage };
- dh.CallProcedure("CS_SETSTEPRESULT", ref param);
- oErrorMessage = param[5];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
- return true;
- else
- return false;
- }
- /// <summary>
- /// 设置测试结果
- /// </summary>
- /// <param name="iMakeCode"></param>
- /// <param name="iSourceCode"></param>
- /// <param name="iSN"></param>
- /// <param name="iMPKind"></param>
- /// <param name="iResult"></param>
- /// <param name="iUserCode"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public static bool SetTestResult(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
- {
- return SetStepFinish(iMakeCode, iSourceCode, iSN, iMPKind, iResult, iUserCode, out oErrorMessage);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public static string GetPiInoutCode(string iCaller, string iType)
- {
- string Code = "";
- string[] param = new string[] { iCaller, iType, Code };
- dh.CallProcedure("SP_GETMAXNUMBER", ref param);
- return param[2];
- }
- /// <summary>
- /// 执行不良信息采集
- /// </summary>
- /// <param name="iSnCode"></param>
- /// <param name="iMakeCode"></param>
- /// <param name="iUserCode"></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 iUserCode, string iSourceCode, string iResult, string[] iBadGroupCode, string[] iBadCode, string[] iBadGroupName, string[] iBadName, string[] iBadRemark, out string oErrorMessage)
- {
- oErrorMessage = "";
- string StepCode = "";
- string StepName = "";
- string ScanType = "";
- string LineCode = "";
- if (iResult == "" || iResult == null)
- iResult = "检查未通过";
- GetStepCodeAndNameAndTypAndLineCodeBySource(iSourceCode, ref StepCode, ref StepName, ref ScanType, ref LineCode);
- if (ScanType == "REJUDGE")
- {
- AutoPassJudge(iSnCode, iMakeCode, iSourceCode, "", LineCode, "", "-1");
- }
- sql.Clear();
- sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
- sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badremark,mb_bgname,mb_badname,mb_type)");
- sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + StepCode + "','" + iSourceCode + "',:bc_code,:bg_code,'',");
- sql.Append("'0',:bc_remark,:bg_name,:bc_name,'Client' from make left join makeSerial on ms_makecode=ma_code ");
- sql.Append(" where ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- if (iBadGroupCode.Length > 0)
- {
- dh.BatchInsert(sql.ToString(), new string[] { "bc_code", "bg_code", "bc_remark", "bg_name", "bc_name" }, iBadCode, iBadGroupCode, iBadRemark, iBadGroupName, iBadName);
- }
- //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
- //如果存在送检批号则进行删除
- if (dh.CheckExist("oqcbatchdetail", "obd_sncode='" + iSnCode + "'"))
- {
- string checkno = dh.getFieldDataByCondition("oqcbatchdetail", "obd_checkno", "obd_sncode='" + iSnCode + "'").ToString();
- string ifng = dh.getFieldDataByCondition("oqcbatchdetail", "obd_ifng", "obd_sncode='" + iSnCode + "'").ToString();
- if (ifng == "-1")
- {
- dh.ExecuteSql("delete OQCITEMSAMPLES where ois_sncode = '" + iSnCode + "'", "select");
- dh.ExecuteSql("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1,ob_ngqty = ob_ngqty -1 where ob_checkno='" + checkno + "'", "update");
- }
- dh.ExecuteSql("delete from oqcbatchdetail where obd_sncode='" + iSnCode + "'", "delete");
- }
- //之前保存的不良就不再调用
- DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_stepcode", "nvl(ms_ifrework,0)ms_ifrework", "ms_status" }, "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- if (dt.Rows.Count > 0)
- {
- string ifrework = dt.Rows[0]["ms_ifrework"].ToString();
- string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
- string ms_status = dt.Rows[0]["ms_status"].ToString();
- if (ms_status == "2")
- {
- dh.ExecuteSql("delete from steppassed where sp_sncode='" + iSnCode + "' and sp_makecode='" + iMakeCode + "' and sp_stepcode='" + StepCode + "'", "delete");
- dh.UpdateByCondition("make", "ma_madeqty=nvl(ma_madeqty,0)-1", "ma_code='" + iMakeCode + "'");
- }
- if (ms_stepcode == StepCode)
- {
- if (ifrework == "0")
- dh.UpdateByCondition("makeserial", "ms_status=3,ms_nextstepcode=''", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- else
- dh.UpdateByCondition("makeserial", "ms_reworkstatus=3,ms_nextstepcode=''", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- }
- else
- {
- if (ifrework == "0")
- dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_status=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "' ");
- else
- dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_paststep = ms_paststep ||'," + StepCode + "',ms_reworkstatus=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
- SetTestResult(iMakeCode, iSourceCode, iSnCode, "不良采集", "NG", iUserCode, 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 ms_makecode='" + iMakeCode + "') 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="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 iSourceCode, 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 + "";
- 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, iSourceCode, "下料操作", "下料成功", 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;
- }
- public static void CollectRemarkInf(string iSN, string iECN, string iSoftVersion, string iMaCode, string iPrCode, string iRemark)
- {
- sql.Clear();
- sql.Append("insert into SNRELATIONINFORECORD(SIR_ID,SIR_SNCODE,SIR_MSCODE,SIR_ECNCODE,SIR_SOFTVER,");
- sql.Append("SIR_LINECODE,SIR_SOURCECODE,SIR_STEPCODE,SIR_MACODE,SIR_PRODCODE,SIR_INMAN,SIR_INDATE,sir_firstsn,sir_remark) select ");
- sql.Append("SNRELATIONINFORECORD_SEQ.nextval,'" + iSN + "',ms_code,'" + iECN + "','" + iSoftVersion + "',");
- sql.Append("'" + User.UserLineCode + "','" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + iMaCode + "','" + iPrCode + "',");
- sql.Append("'" + User.UserCode + "',sysdate,ms_firstsn,'" + iRemark + "' from makeserial where ms_sncode='" + iSN + "' and ms_makecode='" + iMaCode + "'");
- dh.ExecuteSql(sql.ToString(), "insert");
- }
- /// <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 GetStepCodeAndNameAndTypAndLineCodeBySource(string Source, ref string StepCode, ref string StepName, ref string ScanType, ref string LineCode)
- {
- DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_scantype", "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();
- ScanType = dt.Rows[0]["sc_scantype"].ToString();
- LineCode = dt.Rows[0]["sc_linecode"].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();
- }
- /// <summary>
- /// 获取箱号
- /// </summary>
- /// <param name="pr_id">物料主表的ID</param>
- /// <param name="kind">管控类型</param>
- /// <returns></returns>
- public static string GetOutBoxCode(string Caller, string iMakeCode, string iProdCode, string iUserCode)
- {
- string BoxCode = "";
- string[] param = new string[] { Caller, iMakeCode, iProdCode, iUserCode, BoxCode };
- dh.CallProcedure("SP_GETPACKORPALLETCODE", ref param);
- return param[4];
- }
- public static bool CheckSNBeforeLoad(string iMakeCode, string iSN, string iFSonCode, string iSonCode, string iRule, string iPrefix, string iLength, string iIfRepeat, string iChecksalecode, out string ErrMessage)
- {
- DataTable dt;
- ErrMessage = "";
- switch (iRule)
- {
- case "TSN":
- dt = (DataTable)dh.ExecuteSql("select ms_id,ms_prodcode,ms_nextmacode,ms_salecode,ms_downstatus from makeserial where ms_sncode='" + iSN + "' and ms_makecode<>'" + iMakeCode + "' and ms_status=2 order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["ms_downstatus"].ToString() != "0")
- {
- ErrMessage = "序列号:" + iSN + "已下地,请先取消下地";
- return false;
- }
- if (dt.Rows[0]["ms_nextmacode"].ToString() != "")
- {
- ErrMessage = "序列号:" + iSN + "已被工单" + dt.Rows[0]["ms_nextmacode"].ToString() + "使用";
- return false;
- }
- if ((dt.Rows[0]["ms_salecode"].ToString() != dh.getFieldDataByCondition("make", "ma_salecode", "ma_code='" + iMakeCode + "'").ToString()) && iChecksalecode != "0")
- {
- ErrMessage = "序列号对应销售订单与工单不符";
- return false;
- }
- //ms_salecode是否等于工单的SaleCode
- if (iSonCode != dt.Rows[0]["ms_prodcode"].ToString())
- {
- ErrMessage = "序列号对应的物料不是:" + iSonCode;
- return false;
- }
- else
- {
- return true;
- }
- }
- else ErrMessage = "序列号" + iSN + "不存在";
- break;
- case "BARCODE":
- if (iIfRepeat != "-1")
- {
- //判定条码是否已经上料了
- dt = (DataTable)dh.ExecuteSql("select cm_barcode from craftmaterial where cm_barcode='" + iSN + "' and cm_status=0", "select");
- if (dt.Rows.Count > 0)
- {
- ErrMessage = "条码" + iSN + "已经上料";
- return false;
- }
- }
- dt = (DataTable)dh.ExecuteSql("select bar_prodcode,bar_code from barcode where bar_code='" + iSN + "'", "select");
- if (dt.Rows.Count > 0)
- {
- string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
- if (!iFSonCode.Contains(bar_prodcode))
- {
- if (!iSonCode.Contains(bar_prodcode))
- {
- ErrMessage = "用户条码号对应的物料不是:" + iSonCode;
- }
- else
- {
- ErrMessage = bar_prodcode;
- return true;
- }
- }
- else
- {
- ErrMessage = bar_prodcode;
- return true;
- }
- }
- else ErrMessage = "条码" + iSN + "不存在";
- break;
- case "RULE":
- if (iIfRepeat != "-1")
- {
- dt = (DataTable)dh.ExecuteSql("select cm_barcode from craftmaterial where cm_barcode='" + iSN + "' and cm_status=0", "select");
- if (dt.Rows.Count > 0)
- {
- ErrMessage = "条码" + iSN + "已经上料";
- return false;
- }
- }
- int sp_length = int.Parse(iLength != "" ? iLength : "0");
- //若有多个,以|分割
- string[] pres = iPrefix.Split('|');
- bool f = false;
- for (int i = 0; i < pres.Length; i++)
- {
- if (pres[i] == "" ? true : iSN.StartsWith(pres[i]))
- {
- //满足其中一条即可
- f = true;
- break;
- }
- }
- if (f)
- {
- //进行长度匹配
- if (iSN.Length == sp_length || sp_length == 0)
- {
- return true;
- }
- else ErrMessage = iSN + "长度不匹配";
- }
- else ErrMessage = iSN + "前缀不匹配";
- break;
- default:
- break;
- }
- return false;
- }
- public static bool Packing(string iSN, string iOutBoxCode, bool iAutoNew, string iType, string iSource, string iUser, string iStandarqty, bool iInOrOut, out string oOutBoxCode, out string oErrorMessage)
- {
- oErrorMessage = "";
- oOutBoxCode = "";
- string[] param = new string[] { iSN, iOutBoxCode, iAutoNew ? "Y" : "N", iType, iSource, iUser, iStandarqty, iInOrOut ? "OUT" : "IN", oOutBoxCode, oErrorMessage };
- dh.CallProcedure("CS_PACKCARTON", ref param);
- oOutBoxCode = param[8];
- oErrorMessage = param[9];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
- return true;
- else
- return false;
- }
- public static void RecordProdWeight(string iSN, string iType, float iWeight, string iUnit, string iLineCode, string iPrCode, string iSource, string iUser)
- {
- //记录重量
- sql.Clear();
- sql.Append("insert into weightlog(wl_id,wl_type,wl_scancode,wl_weight,wl_unit,wl_linecode,");
- sql.Append("wl_prodcode,wl_sccode,wl_indate,wl_inman) values (weightlog_seq.nextval,:wl_type,:wl_scancode,");
- sql.Append(":wl_weight,:wl_unit,:wl_linecode,:wl_prodcode,:wl_sccode,sysdate,:wl_inman)");
- dh.ExecuteSql(sql.ToString(), "insert", iType, iSN, iWeight, iUnit, iLineCode, iPrCode, iSource, iUser);
- }
- public static bool CheckUpdate()
- {
- string version = BaseUtil.GetCacheData("Version").ToString();
- DataHelper dh = new DataHelper();
- string LastVersion = dh.getFieldDataByCondition("configs", "code", "caller='CSUPDATE'").ToString();
- if (version == LastVersion || version == "" || LastVersion == "")
- {
- return false;
- }
- else
- {
- BaseUtil.SetCacheData("Version", LastVersion);
- return true;
- }
- }
- /// <summary>
- /// 小箱装大箱的包装规则判断
- /// </summary>
- /// <param name="packrule"></param>
- /// <param name="pa_outboxcode"></param>
- /// <param name="outboxcode"></param>
- /// <param name="pa_makecode"></param>
- /// <param name="pa_salecode"></param>
- /// <param name="pa_prodcode"></param>
- /// <param name="error"></param>
- /// <returns></returns>
- public static Boolean CheckPackRule(string packrule, string pa_outboxcode, string outboxcode, string pa_makecode, string pa_salecode, string pa_prodcode, string type, out string error)
- {
- //按工单核对装箱
- switch (packrule.ToUpper())
- {
- case "MAKE":
- string makecode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode + "'").ToString();
- if (makecode != pa_makecode && pa_makecode != "")
- {
- error = ">>当前箱" + outboxcode + "对应工单号" + makecode + "和所装" + type + "号" + pa_outboxcode + "对应工单" + pa_makecode + "不相等";
- return false;
- }
- break;
- case "SALE":
- if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode + "'"))
- {
- string salecode = dh.getFieldDataByCondition("package", "pa_salecode", "pa_outboxcode = '" + outboxcode + "'").ToString();
- if (salecode != pa_salecode)
- {
- error = ">>当前箱" + outboxcode + "对应订单号" + salecode + "和所装" + type + "号" + pa_outboxcode + "对应订单" + pa_salecode + "不相等";
- return false;
- }
- }
- break;
- case "PROD":
- string prodcode = dh.getFieldDataByCondition("package", "pa_prodcode", "pa_outboxcode='" + outboxcode + "'").ToString();
- if (prodcode != pa_prodcode)
- {
- error = ">>当前箱" + outboxcode + "对应物料" + prodcode + "和所装" + type + "号" + pa_outboxcode + "对应物料" + pa_prodcode + "不相等";
- return false;
- }
- break;
- case "MIX":
- break;
- default:
- prodcode = dh.getFieldDataByCondition("package", "pa_prodcode", "pa_outboxcode='" + outboxcode + "'").ToString();
- error = ">>当前箱" + outboxcode + "对应物料" + prodcode + "没有维护装箱规则";
- return false;
- break;
- }
- error = "";
- return true;
- }
- /// <summary>
- /// 验证是否符合合同防呆
- /// </summary>
- /// <param name="msid"></param>
- /// <param name="macOrBt"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- public static Boolean checkMacOrBtRange(string msid, string macOrBt, string type)
- {
- //--判断是否有合同,是否在合同定义的范围内
- string saleCode = dh.getFieldDataByCondition("makeserial", "ms_salecode", "ms_id='" + msid + "'").ToString();
- if (saleCode == "")
- {
- return true;
- }
- //判断是否有合同范围
- if (dh.CheckExist("SaleMacBTRange", "Sr_Sacode = '" + saleCode + "' and sr_type = '" + type + "'"))
- {
- //有合同范围再判断是否在范围内
- if (!dh.CheckExist("SaleMacBTRange", "Sr_Sacode = '" + saleCode + "' and sr_type = '" + type + "' and '" + macOrBt + "' between SR_STARTCODE and SR_ENDCODE"))
- {
- return false;
- }
- }
- return true;
- }
- /// <summary>
- /// 序列烧录转换
- /// </summary>
- /// <param name="iTSN"></param>
- /// <param name="iSN"></param>
- /// <param name="iSourcecode"></param>
- /// <param name="iUsercode"></param>
- /// <param name="iMacode"></param>
- /// <param name="iifrechange"></param>
- /// <param name="iMEI1"></param>
- /// <param name="iMEI2"></param>
- /// <param name="iMEI3"></param>
- /// <param name="iMEID"></param>
- /// <param name="iNETCODE"></param>
- /// <param name="iPSN"></param>
- /// <param name="iID1"></param>
- /// <param name="iID2"></param>
- /// <param name="iID3"></param>
- /// <param name="iMAC"></param>
- /// <param name="iBT"></param>
- /// <param name="iCODE1"></param>
- /// <param name="iCODE2"></param>
- /// <param name="iCODE3"></param>
- /// <param name="oErrorMessage"></param>
- /// <returns></returns>
- public static bool snChangeAndBurn(string iTSN, string iSN, string iSourcecode, string iUsercode, string iMacode, int iifrechange, string iMEI1, string iMEI2, string iMEI3, string iMEID, string iNETCODE, string iPSN, string iID1, string iID2, string iID3, string iMAC, string iBT, string iCODE1, string iCODE2, string iCODE3, out string oErrorMessage)
- {
- oErrorMessage = "";
- string[] param = new string[] { iTSN, iSN, iSourcecode, iUsercode, iMacode, iifrechange + "", iMEI1, iMEI2, iMEI3, iMEID, iNETCODE, iPSN, iID1, iID2, iID3, iMAC, iBT, iCODE1, iCODE2, iCODE3, oErrorMessage };
- dh.CallProcedure("CS_SNCHANGEANDBURN", ref param);
- oErrorMessage = param[20];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
- return true;
- else
- return false;
- }
- public static bool snBurn(string iTSN, string iSN, string iSourcecode, string iUsercode, string iMacode, int iifrechange, string iMEI1, string iMEI2, string iMEI3, string iMEID, string iNETCODE, string iPSN, string iID1, string iID2, string iID3, string iMAC, string iBT, string iCODE1, string iCODE2, string iCODE3, out string oErrorMessage)
- {
- oErrorMessage = "";
- string[] param = new string[] { iTSN, iSN, iSourcecode, iUsercode, iMacode, iifrechange + "", iMEI1, iMEI2, iMEI3, iMEID, iNETCODE, iPSN, iID1, iID2, iID3, iMAC, iBT, iCODE1, iCODE2, iCODE3, oErrorMessage };
- dh.CallProcedure("CS_SNBURN", ref param);
- oErrorMessage = param[20];
- if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
- return true;
- else
- return false;
- }
- /// <summary>
- /// 记录打印
- /// </summary>
- /// <param name="printValue"></param>
- /// <param name="printType"></param>
- /// <param name="MakeCode"></param>
- /// <param name="prodCode"></param>
- /// <param name="sourceCode"></param>
- /// <param name="stepcode"></param>
- /// <param name="ifRePrint"></param>
- /// <param name="userCode"></param>
- public static void doLabelPrintLog(string printValue, string printType, string MakeCode, string prodCode, string sourceCode, string stepcode, string ifRePrint, string userCode)
- {
- sql.Clear();
- sql.Append("insert into labelprintlog(LPL_ID,LPL_VALUE,LPL_TYPE,LPL_MAKECODE,LPL_PRODCODE,LPL_SOURCECODE,LPL_STEPCODE,LPL_IFREPRINT,LPL_INDATE,LPL_INMAN) ");
- sql.Append("values( labelprintlog_seq.nextval,:lpl_value,:lpl_type,:makecode,:prodcode,");
- sql.Append(":SourceCode,:stepcode,:ifreprint,sysdate,:inman)");
- dh.ExecuteSql(sql.ToString(), "insert", printValue, printType, MakeCode, prodCode, sourceCode, stepcode, ifRePrint, userCode);
- }
- public static bool GetMobileAllInfo(string iSN, out Dictionary<string, string> oInfo, out string oErrMessage)
- {
- oInfo = new Dictionary<string, string>();
- oErrMessage = "";
- if (iSN == "")
- {
- oErrMessage = "SN不能为空";
- return false;
- }
- //通过序列号获取最近操作的工单号
- string ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "'").ToString();
- if (ms_id != "")
- {
- 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_id='" + ms_id + "'");
- if (dt.Rows.Count > 0)
- {
- string Code1 = "";
- string Code2 = "";
- string Code3 = "";
- string Code4 = "";
- string Code5 = "";
- string Code6 = "";
- string Code7 = "";
- string Code8 = "";
- string Code9 = "";
- string Code10 = "";
- string Code11 = "";
- string Code12 = "";
- string Code13 = "";
- string Code14 = "";
- string Code15 = "";
- string[] param = new string[] { ms_id, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15 };
- string[] ParamName = new string[] { "v_ms_id", "v_i_code1", "v_i_code2", "v_i_code3", "v_i_code4", "v_i_code5", "v_i_code6", "v_i_code7", "v_i_code8", "v_i_code9", "v_i_code10", "v_i_code11", "v_i_code12", "v_i_code13", "v_i_code14", "v_i_code15" };
- dh.CallProcedure("GetMobileAllInfo", ParamName, ref param);
- for (int i = 1; i < param.Length; i++)
- {
- //获取出来的参数使用^分割
- if (param[i] != "" && param[i] != "null" && param[i] != null)
- {
- oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
- }
- }
- oErrMessage = "";
- return true;
- }
- else
- {
- oErrMessage = "序列号" + iSN + "不存在";
- return false;
- }
- }
- else
- {
- oErrMessage = "序列号" + iSN + "不存在";
- return false;
- }
- }
- }
- }
|