PCModuleLogicDAL.cs 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:PCModuleLogicDAL.cs
  5. * 2.功能描述:生产配置数据库访问类(插入、修改、删除)
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/09/3 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Linq;
  13. using Dongke.IBOSS.PRD.Basics.BaseResources;
  14. using Dongke.IBOSS.PRD.Basics.DataAccess;
  15. using Dongke.IBOSS.PRD.Service.DataModels;
  16. using Dongke.IBOSS.PRD.WCF.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.DataModels.PCModule;
  18. using Oracle.ManagedDataAccess.Client;
  19. namespace Dongke.IBOSS.PRD.Service.PCModuleLogic
  20. {
  21. /// <summary>
  22. /// 生产配置数据库访问类(插入、修改、删除)
  23. /// </summary>
  24. public partial class PCModuleLogicDAL
  25. {
  26. #region 生产线管理
  27. /// <summary>
  28. /// 保存生产线
  29. /// </summary>
  30. /// <param name="productionLine">生产线实体</param>
  31. /// <param name="sUserInfo">用户基本信息</param>
  32. /// <returns></returns>
  33. public static int SaveProductionLine(ProductionLineEntity productionLine, SUserInfo sUserInfo)
  34. {
  35. int returnRows = 0;
  36. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  37. try
  38. {
  39. #region 新建生产线
  40. if (productionLine.ProductionLineID == 0)
  41. {
  42. #region 判断编码是否重复
  43. string sqlText = " SELECT ProductionLineID "
  44. + " FROM TP_PC_ProductionLine "
  45. + " WHERE "
  46. + " AccountID=:accountID "
  47. + " AND ProductionLineCode=:productionLineCode";
  48. OracleParameter[] paras = new OracleParameter[]
  49. {
  50. new OracleParameter(":accountID",sUserInfo.AccountID),
  51. new OracleParameter(":productionLineCode",productionLine.ProductionLineCode),
  52. };
  53. string returnCode = oracleTrConn.GetSqlResultToStr(sqlText, paras);
  54. if (!string.IsNullOrEmpty(returnCode))
  55. {
  56. return Constant.RETURN_IS_EXIST;
  57. }
  58. #endregion
  59. #region 查询新ID
  60. sqlText = "SELECT SEQ_PC_PRODUCTIONLINE_ID.nextval FROM dual";
  61. productionLine.ProductionLineID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  62. #endregion
  63. #region 插入生产线
  64. sqlText = "INSERT INTO TP_PC_ProductionLine (ProductionLineID,"
  65. + "ProductionLineCode,"
  66. + "ProductionLineName,"
  67. + "FlowXML,"
  68. + "Remarks,"
  69. + "AccountID,"
  70. + "CreateUserID,"
  71. + "UpdateUserID)"
  72. + " VALUES(:ProductionLineID,"
  73. + ":productionLineCode,"
  74. + ":productionLineName,"
  75. + ":flowXML,"
  76. + ":remarks,"
  77. + ":accountID,"
  78. + ":createUserID,"
  79. + ":updateUserID"
  80. + ")";
  81. paras = new OracleParameter[]
  82. {
  83. new OracleParameter(":ProductionLineID",productionLine.ProductionLineID),
  84. new OracleParameter(":productionLineCode",productionLine.ProductionLineCode),
  85. new OracleParameter(":productionLineName",productionLine.ProductionLineName),
  86. new OracleParameter(":flowXML", System.Text.Encoding.UTF8.GetBytes(productionLine.FlowXML)),
  87. new OracleParameter(":remarks",productionLine.Remarks),
  88. new OracleParameter(":accountID",sUserInfo.AccountID),
  89. new OracleParameter(":createUserID",sUserInfo.UserID),
  90. new OracleParameter(":updateUserID",sUserInfo.UserID),
  91. };
  92. foreach (OracleParameter item in paras)
  93. {
  94. if (item.Value + "" == "")
  95. {
  96. item.Value = System.DBNull.Value;
  97. }
  98. }
  99. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  100. #endregion
  101. //#region 查询新ID
  102. //sqlText = "SELECT SEQ_PC_PRODUCTIONLINE_ID.currval FROM dual";
  103. //productionLine.ProductionLineID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  104. //#endregion
  105. #region 插入工序
  106. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  107. {
  108. sqlText = "SELECT SEQ_PC_PROCEDURE_PROCEDUREID.Nextval FROM dual";
  109. procedure.ProcedureID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  110. sqlText = "INSERT INTO TP_PC_Procedure ("
  111. + "ProcedureID,"
  112. + "NodeNo,"
  113. + "ProductionLineID,"
  114. + "ProcedureCode,"
  115. + "ProcedureName,"
  116. + "ProcedureModel,"
  117. + "ModelType,"
  118. + "NodeType,"
  119. + "MustFlag,"
  120. + "CollectType,"
  121. + "PieceType,"
  122. + "IsSpecialRework,"
  123. + "IsSemireWork,"
  124. + "OrganizationID,"
  125. + "Remarks,"
  126. + "AccountID,"
  127. + "CreateUserID,"
  128. + "UpdateUserID)"
  129. + " VALUES("
  130. + ":procedureID,"
  131. + ":nodeNo,"
  132. + ":productionLineID,"
  133. + ":procedureCode,"
  134. + ":procedureName,"
  135. + ":procedureModel,"
  136. + ":ModelType,"
  137. + ":NodeType,"
  138. + ":mustFlag,"
  139. + ":collectType,"
  140. + ":pieceType,"
  141. + ":isSpecialRework,"
  142. + ":IsSemireWork,"
  143. + ":organizationID,"
  144. + ":remarks,"
  145. + ":accountID,"
  146. + ":createUserID,"
  147. + ":updateUserID"
  148. + ")";
  149. paras = new OracleParameter[]
  150. {
  151. new OracleParameter(":procedureID",procedure.ProcedureID),
  152. new OracleParameter(":nodeNo",procedure.NodeNo),
  153. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  154. new OracleParameter(":procedureCode",procedure.ProcedureCode),
  155. new OracleParameter(":procedureName",procedure.ProcedureName),
  156. new OracleParameter(":procedureModel",procedure.ProcedureModel),
  157. new OracleParameter(":ModelType",procedure.ModelType),
  158. new OracleParameter(":NodeType",procedure.NodeType),
  159. new OracleParameter(":mustFlag",procedure.MustFlag),
  160. new OracleParameter(":collectType",procedure.CollectType),
  161. new OracleParameter(":pieceType",procedure.PieceType),
  162. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  163. new OracleParameter(":IsSemireWork",procedure.IsSemireWork),
  164. new OracleParameter(":organizationID",procedure.OrganizationID),
  165. new OracleParameter(":remarks",procedure.Remarks),
  166. new OracleParameter(":accountID",sUserInfo.AccountID),
  167. new OracleParameter(":createUserID",sUserInfo.UserID),
  168. new OracleParameter(":updateUserID",sUserInfo.UserID),
  169. };
  170. foreach (OracleParameter item in paras)
  171. {
  172. if (item.Value + "" == "")
  173. {
  174. item.Value = System.DBNull.Value;
  175. }
  176. }
  177. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  178. }
  179. #endregion
  180. }
  181. #endregion
  182. #region 编辑生产线
  183. else
  184. {
  185. #region 校验时间戳
  186. // todo
  187. string sql = "SELECT OPTimeStamp FROM TP_PC_ProductionLine"
  188. + " WHERE ProductionLineID = " + productionLine.ProductionLineID + " and OPTimeStamp = :OPTimeStamp";
  189. OracleParameter[] parmetersSql = new OracleParameter[]
  190. {
  191. new OracleParameter(":OPTimeStamp", OracleDbType.TimeStamp, productionLine.OPTimeStamp, ParameterDirection.Input),
  192. };
  193. DataSet returnDataset = oracleTrConn.GetSqlResultToDs(sql, parmetersSql);
  194. if (returnDataset != null && returnDataset.Tables[0].Rows.Count == 0)
  195. {
  196. oracleTrConn.Commit();
  197. oracleTrConn.Disconnect();
  198. return Constant.RETURN_IS_DATACHANGED;
  199. }
  200. #endregion
  201. #region 判断编码是否重复
  202. string sqlText = " SELECT ProductionLineID "
  203. + " FROM TP_PC_ProductionLine "
  204. + " WHERE "
  205. + " AccountID=:accountID "
  206. + " AND ProductionLineCode=:productionLineCode"
  207. + " AND ProductionLineID <> :productionLineID";
  208. OracleParameter[] paras = new OracleParameter[]
  209. {
  210. new OracleParameter(":accountID",sUserInfo.AccountID),
  211. new OracleParameter(":productionLineCode",productionLine.ProductionLineCode),
  212. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  213. };
  214. string returnCode = oracleTrConn.GetSqlResultToStr(sqlText, paras);
  215. if (!string.IsNullOrEmpty(returnCode))
  216. {
  217. return Constant.RETURN_IS_EXIST;
  218. }
  219. #endregion
  220. #region 编辑生产线
  221. sqlText = "UPDATE TP_PC_ProductionLine SET "
  222. + "ProductionLineName=:productionLineName,"
  223. + "FlowXML=:flowXML,"
  224. + "Remarks=:remarks,"
  225. + "UpdateTime=sysdate, "
  226. + "UpdateUserID=:updateUserID "
  227. + " WHERE ProductionLineID=:productionLineID";
  228. paras = new OracleParameter[]
  229. {
  230. new OracleParameter(":productionLineName",productionLine.ProductionLineName),
  231. new OracleParameter(":flowXML", OracleDbType.Blob,System.Text.Encoding.UTF8.GetBytes(productionLine.FlowXML),ParameterDirection.Input),
  232. new OracleParameter(":remarks",productionLine.Remarks),
  233. new OracleParameter(":updateUserID",OracleDbType.Int32, sUserInfo.UserID,ParameterDirection.Input),
  234. new OracleParameter(":productionLineID", OracleDbType.Int32, productionLine.ProductionLineID,ParameterDirection.Input)
  235. };
  236. //foreach (OracleParameter item in paras)
  237. //{
  238. // if (item.Value + "" == "")
  239. // {
  240. // item.Value = System.DBNull.Value;
  241. // }
  242. //}
  243. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  244. #endregion
  245. #region 编辑工序
  246. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  247. {
  248. if (procedure.EditingAddFlag)
  249. {
  250. #region 编辑时新添加的节点
  251. sqlText = "SELECT SEQ_PC_PROCEDURE_PROCEDUREID.Nextval FROM dual";
  252. procedure.ProcedureID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  253. sqlText = "INSERT INTO TP_PC_Procedure ("
  254. + "ProcedureID,"
  255. + "NodeNo,"
  256. + "ProductionLineID,"
  257. + "ProcedureCode,"
  258. + "ProcedureName,"
  259. + "ProcedureModel,"
  260. + "ModelType,"
  261. + "NodeType,"
  262. + "MustFlag,"
  263. + "CollectType,"
  264. + "PieceType,"
  265. + "IsSpecialRework,"
  266. + "IsSemireWork,"
  267. + "OrganizationID,"
  268. + "Remarks,"
  269. + "AccountID,"
  270. + "CreateUserID,"
  271. + "UpdateUserID)"
  272. + " VALUES("
  273. + ":procedureID,"
  274. + ":nodeNo,"
  275. + ":productionLineID,"
  276. + ":procedureCode,"
  277. + ":procedureName,"
  278. + ":procedureModel,"
  279. + ":ModelType,"
  280. + ":NodeType,"
  281. + ":mustFlag,"
  282. + ":collectType,"
  283. + ":pieceType,"
  284. + ":isSpecialRework,"
  285. + ":isSemireWork,"
  286. + ":organizationID,"
  287. + ":remarks,"
  288. + ":accountID,"
  289. + ":createUserID,"
  290. + ":updateUserID"
  291. + ")";
  292. paras = new OracleParameter[]
  293. {
  294. new OracleParameter(":procedureID",procedure.ProcedureID),
  295. new OracleParameter(":nodeNo",procedure.NodeNo),
  296. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  297. new OracleParameter(":procedureCode",procedure.ProcedureCode),
  298. new OracleParameter(":procedureName",procedure.ProcedureName),
  299. new OracleParameter(":procedureModel",procedure.ProcedureModel),
  300. new OracleParameter(":ModelType",procedure.ModelType),
  301. new OracleParameter(":NodeType",procedure.NodeType),
  302. new OracleParameter(":mustFlag",procedure.MustFlag),
  303. new OracleParameter(":collectType",procedure.CollectType),
  304. new OracleParameter(":pieceType",procedure.PieceType),
  305. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  306. new OracleParameter(":isSemireWork",procedure.IsSemireWork),
  307. new OracleParameter(":organizationID",procedure.OrganizationID),
  308. new OracleParameter(":remarks",procedure.Remarks),
  309. new OracleParameter(":accountID",sUserInfo.AccountID),
  310. new OracleParameter(":createUserID",sUserInfo.UserID),
  311. new OracleParameter(":updateUserID",sUserInfo.UserID),
  312. };
  313. #endregion
  314. }
  315. else
  316. {
  317. #region 编辑
  318. sqlText = "UPDATE TP_PC_Procedure SET "
  319. + " ProcedureName=:procedureName,"
  320. + " ProcedureCode=:ProcedureCode,"
  321. + " ModelType=:modelType,"
  322. + " MustFlag=:mustFlag,"
  323. + " CollectType=:collectType,"
  324. + " OrganizationID=:organizationID,"
  325. + " NodeType=:nodeType,"
  326. + " PieceType=:pieceType,"
  327. + " IsSpecialRework=:isSpecialRework,"
  328. + " IsSemireWork=:isSemireWork,"
  329. + " NodeNo=:nodeNo,"
  330. + " Remarks=:remarks,"
  331. + " updateUserID=:updateUserID,"
  332. + " UpdateTime=sysdate"
  333. + " WHERE NodeNo=:nodeNo "
  334. + " AND ProductionLineID=:productionLineID";
  335. paras = new OracleParameter[]
  336. {
  337. new OracleParameter(":nodeNo",procedure.NodeNo),
  338. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  339. new OracleParameter(":procedureName",procedure.ProcedureName),
  340. new OracleParameter(":ProcedureCode",procedure.ProcedureCode),
  341. new OracleParameter(":modelType",procedure.ModelType),
  342. new OracleParameter(":mustFlag",procedure.MustFlag),
  343. new OracleParameter(":collectType",procedure.CollectType),
  344. new OracleParameter(":organizationID",procedure.OrganizationID),
  345. new OracleParameter(":nodeType",procedure.NodeType),
  346. new OracleParameter(":pieceType",procedure.PieceType),
  347. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  348. new OracleParameter(":isSemireWork",procedure.IsSemireWork),
  349. new OracleParameter(":nodeNo",procedure.NodeNo),
  350. new OracleParameter(":remarks",procedure.Remarks),
  351. new OracleParameter(":updateUserID",sUserInfo.UserID),
  352. };
  353. #endregion
  354. }
  355. foreach (OracleParameter item in paras)
  356. {
  357. if (item.Value + "" == "")
  358. {
  359. item.Value = System.DBNull.Value;
  360. }
  361. }
  362. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  363. }
  364. #endregion
  365. #region 先删除生产工序流程明细 然后再插入
  366. sqlText = "DELETE TP_PC_ProcedureFlow WHERE ProductionLineID=:productionLineID";
  367. paras = new OracleParameter[]
  368. {
  369. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  370. };
  371. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  372. #endregion
  373. #region 删除对应产品 然后再插入
  374. sqlText = "DELETE TP_PC_ProcedureGoods WHERE ProductionLineID=:productionLineID";
  375. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  376. #endregion
  377. #region 删除对应工号 然后再插入
  378. sqlText = "DELETE TP_PC_ProcedureUser WHERE ProductionLineID=:productionLineID";
  379. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  380. #endregion
  381. #region 删除对应缺陷 然后再插入
  382. sqlText = "DELETE TP_PC_ProcedureDefect WHERE ProductionLineID=:productionLineID";
  383. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  384. #endregion
  385. #region 删除缺陷对应工序工种表 然后再插入
  386. sqlText = "DELETE TP_PC_DefectProcedureJobs WHERE ProductionLineID=:productionLineID";
  387. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  388. #endregion
  389. }
  390. #endregion
  391. #region 插入生产工序属性等信息
  392. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  393. {
  394. string sqlText;
  395. OracleParameter[] paras;
  396. #region 插入生产工序流程明细
  397. if (procedure.ProcedureFlowDetailList != null)
  398. {
  399. foreach (ProcedureFlowEntity flowDetail in procedure.ProcedureFlowDetailList)
  400. {
  401. ProcedureEntity procedureWhere = productionLine.ProcedureList.Where(p => p.NodeNo == flowDetail.ArriveNodeNo).SingleOrDefault();
  402. // 没有找到对应节点的ID
  403. if (procedureWhere == null)
  404. {
  405. return Constant.INT_IS_ZERO;
  406. }
  407. else
  408. {
  409. flowDetail.ArriveProcedureID = procedureWhere.ProcedureID;
  410. }
  411. sqlText = "INSERT INTO TP_PC_ProcedureFlow ("
  412. + "ProductionLineID,"
  413. + "ProcedureID,"
  414. + "NodeNo,"
  415. + "FlowFlag,"
  416. + "ArriveProcedureID,"
  417. + "ArriveNodeNo"
  418. + ")"
  419. + " VALUES("
  420. + ":productionLineID,"
  421. + ":procedureID,"
  422. + ":nodeNo,"
  423. + ":flowFlag,"
  424. + ":arriveProcedureID,"
  425. + ":arriveNodeNo"
  426. + ")";
  427. paras = new OracleParameter[]
  428. {
  429. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  430. new OracleParameter(":procedureID",procedure.ProcedureID),
  431. new OracleParameter(":nodeNo",procedure.NodeNo),
  432. new OracleParameter(":flowFlag",flowDetail.FlowFlag),
  433. new OracleParameter(":arriveProcedureID",flowDetail.ArriveProcedureID),
  434. new OracleParameter(":arriveNodeNo",flowDetail.ArriveNodeNo),
  435. };
  436. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  437. }
  438. }
  439. #endregion
  440. #region 插入生产工序对应产品表
  441. foreach (DataRow row in procedure.ProcedureGoodsTable.Rows)
  442. {
  443. sqlText = "INSERT INTO TP_PC_ProcedureGoods ("
  444. + "ProductionLineID,"
  445. + "ProcedureID,"
  446. + "NodeNo,"
  447. + "GOODSID,"
  448. + "CreateUserID"
  449. + ")"
  450. + " VALUES("
  451. + ":productionLineID,"
  452. + ":procedureID,"
  453. + ":nodeNo,"
  454. + ":goodsID,"
  455. + ":createUserID"
  456. + ")";
  457. paras = new OracleParameter[]
  458. {
  459. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  460. new OracleParameter(":procedureID",procedure.ProcedureID),
  461. new OracleParameter(":nodeNo",procedure.NodeNo),
  462. new OracleParameter(":goodsID",OracleDbType.Int32,row["goodsID"],ParameterDirection.Input),
  463. new OracleParameter(":createUserID",sUserInfo.UserID),
  464. };
  465. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  466. }
  467. #endregion
  468. #region 插入生产工序对应工号表
  469. foreach (DataRow row in procedure.ProcedureUserTable.Rows)
  470. {
  471. sqlText = "INSERT INTO TP_PC_ProcedureUser ("
  472. + "ProductionLineID,"
  473. + "ProcedureID,"
  474. + "NodeNo,"
  475. + "UserID,"
  476. + "CreateUserID"
  477. + ")"
  478. + " VALUES("
  479. + ":productionLineID,"
  480. + ":procedureID,"
  481. + ":nodeNo,"
  482. + ":userID,"
  483. + ":createUserID"
  484. + ")";
  485. paras = new OracleParameter[]
  486. {
  487. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  488. new OracleParameter(":procedureID",procedure.ProcedureID),
  489. new OracleParameter(":nodeNo",procedure.NodeNo),
  490. new OracleParameter(":userID",OracleDbType.Int32,row["userID"],ParameterDirection.Input),
  491. new OracleParameter(":createUserID",sUserInfo.UserID),
  492. };
  493. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  494. }
  495. #endregion
  496. #region 插入生产工序对应缺陷表
  497. foreach (DataRow row in procedure.ProcedureDefectTable.Rows)
  498. {
  499. if (row["DefectID"] == DBNull.Value)
  500. {
  501. continue;
  502. }
  503. sqlText = "INSERT INTO TP_PC_ProcedureDefect ("
  504. + "ProductionLineID,"
  505. + "ProcedureID,"
  506. + "NodeNo,"
  507. + "DefectID,"
  508. + "CreateUserID"
  509. + ")"
  510. + " VALUES("
  511. + ":productionLineID,"
  512. + ":procedureID,"
  513. + ":nodeNo,"
  514. + ":defectID,"
  515. + ":createUserID"
  516. + ")";
  517. paras = new OracleParameter[]
  518. {
  519. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  520. new OracleParameter(":procedureID",procedure.ProcedureID),
  521. new OracleParameter(":nodeNo",procedure.NodeNo),
  522. new OracleParameter(":defectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  523. new OracleParameter(":createUserID",sUserInfo.UserID),
  524. };
  525. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  526. }
  527. #endregion
  528. #region 插入缺陷对应工序工种表
  529. foreach (DataRow row in procedure.DefectProcedureJobsTable.Rows)
  530. {
  531. if (row["DefectID"] == DBNull.Value || row["jobsID"] == DBNull.Value)
  532. {
  533. continue;
  534. }
  535. sqlText = "INSERT INTO TP_PC_DefectProcedureJobs ("
  536. + "ProductionLineID,"
  537. + "ProcedureID,"
  538. + "NodeNo,"
  539. + "DefectID,"
  540. + "JobsID,"
  541. + "CreateUserID"
  542. + ")"
  543. + " VALUES("
  544. + ":productionLineID,"
  545. + ":procedureID,"
  546. + ":nodeNo,"
  547. + ":DefectID,"
  548. + ":jobsID,"
  549. + ":createUserID"
  550. + ")";
  551. paras = new OracleParameter[]
  552. {
  553. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  554. new OracleParameter(":procedureID",procedure.ProcedureID),
  555. new OracleParameter(":nodeNo",procedure.NodeNo),
  556. new OracleParameter(":DefectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  557. new OracleParameter(":jobsID",OracleDbType.Int32,row["jobsID"],ParameterDirection.Input),
  558. new OracleParameter(":createUserID",sUserInfo.UserID),
  559. };
  560. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  561. }
  562. #endregion
  563. }
  564. #endregion
  565. oracleTrConn.Commit();
  566. }
  567. catch (Exception ex)
  568. {
  569. oracleTrConn.Rollback();
  570. throw ex;
  571. }
  572. finally
  573. {
  574. // 释放资源
  575. if (oracleTrConn.ConnState == System.Data.ConnectionState.Open)
  576. {
  577. oracleTrConn.Disconnect();
  578. }
  579. }
  580. return returnRows;
  581. }
  582. /// <summary>
  583. /// 停用生产线
  584. /// </summary>
  585. /// <param name="lineID">生产线ID</param>
  586. /// <param name="sUserInfo">用户基本信息</param>
  587. /// <returns>int</returns>
  588. /// <remarks>
  589. /// 陈冰 2014.09.15 新建
  590. /// </remarks>
  591. public static int StopProductionLine(int lineID, int flag, SUserInfo sUserInfo)
  592. {
  593. int returnRows = 0;
  594. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  595. try
  596. {
  597. // 更新总表
  598. // 更新明细表
  599. if (flag == 0)
  600. {
  601. string sqlText = "UPDATE tp_pc_productionline SET valueflag=0,UpdateUserID=:updateUserID WHERE productionlineid=:productionLineID";
  602. OracleParameter[] paras = new OracleParameter[]
  603. {
  604. new OracleParameter(":updateUserID",sUserInfo.UserID),
  605. new OracleParameter(":productionLineID",lineID),
  606. };
  607. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  608. sqlText = "UPDATE TP_PC_Procedure SET valueflagback=valueflag, valueflag=0,UpdateUserID=:updateUserID WHERE productionlineid=:productionLineID";
  609. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  610. }
  611. else
  612. {
  613. string sqlText = "UPDATE tp_pc_productionline SET valueflag=1,UpdateUserID=:updateUserID WHERE productionlineid=:productionLineID";
  614. OracleParameter[] paras = new OracleParameter[]
  615. {
  616. new OracleParameter(":updateUserID",sUserInfo.UserID),
  617. new OracleParameter(":productionLineID",lineID),
  618. };
  619. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  620. sqlText = "UPDATE TP_PC_Procedure SET valueflag=valueflagback, UpdateUserID=:updateUserID WHERE productionlineid=:productionLineID";
  621. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  622. }
  623. oracleTrConn.Commit();
  624. }
  625. catch (Exception ex)
  626. {
  627. oracleTrConn.Rollback();
  628. throw ex;
  629. }
  630. finally
  631. {
  632. // 释放资源
  633. if (oracleTrConn.ConnState == System.Data.ConnectionState.Open)
  634. {
  635. oracleTrConn.Disconnect();
  636. }
  637. }
  638. return returnRows;
  639. }
  640. #endregion
  641. #region 班次配置
  642. /// <summary>
  643. /// 保存班次配置信息
  644. /// </summary>
  645. /// <param name="setEntity">班次配置实体</param>
  646. /// <param name="dtClassesSetting">班次配置明细table</param>
  647. /// <param name="sUserInfo">用户基本信息</param>
  648. /// <returns>>0 保存成功 else 失败</returns>
  649. /// <remarks>
  650. /// 作者 日期 内容
  651. /// 冯雪 2014-9-24 新建
  652. /// </remarks>
  653. public static int SaveClassesSetting(ClassesSettingEntity setEntity, DataTable dtClassesSetting, SUserInfo sUserInfo)
  654. {
  655. int returnRows = 0;
  656. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  657. try
  658. {
  659. oracleTrConn.Connect();
  660. int classesSettingID = 0;
  661. if (setEntity.ClassesSettingID == 0)
  662. {
  663. // 查询新插入的生产数据ID
  664. string sqlText = "SELECT SEQ_PC_ClassesSetting_ID.NEXTVAL FROM dual";
  665. classesSettingID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  666. // 插入班次配置表
  667. string sqlString1 = " INSERT INTO TP_PC_ClassesSetting "
  668. + " (ClassesSettingID,AccountDate,UserID,UserCode, "
  669. + " Remarks,AccountID,CreateTime,CreateUserID,UpdateUserID) "
  670. + " VALUES (:ClassesSettingID,:AccountDate,:userID,:userCode, "
  671. + " :remarks,:accountID,sysdate,:createUserID,:updateUserID)";
  672. OracleParameter[] parmeters1 = new OracleParameter[]
  673. {
  674. new OracleParameter(":ClassesSettingID",OracleDbType.Int32,classesSettingID,ParameterDirection.Input),
  675. new OracleParameter(":accountID",OracleDbType.Int32,sUserInfo.AccountID,ParameterDirection.Input),
  676. new OracleParameter(":userID",OracleDbType.Int32,setEntity.UserID,ParameterDirection.Input),
  677. new OracleParameter(":userCode",OracleDbType.Varchar2,setEntity.UserCode,ParameterDirection.Input),
  678. new OracleParameter(":AccountDate",OracleDbType.Date,setEntity.AccountDate,ParameterDirection.Input),
  679. new OracleParameter(":remarks",OracleDbType.Varchar2,setEntity.Remarks,ParameterDirection.Input),
  680. new OracleParameter(":accountID",OracleDbType.Int32,sUserInfo.AccountID,ParameterDirection.Input),
  681. new OracleParameter(":createUserID",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  682. new OracleParameter(":updateUserID",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  683. };
  684. returnRows = oracleTrConn.ExecuteNonQuery(sqlString1, parmeters1);
  685. }
  686. else
  687. {
  688. classesSettingID = setEntity.ClassesSettingID;
  689. // 删除以前的班次
  690. string sqlDelete = "DELETE FROM TP_PC_ClassesDetail WHERE ClassesSettingID=:ClassesSettingID";
  691. OracleParameter[] parmeters1 = new OracleParameter[]
  692. {
  693. new OracleParameter(":ClassesSettingID",OracleDbType.Int32,classesSettingID,ParameterDirection.Input),
  694. };
  695. returnRows = oracleTrConn.ExecuteNonQuery(sqlDelete, parmeters1);
  696. }
  697. #region 保存班次配置明细信息
  698. foreach (DataRow dataRow in dtClassesSetting.Rows)
  699. {
  700. if (dataRow["UJobsId"].ToString() == "" && dataRow["StaffCode"].ToString() == "")
  701. {
  702. continue;
  703. }
  704. if (dataRow.RowState == DataRowState.Deleted)
  705. {
  706. continue;
  707. }
  708. string sqlInsertString = "INSERT INTO TP_PC_ClassesDetail "
  709. + " (ClassesSettingID,AccountDate,userid,usercode,ujobsid,staffid,sjobsid,staffstatus,"
  710. + " remarks,accountid,createtime,createuserid,UpdateUserID,UJobsNum) "
  711. + "VALUES (:settingID,:AccountDate,:userid,:usercode,:ujobsid,:staffid,:sjobsid,:staffstatus,"
  712. + " :remarks,:accountid,sysdate,:createuserid,:updateUserID,:uJobsNum)";
  713. int UJobsNum = 1;//默认一个
  714. if (dtClassesSetting.Select("ujobsid=" + dataRow["UJobsId"]).Length > 0)
  715. {
  716. UJobsNum = dtClassesSetting.Select("ujobsid=" + dataRow["UJobsId"]).Length;
  717. }
  718. OracleParameter[] oracleParameter = new OracleParameter[]
  719. {
  720. new OracleParameter(":settingID",OracleDbType.Int32,classesSettingID,ParameterDirection.Input),
  721. new OracleParameter(":userid",OracleDbType.Int32,dataRow["userid"].ToString(),ParameterDirection.Input),
  722. new OracleParameter(":usercode",OracleDbType.Varchar2,dataRow["usercode"].ToString(),ParameterDirection.Input),
  723. new OracleParameter(":ujobsid",OracleDbType.Int32,dataRow["UJobsId"].ToString(),ParameterDirection.Input),
  724. new OracleParameter(":staffid",OracleDbType.Int32,dataRow["staffid"].ToString(),ParameterDirection.Input),
  725. new OracleParameter(":sjobsid",OracleDbType.Int32,dataRow["Jobs"].ToString(),ParameterDirection.Input),
  726. new OracleParameter(":staffstatus",OracleDbType.Int32,dataRow["staffstatus"].ToString(),ParameterDirection.Input),
  727. new OracleParameter(":remarks",OracleDbType.Varchar2,dataRow["remarks"].ToString(),ParameterDirection.Input),
  728. new OracleParameter(":AccountDate",OracleDbType.Date,setEntity.AccountDate,ParameterDirection.Input),
  729. new OracleParameter(":accountid",OracleDbType.Int32,sUserInfo.AccountID,ParameterDirection.Input),
  730. new OracleParameter(":createuserid",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  731. new OracleParameter(":updateUserID",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  732. new OracleParameter(":uJobsNum",OracleDbType.Decimal,UJobsNum,ParameterDirection.Input)
  733. };
  734. returnRows = oracleTrConn.ExecuteNonQuery(sqlInsertString, oracleParameter);
  735. }
  736. #endregion
  737. oracleTrConn.Commit();
  738. oracleTrConn.Disconnect();
  739. return returnRows;
  740. }
  741. catch (Exception ex)
  742. {
  743. oracleTrConn.Rollback();
  744. oracleTrConn.Disconnect();
  745. throw ex;
  746. }
  747. finally
  748. {
  749. // 释放资源
  750. if (oracleTrConn.ConnState == System.Data.ConnectionState.Open)
  751. {
  752. oracleTrConn.Disconnect();
  753. }
  754. }
  755. }
  756. #endregion
  757. /// <summary>
  758. /// 保存生产线 xuwei modify 2019-11-22
  759. /// </summary>
  760. /// <param name="productionLine">生产线实体</param>
  761. /// <param name="sUserInfo">用户基本信息</param>
  762. /// <returns></returns>
  763. public static int SaveProductionLine2(ProductionLineEntity productionLine, SUserInfo sUserInfo)
  764. {
  765. int returnRows = 0;
  766. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  767. try
  768. {
  769. #region 验证工序个数
  770. if (DataManager.LicDataSet != null)
  771. {
  772. int licCount = Convert.ToInt32(DataManager.LicDataSet.Tables["Info"].Rows[0]["PFNum"]);
  773. if (licCount > -1)
  774. {
  775. int pNum = Convert.ToInt32(oracleTrConn.GetSqlResultToObj("select count(*) from tp_pc_procedure p where p.valueflag = '1' and p.productionlineid <> " + productionLine.ProductionLineID));
  776. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  777. {
  778. if(procedure.ProcedureState != 2)
  779. {
  780. pNum++;
  781. }
  782. }
  783. if (pNum > licCount)
  784. {
  785. oracleTrConn.Rollback();
  786. return -10;
  787. }
  788. }
  789. }
  790. #endregion
  791. #region 新建生产线
  792. if (productionLine.ProductionLineID == 0)
  793. {
  794. #region 判断编码是否重复
  795. string sqlText = " SELECT ProductionLineID "
  796. + " FROM TP_PC_ProductionLine "
  797. + " WHERE "
  798. + " AccountID=:accountID "
  799. + " AND ProductionLineCode=:productionLineCode";
  800. OracleParameter[] paras = new OracleParameter[]
  801. {
  802. new OracleParameter(":accountID",sUserInfo.AccountID),
  803. new OracleParameter(":productionLineCode",productionLine.ProductionLineCode),
  804. };
  805. string returnCode = oracleTrConn.GetSqlResultToStr(sqlText, paras);
  806. if (!string.IsNullOrEmpty(returnCode))
  807. {
  808. return Constant.RETURN_IS_EXIST;
  809. }
  810. #endregion
  811. #region 查询新ID
  812. sqlText = "SELECT SEQ_PC_PRODUCTIONLINE_ID.nextval FROM dual";
  813. productionLine.ProductionLineID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  814. #endregion
  815. #region 插入生产线
  816. sqlText = "INSERT INTO TP_PC_ProductionLine (ProductionLineID,"
  817. + "ProductionLineCode,"
  818. + "ProductionLineName,"
  819. + "FlowXML,"
  820. + "Remarks,"
  821. + "AccountID,"
  822. + "CreateUserID,"
  823. + "UpdateUserID)"
  824. + " VALUES(:ProductionLineID,"
  825. + ":productionLineCode,"
  826. + ":productionLineName,"
  827. + ":flowXML,"
  828. + ":remarks,"
  829. + ":accountID,"
  830. + ":createUserID,"
  831. + ":updateUserID"
  832. + ")";
  833. paras = new OracleParameter[]
  834. {
  835. new OracleParameter(":ProductionLineID",productionLine.ProductionLineID),
  836. new OracleParameter(":productionLineCode",productionLine.ProductionLineCode),
  837. new OracleParameter(":productionLineName",productionLine.ProductionLineName),
  838. new OracleParameter(":flowXML", System.Text.Encoding.UTF8.GetBytes(productionLine.FlowXML)),
  839. new OracleParameter(":remarks",productionLine.Remarks),
  840. new OracleParameter(":accountID",sUserInfo.AccountID),
  841. new OracleParameter(":createUserID",sUserInfo.UserID),
  842. new OracleParameter(":updateUserID",sUserInfo.UserID),
  843. };
  844. foreach (OracleParameter item in paras)
  845. {
  846. if (item.Value + "" == "")
  847. {
  848. item.Value = System.DBNull.Value;
  849. }
  850. }
  851. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  852. #endregion
  853. //#region 查询新ID
  854. //sqlText = "SELECT SEQ_PC_PRODUCTIONLINE_ID.currval FROM dual";
  855. //productionLine.ProductionLineID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  856. //#endregion
  857. #region 插入工序
  858. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  859. {
  860. sqlText = "SELECT SEQ_PC_PROCEDURE_PROCEDUREID.Nextval FROM dual";
  861. procedure.ProcedureID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  862. sqlText = "INSERT INTO TP_PC_Procedure ("
  863. + "ProcedureID,"
  864. + "NodeNo,"
  865. + "ProductionLineID,"
  866. + "ProcedureCode,"
  867. + "ProcedureName,"
  868. + "ProcedureModel,"
  869. + "ModelType,"
  870. + "NodeType,"
  871. + "MustFlag,"
  872. + "CollectType,"
  873. + "PieceType,"
  874. + "IsSpecialRework,"
  875. + "IsSemireWork,"
  876. + "OrganizationID,"
  877. + "Remarks,"
  878. + "AccountID,"
  879. + "CreateUserID,"
  880. + "UpdateUserID,misspriority,displayno,UNDOFLAG,DeliverType,BarCodePrintCopies,BarCodeFlag)"
  881. + " VALUES("
  882. + ":procedureID,"
  883. + ":nodeNo,"
  884. + ":productionLineID,"
  885. + ":procedureCode,"
  886. + ":procedureName,"
  887. + ":procedureModel,"
  888. + ":ModelType,"
  889. + ":NodeType,"
  890. + ":mustFlag,"
  891. + ":collectType,"
  892. + ":pieceType,"
  893. + ":isSpecialRework,"
  894. + ":isSemireWork,"
  895. + ":organizationID,"
  896. + ":remarks,"
  897. + ":accountID,"
  898. + ":createUserID,"
  899. + ":updateUserID,:misspriority,:displayno,:UNDOFLAG,:DeliverType,:BarCodePrintCopies,:BarCodeFlag"
  900. + ")";
  901. paras = new OracleParameter[]
  902. {
  903. new OracleParameter(":procedureID",procedure.ProcedureID),
  904. new OracleParameter(":nodeNo",procedure.NodeNo),
  905. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  906. new OracleParameter(":procedureCode",procedure.ProcedureCode),
  907. new OracleParameter(":procedureName",procedure.ProcedureName),
  908. new OracleParameter(":procedureModel",procedure.ProcedureModel),
  909. new OracleParameter(":ModelType",procedure.ModelType),
  910. new OracleParameter(":NodeType",procedure.NodeType),
  911. new OracleParameter(":mustFlag",procedure.MustFlag),
  912. new OracleParameter(":collectType",procedure.CollectType),
  913. new OracleParameter(":pieceType",procedure.PieceType),
  914. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  915. new OracleParameter(":isSemireWork",procedure.IsSemireWork),
  916. new OracleParameter(":organizationID",procedure.OrganizationID),
  917. new OracleParameter(":remarks",procedure.Remarks),
  918. new OracleParameter(":accountID",sUserInfo.AccountID),
  919. new OracleParameter(":createUserID",sUserInfo.UserID),
  920. new OracleParameter(":updateUserID",sUserInfo.UserID),
  921. new OracleParameter(":misspriority",procedure.MissPriority),
  922. new OracleParameter(":displayno",procedure.DisplayNo),
  923. new OracleParameter(":UNDOFLAG",procedure.UnDo),
  924. new OracleParameter(":DeliverType",procedure.DeliverType),
  925. new OracleParameter(":BarCodePrintCopies",procedure.BarCodePrintCopies),
  926. new OracleParameter(":BarCodeFlag",procedure.BarCodeFlag),
  927. };
  928. foreach (OracleParameter item in paras)
  929. {
  930. if (item.Value + "" == "")
  931. {
  932. item.Value = System.DBNull.Value;
  933. }
  934. }
  935. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  936. }
  937. #endregion
  938. }
  939. #endregion
  940. #region 编辑生产线
  941. else
  942. {
  943. #region 校验时间戳
  944. // todo
  945. string sql = "SELECT OPTimeStamp FROM TP_PC_ProductionLine"
  946. + " WHERE ProductionLineID = " + productionLine.ProductionLineID + " and OPTimeStamp = :OPTimeStamp";
  947. OracleParameter[] parmetersSql = new OracleParameter[]
  948. {
  949. new OracleParameter(":OPTimeStamp", OracleDbType.TimeStamp, productionLine.OPTimeStamp, ParameterDirection.Input),
  950. };
  951. DataSet returnDataset = oracleTrConn.GetSqlResultToDs(sql, parmetersSql);
  952. if (returnDataset != null && returnDataset.Tables[0].Rows.Count == 0)
  953. {
  954. oracleTrConn.Commit();
  955. oracleTrConn.Disconnect();
  956. return Constant.RETURN_IS_DATACHANGED;
  957. }
  958. #endregion
  959. #region 判断编码是否重复
  960. string sqlText = " SELECT ProductionLineID "
  961. + " FROM TP_PC_ProductionLine "
  962. + " WHERE "
  963. + " AccountID=:accountID "
  964. + " AND ProductionLineCode=:productionLineCode"
  965. + " AND ProductionLineID <> :productionLineID";
  966. OracleParameter[] paras = new OracleParameter[]
  967. {
  968. new OracleParameter(":accountID",sUserInfo.AccountID),
  969. new OracleParameter(":productionLineCode",productionLine.ProductionLineCode),
  970. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  971. };
  972. string returnCode = oracleTrConn.GetSqlResultToStr(sqlText, paras);
  973. if (!string.IsNullOrEmpty(returnCode))
  974. {
  975. return Constant.RETURN_IS_EXIST;
  976. }
  977. #endregion
  978. #region 编辑生产线
  979. sqlText = "UPDATE TP_PC_ProductionLine SET "
  980. + "ProductionLineName=:productionLineName,"
  981. + "FlowXML=:flowXML,"
  982. + "Remarks=:remarks,"
  983. + "UpdateTime=sysdate, "
  984. + "UpdateUserID=:updateUserID "
  985. + " WHERE ProductionLineID=:productionLineID";
  986. paras = new OracleParameter[]
  987. {
  988. new OracleParameter(":productionLineName",productionLine.ProductionLineName),
  989. new OracleParameter(":flowXML", OracleDbType.Blob,System.Text.Encoding.UTF8.GetBytes(productionLine.FlowXML),ParameterDirection.Input),
  990. new OracleParameter(":remarks",productionLine.Remarks),
  991. new OracleParameter(":updateUserID",OracleDbType.Int32, sUserInfo.UserID,ParameterDirection.Input),
  992. new OracleParameter(":productionLineID", OracleDbType.Int32, productionLine.ProductionLineID,ParameterDirection.Input)
  993. };
  994. //foreach (OracleParameter item in paras)
  995. //{
  996. // if (item.Value + "" == "")
  997. // {
  998. // item.Value = System.DBNull.Value;
  999. // }
  1000. //}
  1001. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1002. #endregion
  1003. #region 编辑工序
  1004. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  1005. {
  1006. //if (procedure.EditingAddFlag)
  1007. if (procedure.ProcedureState == 1)
  1008. {
  1009. #region 编辑时新添加的节点
  1010. sqlText = "SELECT SEQ_PC_PROCEDURE_PROCEDUREID.Nextval FROM dual";
  1011. procedure.ProcedureID = int.Parse(oracleTrConn.GetSqlResultToStr(sqlText));
  1012. sqlText = "INSERT INTO TP_PC_Procedure ("
  1013. + "ProcedureID,"
  1014. + "NodeNo,"
  1015. + "ProductionLineID,"
  1016. + "ProcedureCode,"
  1017. + "ProcedureName,"
  1018. + "ProcedureModel,"
  1019. + "ModelType,"
  1020. + "NodeType,"
  1021. + "MustFlag,"
  1022. + "CollectType,"
  1023. + "PieceType,"
  1024. + "IsSpecialRework,"
  1025. + "IsSemireWork,"
  1026. + "OrganizationID,"
  1027. + "Remarks,"
  1028. + "AccountID,"
  1029. + "CreateUserID,"
  1030. + "UpdateUserID,misspriority,displayno,UNDOFLAG,DeliverType,BarCodePrintCopies,BarCodeFlag)"
  1031. + " VALUES("
  1032. + ":procedureID,"
  1033. + ":nodeNo,"
  1034. + ":productionLineID,"
  1035. + ":procedureCode,"
  1036. + ":procedureName,"
  1037. + ":procedureModel,"
  1038. + ":ModelType,"
  1039. + ":NodeType,"
  1040. + ":mustFlag,"
  1041. + ":collectType,"
  1042. + ":pieceType,"
  1043. + ":isSpecialRework,"
  1044. + ":isSemireWork,"
  1045. + ":organizationID,"
  1046. + ":remarks,"
  1047. + ":accountID,"
  1048. + ":createUserID,"
  1049. + ":updateUserID,:misspriority,:displayno,:UNDOFLAG,:DeliverType,:BarCodePrintCopies,:BarCodeFlag"
  1050. + ")";
  1051. paras = new OracleParameter[]
  1052. {
  1053. new OracleParameter(":procedureID",procedure.ProcedureID),
  1054. new OracleParameter(":nodeNo",procedure.NodeNo),
  1055. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1056. new OracleParameter(":procedureCode",procedure.ProcedureCode),
  1057. new OracleParameter(":procedureName",procedure.ProcedureName),
  1058. new OracleParameter(":procedureModel",procedure.ProcedureModel),
  1059. new OracleParameter(":ModelType",procedure.ModelType),
  1060. new OracleParameter(":NodeType",procedure.NodeType),
  1061. new OracleParameter(":mustFlag",procedure.MustFlag),
  1062. new OracleParameter(":collectType",procedure.CollectType),
  1063. new OracleParameter(":pieceType",procedure.PieceType),
  1064. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  1065. new OracleParameter(":isSemireWork",procedure.IsSemireWork),
  1066. new OracleParameter(":organizationID",procedure.OrganizationID),
  1067. new OracleParameter(":remarks",procedure.Remarks),
  1068. new OracleParameter(":accountID",sUserInfo.AccountID),
  1069. new OracleParameter(":createUserID",sUserInfo.UserID),
  1070. new OracleParameter(":updateUserID",sUserInfo.UserID),
  1071. new OracleParameter(":misspriority",procedure.MissPriority),
  1072. new OracleParameter(":displayno",procedure.DisplayNo),
  1073. new OracleParameter(":UNDOFLAG",procedure.UnDo),
  1074. new OracleParameter(":DeliverType",procedure.DeliverType),
  1075. new OracleParameter(":BarCodePrintCopies",procedure.BarCodePrintCopies),
  1076. new OracleParameter(":BarCodeFlag",procedure.BarCodeFlag),
  1077. };
  1078. #endregion
  1079. }
  1080. else if (procedure.ProcedureState == 2) //后添加的,删除后标用节点
  1081. {
  1082. #region 编辑
  1083. sqlText = "update TP_PC_Procedure set valueflag=0 "
  1084. + " WHERE ProcedureID=:procedureID "
  1085. + " AND ProductionLineID=:productionLineID";
  1086. paras = new OracleParameter[]
  1087. {
  1088. new OracleParameter(":procedureID",procedure.ProcedureID),
  1089. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1090. };
  1091. #endregion
  1092. }
  1093. else
  1094. {
  1095. #region 编辑
  1096. sqlText = "UPDATE TP_PC_Procedure SET "
  1097. + " ProcedureName=:procedureName,"
  1098. + " ProcedureCode=:ProcedureCode,"
  1099. + " ModelType=:modelType,"
  1100. + " MustFlag=:mustFlag,"
  1101. + " CollectType=:collectType,"
  1102. + " OrganizationID=:organizationID,"
  1103. + " NodeType=:nodeType,"
  1104. + " PieceType=:pieceType,"
  1105. + " IsSpecialRework=:isSpecialRework,"
  1106. + " IsSemireWork=:isSemireWork,"
  1107. + " PrintType=:printType," //xuwei add 2019-11-20
  1108. + " IsGlazeChange=:IsGlazeChange," //xuwei add 2020-01-02
  1109. + " NodeNo=:nodeNo,"
  1110. + " Remarks=:remarks,"
  1111. + " updateUserID=:updateUserID,"
  1112. + " UpdateTime=sysdate,"
  1113. + " misspriority=:misspriority,"
  1114. + " displayno=:displayno,"
  1115. + " UNDOFLAG=:UNDOFLAG,"
  1116. + " DeliverType=:DeliverType,"
  1117. + " BarCodePrintCopies=:BarCodePrintCopies,"
  1118. + " BarCodeFlag=:BarCodeFlag"
  1119. + " WHERE NodeNo=:nodeNo "
  1120. + " AND ProductionLineID=:productionLineID";
  1121. paras = new OracleParameter[]
  1122. {
  1123. new OracleParameter(":nodeNo",procedure.NodeNo),
  1124. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1125. new OracleParameter(":procedureName",procedure.ProcedureName),
  1126. new OracleParameter(":ProcedureCode",procedure.ProcedureCode),
  1127. new OracleParameter(":modelType",procedure.ModelType),
  1128. new OracleParameter(":mustFlag",procedure.MustFlag),
  1129. new OracleParameter(":collectType",procedure.CollectType),
  1130. new OracleParameter(":organizationID",procedure.OrganizationID),
  1131. new OracleParameter(":nodeType",procedure.NodeType),
  1132. new OracleParameter(":pieceType",procedure.PieceType),
  1133. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  1134. new OracleParameter(":isSemireWork",procedure.IsSemireWork),
  1135. new OracleParameter(":printType",procedure.PrintType),//xuwei add 2019-11-20
  1136. new OracleParameter(":IsGlazeChange",procedure.IsGlazeChange),//xuwei add 2020-01-02
  1137. new OracleParameter(":nodeNo",procedure.NodeNo),
  1138. new OracleParameter(":remarks",procedure.Remarks),
  1139. new OracleParameter(":updateUserID",sUserInfo.UserID),
  1140. new OracleParameter(":misspriority",procedure.MissPriority),
  1141. new OracleParameter(":displayno",procedure.DisplayNo),
  1142. new OracleParameter(":UNDOFLAG",procedure.UnDo),
  1143. new OracleParameter(":DeliverType",procedure.DeliverType),
  1144. new OracleParameter(":BarCodePrintCopies",procedure.BarCodePrintCopies),
  1145. new OracleParameter(":BarCodeFlag",procedure.BarCodeFlag),
  1146. };
  1147. #endregion
  1148. }
  1149. foreach (OracleParameter item in paras)
  1150. {
  1151. if (item.Value + "" == "")
  1152. {
  1153. item.Value = System.DBNull.Value;
  1154. }
  1155. }
  1156. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1157. }
  1158. #endregion
  1159. #region 先删除生产工序流程明细 然后再插入
  1160. sqlText = "DELETE TP_PC_ProcedureFlow WHERE ProductionLineID=:productionLineID";
  1161. paras = new OracleParameter[]
  1162. {
  1163. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1164. };
  1165. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1166. #endregion
  1167. #region 删除对应产品 然后再插入
  1168. sqlText = "DELETE TP_PC_ProcedureGoods WHERE ProductionLineID=:productionLineID";
  1169. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1170. #endregion
  1171. #region 删除对应工号 然后再插入
  1172. sqlText = "DELETE TP_PC_ProcedureUser WHERE ProductionLineID=:productionLineID";
  1173. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1174. #endregion
  1175. #region 删除对应缺陷 然后再插入
  1176. sqlText = "DELETE TP_PC_ProcedureDefect WHERE ProductionLineID=:productionLineID";
  1177. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1178. #endregion
  1179. #region 删除缺陷对应工序工种表 然后再插入
  1180. sqlText = "DELETE TP_PC_DefectProcedureJobs WHERE ProductionLineID=:productionLineID";
  1181. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1182. #endregion
  1183. #region 删除对应窑炉 然后再插入
  1184. sqlText = "DELETE TP_PC_ProcedureKiln WHERE ProductionLineID=:productionLineID";
  1185. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1186. #endregion
  1187. #region 删除半检产品等级 然后再插入 xuwei add 2019-12-12
  1188. sqlText = "DELETE TP_PC_PROCEDUREGOODSLEVEL WHERE PRODUCTIONLINEID = :productionLineID";
  1189. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1190. #endregion
  1191. }
  1192. #endregion
  1193. #region 插入生产工序属性等信息
  1194. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  1195. {
  1196. string sqlText;
  1197. OracleParameter[] paras;
  1198. #region 插入生产工序流程明细
  1199. if (procedure.ProcedureFlowDetailList != null)
  1200. {
  1201. foreach (ProcedureFlowEntity flowDetail in procedure.ProcedureFlowDetailList)
  1202. {
  1203. ProcedureEntity procedureWhere = productionLine.ProcedureList.Where(p => p.NodeNo == flowDetail.ArriveNodeNo).SingleOrDefault();
  1204. // 没有找到对应节点的ID
  1205. if (procedureWhere == null)
  1206. {
  1207. return Constant.INT_IS_ZERO;
  1208. }
  1209. else
  1210. {
  1211. flowDetail.ArriveProcedureID = procedureWhere.ProcedureID;
  1212. }
  1213. sqlText = "INSERT INTO TP_PC_ProcedureFlow ("
  1214. + "ProductionLineID,"
  1215. + "ProcedureID,"
  1216. + "NodeNo,"
  1217. + "FlowFlag,"
  1218. + "ArriveProcedureID,"
  1219. + "ArriveNodeNo"
  1220. + ")"
  1221. + " VALUES("
  1222. + ":productionLineID,"
  1223. + ":procedureID,"
  1224. + ":nodeNo,"
  1225. + ":flowFlag,"
  1226. + ":arriveProcedureID,"
  1227. + ":arriveNodeNo"
  1228. + ")";
  1229. paras = new OracleParameter[]
  1230. {
  1231. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1232. new OracleParameter(":procedureID",procedure.ProcedureID),
  1233. new OracleParameter(":nodeNo",procedure.NodeNo),
  1234. new OracleParameter(":flowFlag",flowDetail.FlowFlag),
  1235. new OracleParameter(":arriveProcedureID",flowDetail.ArriveProcedureID),
  1236. new OracleParameter(":arriveNodeNo",flowDetail.ArriveNodeNo),
  1237. };
  1238. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1239. }
  1240. }
  1241. #endregion
  1242. #region 插入生产工序对应产品表
  1243. foreach (DataRow row in procedure.ProcedureGoodsTable.Rows)
  1244. {
  1245. sqlText = "INSERT INTO TP_PC_ProcedureGoods ("
  1246. + "ProductionLineID,"
  1247. + "ProcedureID,"
  1248. + "NodeNo,"
  1249. + "GOODSID,"
  1250. + "CreateUserID"
  1251. + ")"
  1252. + " VALUES("
  1253. + ":productionLineID,"
  1254. + ":procedureID,"
  1255. + ":nodeNo,"
  1256. + ":goodsID,"
  1257. + ":createUserID"
  1258. + ")";
  1259. paras = new OracleParameter[]
  1260. {
  1261. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1262. new OracleParameter(":procedureID",procedure.ProcedureID),
  1263. new OracleParameter(":nodeNo",procedure.NodeNo),
  1264. new OracleParameter(":goodsID",OracleDbType.Int32,row["goodsID"],ParameterDirection.Input),
  1265. new OracleParameter(":createUserID",sUserInfo.UserID),
  1266. };
  1267. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1268. }
  1269. #endregion
  1270. #region 插入生产工序对应工号表
  1271. foreach (DataRow row in procedure.ProcedureUserTable.Rows)
  1272. {
  1273. sqlText = "INSERT INTO TP_PC_ProcedureUser ("
  1274. + "ProductionLineID,"
  1275. + "ProcedureID,"
  1276. + "NodeNo,"
  1277. + "UserID,"
  1278. + "CreateUserID"
  1279. + ")"
  1280. + " VALUES("
  1281. + ":productionLineID,"
  1282. + ":procedureID,"
  1283. + ":nodeNo,"
  1284. + ":userID,"
  1285. + ":createUserID"
  1286. + ")";
  1287. paras = new OracleParameter[]
  1288. {
  1289. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1290. new OracleParameter(":procedureID",procedure.ProcedureID),
  1291. new OracleParameter(":nodeNo",procedure.NodeNo),
  1292. new OracleParameter(":userID",OracleDbType.Int32,row["userID"],ParameterDirection.Input),
  1293. new OracleParameter(":createUserID",sUserInfo.UserID),
  1294. };
  1295. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1296. }
  1297. #endregion
  1298. #region 插入生产工序对应缺陷表
  1299. foreach (DataRow row in procedure.ProcedureDefectTable.Rows)
  1300. {
  1301. if (row["DefectID"] == DBNull.Value)
  1302. {
  1303. continue;
  1304. }
  1305. sqlText = "INSERT INTO TP_PC_ProcedureDefect ("
  1306. + "ProductionLineID,"
  1307. + "ProcedureID,"
  1308. + "NodeNo,"
  1309. + "DefectID,"
  1310. + "CreateUserID"
  1311. + ")"
  1312. + " VALUES("
  1313. + ":productionLineID,"
  1314. + ":procedureID,"
  1315. + ":nodeNo,"
  1316. + ":defectID,"
  1317. + ":createUserID"
  1318. + ")";
  1319. paras = new OracleParameter[]
  1320. {
  1321. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1322. new OracleParameter(":procedureID",procedure.ProcedureID),
  1323. new OracleParameter(":nodeNo",procedure.NodeNo),
  1324. new OracleParameter(":defectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1325. new OracleParameter(":createUserID",sUserInfo.UserID),
  1326. };
  1327. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1328. }
  1329. #endregion
  1330. #region 插入缺陷对应工序工种表
  1331. foreach (DataRow row in procedure.DefectProcedureJobsTable.Rows)
  1332. {
  1333. if (row["DefectID"] == DBNull.Value || row["jobsID"] == DBNull.Value)
  1334. {
  1335. continue;
  1336. }
  1337. sqlText = "INSERT INTO TP_PC_DefectProcedureJobs ("
  1338. + "ProductionLineID,"
  1339. + "ProcedureID,"
  1340. + "NodeNo,"
  1341. + "DefectID,"
  1342. + "JobsID,"
  1343. + "CreateUserID"
  1344. + ")"
  1345. + " VALUES("
  1346. + ":productionLineID,"
  1347. + ":procedureID,"
  1348. + ":nodeNo,"
  1349. + ":DefectID,"
  1350. + ":jobsID,"
  1351. + ":createUserID"
  1352. + ")";
  1353. paras = new OracleParameter[]
  1354. {
  1355. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1356. new OracleParameter(":procedureID",procedure.ProcedureID),
  1357. new OracleParameter(":nodeNo",procedure.NodeNo),
  1358. new OracleParameter(":DefectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1359. new OracleParameter(":jobsID",OracleDbType.Int32,row["jobsID"],ParameterDirection.Input),
  1360. new OracleParameter(":createUserID",sUserInfo.UserID),
  1361. };
  1362. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1363. }
  1364. #endregion
  1365. #region 插入生产工序对应窑炉
  1366. if (procedure.ProcedureKilnTable != null)
  1367. {
  1368. foreach (DataRow row in procedure.ProcedureKilnTable.Rows)
  1369. {
  1370. sqlText = "INSERT INTO tp_pc_procedurekiln ("
  1371. + "ProductionLineID,"
  1372. + "ProcedureID,"
  1373. + "NodeNo,"
  1374. + "KilnID,"
  1375. + "CreateUserID"
  1376. + ")"
  1377. + " VALUES("
  1378. + ":productionLineID,"
  1379. + ":procedureID,"
  1380. + ":nodeNo,"
  1381. + ":kilnID,"
  1382. + ":createUserID"
  1383. + ")";
  1384. paras = new OracleParameter[]
  1385. {
  1386. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1387. new OracleParameter(":procedureID",procedure.ProcedureID),
  1388. new OracleParameter(":nodeNo",procedure.NodeNo),
  1389. new OracleParameter(":kilnID",OracleDbType.Int32,row["kilnID"],ParameterDirection.Input),
  1390. new OracleParameter(":createUserID",sUserInfo.UserID),
  1391. };
  1392. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1393. }
  1394. }
  1395. #endregion
  1396. #region 插入生产工序对应半检产品等级 xuwei add 2019-12-12
  1397. if (!string.IsNullOrEmpty(procedure.SemiGoodsLevel))
  1398. {
  1399. string[] ids = procedure.SemiGoodsLevel.Split(',');
  1400. string sqlStr = @"
  1401. BEGIN
  1402. ";
  1403. for (int i = 0; i < ids.Length; i++)
  1404. {
  1405. sqlStr += $@"
  1406. INSERT INTO TP_PC_PROCEDUREGOODSLEVEL
  1407. ( PRODUCTIONLINEID, PROCEDUREID, GOODSLEVELTYPEID)
  1408. VALUES
  1409. (:PRODUCTIONLINEID, :PROCEDUREID, {ids[i]});
  1410. ";
  1411. }
  1412. sqlStr += "END;";
  1413. oracleTrConn.ExecuteNonQuery(
  1414. sqlStr,
  1415. new OracleParameter[]
  1416. {
  1417. new OracleParameter(":PRODUCTIONLINEID",productionLine.ProductionLineID),
  1418. new OracleParameter(":PROCEDUREID",procedure.ProcedureID)
  1419. }
  1420. );
  1421. }
  1422. #endregion
  1423. }
  1424. #endregion
  1425. oracleTrConn.Commit();
  1426. }
  1427. catch (Exception ex)
  1428. {
  1429. oracleTrConn.Rollback();
  1430. throw ex;
  1431. }
  1432. finally
  1433. {
  1434. // 释放资源
  1435. if (oracleTrConn.ConnState == System.Data.ConnectionState.Open)
  1436. {
  1437. oracleTrConn.Disconnect();
  1438. }
  1439. }
  1440. return returnRows;
  1441. }
  1442. /// <summary>
  1443. /// 保存工序节点
  1444. /// </summary>
  1445. /// <param name="procedureEntity">工序实体</param>
  1446. /// <param name="sUserInfo">用户基本信息</param>
  1447. /// <returns></returns>
  1448. public static int SaveProcedureInfo(ProcedureEntity procedure, SUserInfo sUserInfo)
  1449. {
  1450. int returnRows = 0;
  1451. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  1452. try
  1453. {
  1454. #region 校验时间戳
  1455. // todo
  1456. string sql = "SELECT OPTimeStamp FROM TP_PC_Procedure"
  1457. + " WHERE ProcedureID = " + procedure.ProcedureID + " and OPTimeStamp = :OPTimeStamp and productionlineid=:productionlineid and nodeno=:nodeno";
  1458. OracleParameter[] parmetersSql = new OracleParameter[]
  1459. {
  1460. new OracleParameter(":OPTimeStamp", OracleDbType.TimeStamp, procedure.OPTimeStamp, ParameterDirection.Input),
  1461. new OracleParameter(":productionlineid", OracleDbType.Int32, procedure.ProductionLineID, ParameterDirection.Input),
  1462. new OracleParameter(":nodeno", OracleDbType.Int32, procedure.NodeNo, ParameterDirection.Input),
  1463. };
  1464. DataSet returnDataset = oracleTrConn.GetSqlResultToDs(sql, parmetersSql);
  1465. if (returnDataset != null && returnDataset.Tables[0].Rows.Count == 0)
  1466. {
  1467. oracleTrConn.Commit();
  1468. oracleTrConn.Disconnect();
  1469. return Constant.RETURN_IS_DATACHANGED;
  1470. }
  1471. #endregion
  1472. string sqlText = "";
  1473. #region 更新工序信息
  1474. sqlText = "UPDATE TP_PC_Procedure SET "
  1475. + " ProcedureName=:procedureName,"
  1476. + " ProcedureCode=:ProcedureCode,"
  1477. + " CollectType=:collectType,"
  1478. + " OrganizationID=:organizationID,"
  1479. + " NodeType=:nodeType,"
  1480. + " PieceType=:pieceType,"
  1481. + " IsSpecialRework=:isSpecialRework,"
  1482. + " IsSemireWork=:isSemireWork," //xuwei add 2019-10-14
  1483. + " PrintType=:printType," //xuwei add 2019-11-20
  1484. + " IsGlazeChange=:IsGlazeChange," //xuwei add 2019-11-20
  1485. + " NodeNo=:nodeNo,"
  1486. + " Remarks=:remarks,"
  1487. + " updateUserID=:updateUserID,"
  1488. + " UpdateTime=sysdate,"
  1489. + " misspriority=:misspriority,"
  1490. + " displayno=:displayno,"
  1491. + " UNDOFLAG=:UNDOFLAG,"
  1492. + " DeliverType=:DeliverType,"
  1493. + " MustFlag=:mustFlag,"
  1494. + " BarCodePrintCopies=:BarCodePrintCopies,"
  1495. + " BarCodeFlag=:BarCodeFlag"
  1496. + " WHERE NodeNo=:nodeNo "
  1497. + " AND ProductionLineID=:productionLineID";
  1498. OracleParameter[] paras = new OracleParameter[]
  1499. {
  1500. new OracleParameter(":nodeNo",procedure.NodeNo),
  1501. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1502. new OracleParameter(":procedureName",procedure.ProcedureName),
  1503. new OracleParameter(":ProcedureCode",procedure.ProcedureCode),
  1504. new OracleParameter(":collectType",procedure.CollectType),
  1505. new OracleParameter(":organizationID",procedure.OrganizationID),
  1506. new OracleParameter(":nodeType",procedure.NodeType),
  1507. new OracleParameter(":pieceType",procedure.PieceType),
  1508. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  1509. new OracleParameter(":isSemireWork",procedure.IsSemireWork),//xuwei add 2019-10-14
  1510. new OracleParameter(":printType",procedure.PrintType),//xuwei add 2019-11-20
  1511. new OracleParameter(":IsGlazeChange",procedure.IsGlazeChange),//xuwei add 2020-01-02
  1512. new OracleParameter(":nodeNo",procedure.NodeNo),
  1513. new OracleParameter(":remarks",procedure.Remarks),
  1514. new OracleParameter(":updateUserID",sUserInfo.UserID),
  1515. new OracleParameter(":misspriority",procedure.MissPriority),
  1516. new OracleParameter(":displayno",procedure.DisplayNo),
  1517. new OracleParameter(":UNDOFLAG",procedure.UnDo),
  1518. new OracleParameter(":DeliverType",procedure.DeliverType),
  1519. new OracleParameter(":mustFlag",procedure.MustFlag),
  1520. new OracleParameter(":BarCodePrintCopies",procedure.BarCodePrintCopies),
  1521. new OracleParameter(":BarCodeFlag",procedure.BarCodeFlag),
  1522. };
  1523. foreach (OracleParameter item in paras)
  1524. {
  1525. if (item.Value + "" == "")
  1526. {
  1527. item.Value = System.DBNull.Value;
  1528. }
  1529. }
  1530. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1531. #endregion
  1532. paras = new OracleParameter[]
  1533. {
  1534. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1535. new OracleParameter(":nodeno",procedure.NodeNo),
  1536. new OracleParameter(":procedureid",procedure.ProcedureID),
  1537. };
  1538. #region 删除对应产品 然后再插入
  1539. sqlText = "DELETE TP_PC_ProcedureGoods WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1540. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1541. #endregion
  1542. #region 删除对应工号 然后再插入
  1543. sqlText = "DELETE TP_PC_ProcedureUser WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1544. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1545. #endregion
  1546. #region 删除对应缺陷 然后再插入
  1547. sqlText = "DELETE TP_PC_ProcedureDefect WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1548. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1549. #endregion
  1550. #region 删除缺陷对应工序工种表 然后再插入
  1551. sqlText = "DELETE TP_PC_DefectProcedureJobs WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1552. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1553. #endregion
  1554. #region 删除对应窑炉 然后再插入
  1555. sqlText = "DELETE TP_PC_ProcedureKiln WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1556. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1557. #endregion
  1558. #region 删除半检产品等级 然后再插入 xuwei add 2019-12-12
  1559. sqlText = "DELETE TP_PC_PROCEDUREGOODSLEVEL WHERE PRODUCTIONLINEID = :productionLineID and ProcedureID=:procedureid";
  1560. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, new OracleParameter[]
  1561. {
  1562. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1563. new OracleParameter(":procedureid",procedure.ProcedureID),
  1564. });
  1565. #endregion
  1566. #region 插入生产工序对应产品表
  1567. foreach (DataRow row in procedure.ProcedureGoodsTable.Rows)
  1568. {
  1569. sqlText = "INSERT INTO TP_PC_ProcedureGoods ("
  1570. + "ProductionLineID,"
  1571. + "ProcedureID,"
  1572. + "NodeNo,"
  1573. + "GOODSID,"
  1574. + "CreateUserID"
  1575. + ")"
  1576. + " VALUES("
  1577. + ":productionLineID,"
  1578. + ":procedureID,"
  1579. + ":nodeNo,"
  1580. + ":goodsID,"
  1581. + ":createUserID"
  1582. + ")";
  1583. paras = new OracleParameter[]
  1584. {
  1585. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1586. new OracleParameter(":procedureID",procedure.ProcedureID),
  1587. new OracleParameter(":nodeNo",procedure.NodeNo),
  1588. new OracleParameter(":goodsID",OracleDbType.Int32,row["goodsID"],ParameterDirection.Input),
  1589. new OracleParameter(":createUserID",sUserInfo.UserID),
  1590. };
  1591. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1592. }
  1593. #endregion
  1594. #region 插入生产工序对应工号表
  1595. foreach (DataRow row in procedure.ProcedureUserTable.Rows)
  1596. {
  1597. sqlText = "INSERT INTO TP_PC_ProcedureUser ("
  1598. + "ProductionLineID,"
  1599. + "ProcedureID,"
  1600. + "NodeNo,"
  1601. + "UserID,"
  1602. + "CreateUserID"
  1603. + ")"
  1604. + " VALUES("
  1605. + ":productionLineID,"
  1606. + ":procedureID,"
  1607. + ":nodeNo,"
  1608. + ":userID,"
  1609. + ":createUserID"
  1610. + ")";
  1611. paras = new OracleParameter[]
  1612. {
  1613. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1614. new OracleParameter(":procedureID",procedure.ProcedureID),
  1615. new OracleParameter(":nodeNo",procedure.NodeNo),
  1616. new OracleParameter(":userID",OracleDbType.Int32,row["userID"],ParameterDirection.Input),
  1617. new OracleParameter(":createUserID",sUserInfo.UserID),
  1618. };
  1619. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1620. }
  1621. #endregion
  1622. #region 插入生产工序对应缺陷表
  1623. foreach (DataRow row in procedure.ProcedureDefectTable.Rows)
  1624. {
  1625. if (row["DefectID"] == DBNull.Value)
  1626. {
  1627. continue;
  1628. }
  1629. sqlText = "INSERT INTO TP_PC_ProcedureDefect ("
  1630. + "ProductionLineID,"
  1631. + "ProcedureID,"
  1632. + "NodeNo,"
  1633. + "DefectID,"
  1634. + "CreateUserID"
  1635. + ")"
  1636. + " VALUES("
  1637. + ":productionLineID,"
  1638. + ":procedureID,"
  1639. + ":nodeNo,"
  1640. + ":defectID,"
  1641. + ":createUserID"
  1642. + ")";
  1643. paras = new OracleParameter[]
  1644. {
  1645. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1646. new OracleParameter(":procedureID",procedure.ProcedureID),
  1647. new OracleParameter(":nodeNo",procedure.NodeNo),
  1648. new OracleParameter(":defectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1649. new OracleParameter(":createUserID",sUserInfo.UserID),
  1650. };
  1651. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1652. }
  1653. #endregion
  1654. #region 插入缺陷对应工序工种表
  1655. foreach (DataRow row in procedure.DefectProcedureJobsTable.Rows)
  1656. {
  1657. if (row["DefectID"] == DBNull.Value || row["jobsID"] == DBNull.Value)
  1658. {
  1659. continue;
  1660. }
  1661. sqlText = "INSERT INTO TP_PC_DefectProcedureJobs ("
  1662. + "ProductionLineID,"
  1663. + "ProcedureID,"
  1664. + "NodeNo,"
  1665. + "DefectID,"
  1666. + "JobsID,"
  1667. + "CreateUserID"
  1668. + ")"
  1669. + " VALUES("
  1670. + ":productionLineID,"
  1671. + ":procedureID,"
  1672. + ":nodeNo,"
  1673. + ":DefectID,"
  1674. + ":jobsID,"
  1675. + ":createUserID"
  1676. + ")";
  1677. paras = new OracleParameter[]
  1678. {
  1679. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1680. new OracleParameter(":procedureID",procedure.ProcedureID),
  1681. new OracleParameter(":nodeNo",procedure.NodeNo),
  1682. new OracleParameter(":DefectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1683. new OracleParameter(":jobsID",OracleDbType.Int32,row["jobsID"],ParameterDirection.Input),
  1684. new OracleParameter(":createUserID",sUserInfo.UserID),
  1685. };
  1686. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1687. }
  1688. #endregion
  1689. #region 插入生产工序对应窑炉
  1690. foreach (DataRow row in procedure.ProcedureKilnTable.Rows)
  1691. {
  1692. sqlText = "INSERT INTO tp_pc_procedurekiln ("
  1693. + "ProductionLineID,"
  1694. + "ProcedureID,"
  1695. + "NodeNo,"
  1696. + "KilnID,"
  1697. + "CreateUserID"
  1698. + ")"
  1699. + " VALUES("
  1700. + ":productionLineID,"
  1701. + ":procedureID,"
  1702. + ":nodeNo,"
  1703. + ":kilnID,"
  1704. + ":createUserID"
  1705. + ")";
  1706. paras = new OracleParameter[]
  1707. {
  1708. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1709. new OracleParameter(":procedureID",procedure.ProcedureID),
  1710. new OracleParameter(":nodeNo",procedure.NodeNo),
  1711. new OracleParameter(":kilnID",OracleDbType.Int32,row["kilnID"],ParameterDirection.Input),
  1712. new OracleParameter(":createUserID",sUserInfo.UserID),
  1713. };
  1714. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1715. }
  1716. #endregion
  1717. #region 插入生产工序对应半检产品等级 xuwei add 2019-12-12
  1718. if (!string.IsNullOrEmpty(procedure.SemiGoodsLevel))
  1719. {
  1720. string[] ids = procedure.SemiGoodsLevel.Split(',');
  1721. string sqlStr = @"
  1722. BEGIN
  1723. ";
  1724. for (int i = 0; i < ids.Length; i++)
  1725. {
  1726. sqlStr += $@"
  1727. INSERT INTO TP_PC_PROCEDUREGOODSLEVEL
  1728. ( PRODUCTIONLINEID, PROCEDUREID, GOODSLEVELTYPEID)
  1729. VALUES
  1730. (:PRODUCTIONLINEID, :PROCEDUREID, {ids[i]});
  1731. ";
  1732. }
  1733. sqlStr += "END;";
  1734. oracleTrConn.ExecuteNonQuery(
  1735. sqlStr,
  1736. new OracleParameter[]
  1737. {
  1738. new OracleParameter(":PRODUCTIONLINEID",procedure.ProductionLineID),
  1739. new OracleParameter(":PROCEDUREID",procedure.ProcedureID)
  1740. }
  1741. );
  1742. }
  1743. #endregion
  1744. oracleTrConn.Commit();
  1745. }
  1746. catch (Exception ex)
  1747. {
  1748. oracleTrConn.Rollback();
  1749. throw ex;
  1750. }
  1751. finally
  1752. {
  1753. // 释放资源
  1754. if (oracleTrConn.ConnState == System.Data.ConnectionState.Open)
  1755. {
  1756. oracleTrConn.Disconnect();
  1757. }
  1758. }
  1759. return returnRows;
  1760. }
  1761. /// <summary>
  1762. /// 注浆变更
  1763. /// </summary>
  1764. /// <param name="user">登录用户信息</param>
  1765. /// <param name="barcode">原条码</param>
  1766. /// <param name="newBarcode">新条码</param>
  1767. /// <param name="remarks">备注</param>
  1768. /// <returns>操作结果</returns>
  1769. public static ServiceResultEntity SetFPM2105Data(SUserInfo user, int? groutingLineID, int? groutingDailyID, string groutingDailyDetailIDs, DateTime groutingDate, string groutingUserCode, int? goodsID)
  1770. {
  1771. IDBTransaction tran = null;
  1772. try
  1773. {
  1774. ServiceResultEntity sre = new ServiceResultEntity();
  1775. tran = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  1776. OracleParameter[] paras = new OracleParameter[]
  1777. {
  1778. new OracleParameter("in_AccountID", OracleDbType.Int32, user.AccountID, ParameterDirection.Input),
  1779. new OracleParameter("in_UserID", OracleDbType.Int32, user.UserID, ParameterDirection.Input),
  1780. new OracleParameter("in_GroutingLineID", OracleDbType.Int32, groutingLineID, ParameterDirection.Input),
  1781. new OracleParameter("in_GroutingDailyID", OracleDbType.Int32, groutingDailyID, ParameterDirection.Input),
  1782. new OracleParameter("in_GroutingDailyDetailIDs", OracleDbType.Varchar2,groutingDailyDetailIDs, ParameterDirection.Input),
  1783. new OracleParameter("in_GroutingDate", OracleDbType.Date, groutingDate, ParameterDirection.Input),
  1784. new OracleParameter("in_GroutingUserCode", OracleDbType.Varchar2, groutingUserCode, ParameterDirection.Input),
  1785. new OracleParameter("in_GoodsID", OracleDbType.Int32, goodsID, ParameterDirection.Input),
  1786. new OracleParameter("out_Result", OracleDbType.Varchar2, 100, null, ParameterDirection.Output),
  1787. new OracleParameter("out_Message", OracleDbType.Varchar2, 100, null, ParameterDirection.Output),
  1788. };
  1789. DataSet ds = tran.ExecStoredProcedure("PRO_PM_ReplacedGroutingInfo", paras);
  1790. string out_Result = paras[8].Value.ToString();
  1791. if (out_Result != "0")
  1792. {
  1793. sre.Status = Constant.ServiceResultStatus.Other;
  1794. switch (out_Result)
  1795. {
  1796. case "1.0":
  1797. sre.OtherStatus = 1;
  1798. sre.Message = "当前用户没有此成型线的操作权限";
  1799. break;
  1800. case "1.1":
  1801. sre.OtherStatus = 2;
  1802. sre.Message = "此注浆日报中的条码已交坯不能修改成型工号。";
  1803. break;
  1804. case "1.2":
  1805. sre.OtherStatus = 3;
  1806. sre.Message = "工号[" + groutingUserCode + "]不存在或不是生产工号";
  1807. break;
  1808. case "1.3":
  1809. sre.OtherStatus = 7;
  1810. sre.Message = "工号[" + groutingUserCode + "]在" + groutingDate.Date + "没有班次配置。";
  1811. break;
  1812. case "2.1":
  1813. sre.OtherStatus = 4;
  1814. sre.Message = "此产品不存在。";
  1815. break;
  1816. default:
  1817. break;
  1818. }
  1819. }
  1820. tran.Commit();
  1821. return sre;
  1822. }
  1823. catch (Exception ex)
  1824. {
  1825. if (tran != null &&
  1826. tran.ConnState == ConnectionState.Open)
  1827. {
  1828. tran.Rollback();
  1829. }
  1830. throw ex;
  1831. }
  1832. finally
  1833. {
  1834. if (tran != null &&
  1835. tran.ConnState == ConnectionState.Open)
  1836. {
  1837. tran.Disconnect();
  1838. }
  1839. }
  1840. }
  1841. /// <summary>
  1842. /// 注浆变更
  1843. /// </summary>
  1844. /// <param name="user">登录用户信息</param>
  1845. /// <param name="barcode">原条码</param>
  1846. /// <param name="newBarcode">新条码</param>
  1847. /// <param name="remarks">备注</param>
  1848. /// <returns>操作结果</returns>
  1849. public static ServiceResultEntity SetFPM2105CancelBarCodeData(SUserInfo user, string BarCodes)
  1850. {
  1851. IDBTransaction tran = null;
  1852. try
  1853. {
  1854. ServiceResultEntity sre = new ServiceResultEntity();
  1855. tran = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  1856. string[] subBarCode = BarCodes.Split(',');
  1857. string sql = "";
  1858. string returnValue = "";
  1859. bool isError = false;
  1860. for (int i = 0; i < subBarCode.Length; i++)
  1861. {
  1862. if (subBarCode[i] != "")
  1863. {
  1864. //sql = "select DELIVERFLAG from TP_PM_GroutingDailyDetail where barcode='" + subBarCode[i] + "'";
  1865. sql = "select BEGINNINGFLAG from TP_PM_GroutingDailyDetail where barcode='" + subBarCode[i] + "'";
  1866. returnValue = tran.GetSqlResultToStr(sql);
  1867. if (returnValue == "1")
  1868. {
  1869. sre.Status = Constant.ServiceResultStatus.Other;
  1870. //sre.Message = "条码[" + subBarCode[i] + "]已经交坯,不能取消绑定";
  1871. sre.Message = "条码[" + subBarCode[i] + "]已经在产,不能取消绑定";
  1872. isError = true;
  1873. break;
  1874. }
  1875. sql = "update TP_PM_GroutingDailyDetail set barcode='' where barcode='" + subBarCode[i] + "'";
  1876. tran.ExecuteNonQuery(sql);
  1877. //sql = "delete from TP_PM_UsedBarCode where barcode='" + subBarCode[i] + "'";
  1878. sql = "update TP_PM_UsedBarCode set barcode='"+ subBarCode[i] + "@" + user.UserCode + "@"
  1879. + DateTime.Now.ToString("yyyyMMddHHmmss") + "' where barcode='" + subBarCode[i] + "'";
  1880. tran.ExecuteNonQuery(sql);
  1881. }
  1882. }
  1883. if (isError) //有错误
  1884. {
  1885. tran.Rollback();
  1886. }
  1887. else
  1888. {
  1889. tran.Commit();
  1890. }
  1891. return sre;
  1892. }
  1893. catch (Exception ex)
  1894. {
  1895. if (tran != null &&
  1896. tran.ConnState == ConnectionState.Open)
  1897. {
  1898. tran.Rollback();
  1899. }
  1900. throw ex;
  1901. }
  1902. finally
  1903. {
  1904. if (tran != null &&
  1905. tran.ConnState == ConnectionState.Open)
  1906. {
  1907. tran.Disconnect();
  1908. }
  1909. }
  1910. }
  1911. }
  1912. }