PCModuleLogicDAL.cs 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016
  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 更新工序半检信息 xuwei add 2019-12-11
  1096. if (!string.IsNullOrEmpty(procedure.SemiGoodsLevel))
  1097. {
  1098. string[] ids = procedure.SemiGoodsLevel.Split(',');
  1099. string sqlStr = @"
  1100. BEGIN
  1101. DELETE
  1102. TP_PC_PROCEDUREGOODSLEVEL
  1103. WHERE
  1104. PRODUCTIONLINEID = :PRODUCTIONLINEID
  1105. AND PROCEDUREID = :PROCEDUREID;
  1106. ";
  1107. for (int i = 0; i < ids.Length; i++)
  1108. {
  1109. sqlStr += $@"
  1110. INSERT INTO TP_PC_PROCEDUREGOODSLEVEL
  1111. ( PRODUCTIONLINEID, PROCEDUREID, GOODSLEVELTYPEID)
  1112. VALUES
  1113. (:PRODUCTIONLINEID, :PROCEDUREID, {ids[i]});
  1114. ";
  1115. }
  1116. sqlStr += "END;";
  1117. oracleTrConn.ExecuteNonQuery(
  1118. sqlStr,
  1119. new OracleParameter[]
  1120. {
  1121. new OracleParameter(":PRODUCTIONLINEID",productionLine.ProductionLineID),
  1122. new OracleParameter(":PROCEDUREID",procedure.ProcedureID)
  1123. }
  1124. );
  1125. }
  1126. #endregion
  1127. #region 编辑
  1128. sqlText = "UPDATE TP_PC_Procedure SET "
  1129. + " ProcedureName=:procedureName,"
  1130. + " ProcedureCode=:ProcedureCode,"
  1131. + " ModelType=:modelType,"
  1132. + " MustFlag=:mustFlag,"
  1133. + " CollectType=:collectType,"
  1134. + " OrganizationID=:organizationID,"
  1135. + " NodeType=:nodeType,"
  1136. + " PieceType=:pieceType,"
  1137. + " IsSpecialRework=:isSpecialRework,"
  1138. + " IsSemireWork=:isSemireWork,"
  1139. + " PrintType=:printType," //xuwei add 2019-11-20
  1140. + " NodeNo=:nodeNo,"
  1141. + " Remarks=:remarks,"
  1142. + " updateUserID=:updateUserID,"
  1143. + " UpdateTime=sysdate,"
  1144. + " misspriority=:misspriority,"
  1145. + " displayno=:displayno,"
  1146. + " UNDOFLAG=:UNDOFLAG,"
  1147. + " DeliverType=:DeliverType,"
  1148. + " BarCodePrintCopies=:BarCodePrintCopies,"
  1149. + " BarCodeFlag=:BarCodeFlag"
  1150. + " WHERE NodeNo=:nodeNo "
  1151. + " AND ProductionLineID=:productionLineID";
  1152. paras = new OracleParameter[]
  1153. {
  1154. new OracleParameter(":nodeNo",procedure.NodeNo),
  1155. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1156. new OracleParameter(":procedureName",procedure.ProcedureName),
  1157. new OracleParameter(":ProcedureCode",procedure.ProcedureCode),
  1158. new OracleParameter(":modelType",procedure.ModelType),
  1159. new OracleParameter(":mustFlag",procedure.MustFlag),
  1160. new OracleParameter(":collectType",procedure.CollectType),
  1161. new OracleParameter(":organizationID",procedure.OrganizationID),
  1162. new OracleParameter(":nodeType",procedure.NodeType),
  1163. new OracleParameter(":pieceType",procedure.PieceType),
  1164. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  1165. new OracleParameter(":isSemireWork",procedure.IsSemireWork),
  1166. new OracleParameter(":printType",procedure.PrintType),//xuwei add 2019-11-20
  1167. new OracleParameter(":nodeNo",procedure.NodeNo),
  1168. new OracleParameter(":remarks",procedure.Remarks),
  1169. new OracleParameter(":updateUserID",sUserInfo.UserID),
  1170. new OracleParameter(":misspriority",procedure.MissPriority),
  1171. new OracleParameter(":displayno",procedure.DisplayNo),
  1172. new OracleParameter(":UNDOFLAG",procedure.UnDo),
  1173. new OracleParameter(":DeliverType",procedure.DeliverType),
  1174. new OracleParameter(":BarCodePrintCopies",procedure.BarCodePrintCopies),
  1175. new OracleParameter(":BarCodeFlag",procedure.BarCodeFlag),
  1176. };
  1177. #endregion
  1178. }
  1179. foreach (OracleParameter item in paras)
  1180. {
  1181. if (item.Value + "" == "")
  1182. {
  1183. item.Value = System.DBNull.Value;
  1184. }
  1185. }
  1186. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1187. }
  1188. #endregion
  1189. #region 先删除生产工序流程明细 然后再插入
  1190. sqlText = "DELETE TP_PC_ProcedureFlow WHERE ProductionLineID=:productionLineID";
  1191. paras = new OracleParameter[]
  1192. {
  1193. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1194. };
  1195. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1196. #endregion
  1197. #region 删除对应产品 然后再插入
  1198. sqlText = "DELETE TP_PC_ProcedureGoods WHERE ProductionLineID=:productionLineID";
  1199. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1200. #endregion
  1201. #region 删除对应工号 然后再插入
  1202. sqlText = "DELETE TP_PC_ProcedureUser WHERE ProductionLineID=:productionLineID";
  1203. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1204. #endregion
  1205. #region 删除对应缺陷 然后再插入
  1206. sqlText = "DELETE TP_PC_ProcedureDefect WHERE ProductionLineID=:productionLineID";
  1207. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1208. #endregion
  1209. #region 删除缺陷对应工序工种表 然后再插入
  1210. sqlText = "DELETE TP_PC_DefectProcedureJobs WHERE ProductionLineID=:productionLineID";
  1211. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1212. #endregion
  1213. #region 删除对应窑炉 然后再插入
  1214. sqlText = "DELETE TP_PC_ProcedureKiln WHERE ProductionLineID=:productionLineID";
  1215. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1216. #endregion
  1217. }
  1218. #endregion
  1219. #region 插入生产工序属性等信息
  1220. foreach (ProcedureEntity procedure in productionLine.ProcedureList)
  1221. {
  1222. string sqlText;
  1223. OracleParameter[] paras;
  1224. #region 插入生产工序流程明细
  1225. if (procedure.ProcedureFlowDetailList != null)
  1226. {
  1227. foreach (ProcedureFlowEntity flowDetail in procedure.ProcedureFlowDetailList)
  1228. {
  1229. ProcedureEntity procedureWhere = productionLine.ProcedureList.Where(p => p.NodeNo == flowDetail.ArriveNodeNo).SingleOrDefault();
  1230. // 没有找到对应节点的ID
  1231. if (procedureWhere == null)
  1232. {
  1233. return Constant.INT_IS_ZERO;
  1234. }
  1235. else
  1236. {
  1237. flowDetail.ArriveProcedureID = procedureWhere.ProcedureID;
  1238. }
  1239. sqlText = "INSERT INTO TP_PC_ProcedureFlow ("
  1240. + "ProductionLineID,"
  1241. + "ProcedureID,"
  1242. + "NodeNo,"
  1243. + "FlowFlag,"
  1244. + "ArriveProcedureID,"
  1245. + "ArriveNodeNo"
  1246. + ")"
  1247. + " VALUES("
  1248. + ":productionLineID,"
  1249. + ":procedureID,"
  1250. + ":nodeNo,"
  1251. + ":flowFlag,"
  1252. + ":arriveProcedureID,"
  1253. + ":arriveNodeNo"
  1254. + ")";
  1255. paras = new OracleParameter[]
  1256. {
  1257. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1258. new OracleParameter(":procedureID",procedure.ProcedureID),
  1259. new OracleParameter(":nodeNo",procedure.NodeNo),
  1260. new OracleParameter(":flowFlag",flowDetail.FlowFlag),
  1261. new OracleParameter(":arriveProcedureID",flowDetail.ArriveProcedureID),
  1262. new OracleParameter(":arriveNodeNo",flowDetail.ArriveNodeNo),
  1263. };
  1264. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1265. }
  1266. }
  1267. #endregion
  1268. #region 插入生产工序对应产品表
  1269. foreach (DataRow row in procedure.ProcedureGoodsTable.Rows)
  1270. {
  1271. sqlText = "INSERT INTO TP_PC_ProcedureGoods ("
  1272. + "ProductionLineID,"
  1273. + "ProcedureID,"
  1274. + "NodeNo,"
  1275. + "GOODSID,"
  1276. + "CreateUserID"
  1277. + ")"
  1278. + " VALUES("
  1279. + ":productionLineID,"
  1280. + ":procedureID,"
  1281. + ":nodeNo,"
  1282. + ":goodsID,"
  1283. + ":createUserID"
  1284. + ")";
  1285. paras = new OracleParameter[]
  1286. {
  1287. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1288. new OracleParameter(":procedureID",procedure.ProcedureID),
  1289. new OracleParameter(":nodeNo",procedure.NodeNo),
  1290. new OracleParameter(":goodsID",OracleDbType.Int32,row["goodsID"],ParameterDirection.Input),
  1291. new OracleParameter(":createUserID",sUserInfo.UserID),
  1292. };
  1293. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1294. }
  1295. #endregion
  1296. #region 插入生产工序对应工号表
  1297. foreach (DataRow row in procedure.ProcedureUserTable.Rows)
  1298. {
  1299. sqlText = "INSERT INTO TP_PC_ProcedureUser ("
  1300. + "ProductionLineID,"
  1301. + "ProcedureID,"
  1302. + "NodeNo,"
  1303. + "UserID,"
  1304. + "CreateUserID"
  1305. + ")"
  1306. + " VALUES("
  1307. + ":productionLineID,"
  1308. + ":procedureID,"
  1309. + ":nodeNo,"
  1310. + ":userID,"
  1311. + ":createUserID"
  1312. + ")";
  1313. paras = new OracleParameter[]
  1314. {
  1315. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1316. new OracleParameter(":procedureID",procedure.ProcedureID),
  1317. new OracleParameter(":nodeNo",procedure.NodeNo),
  1318. new OracleParameter(":userID",OracleDbType.Int32,row["userID"],ParameterDirection.Input),
  1319. new OracleParameter(":createUserID",sUserInfo.UserID),
  1320. };
  1321. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1322. }
  1323. #endregion
  1324. #region 插入生产工序对应缺陷表
  1325. foreach (DataRow row in procedure.ProcedureDefectTable.Rows)
  1326. {
  1327. if (row["DefectID"] == DBNull.Value)
  1328. {
  1329. continue;
  1330. }
  1331. sqlText = "INSERT INTO TP_PC_ProcedureDefect ("
  1332. + "ProductionLineID,"
  1333. + "ProcedureID,"
  1334. + "NodeNo,"
  1335. + "DefectID,"
  1336. + "CreateUserID"
  1337. + ")"
  1338. + " VALUES("
  1339. + ":productionLineID,"
  1340. + ":procedureID,"
  1341. + ":nodeNo,"
  1342. + ":defectID,"
  1343. + ":createUserID"
  1344. + ")";
  1345. paras = new OracleParameter[]
  1346. {
  1347. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1348. new OracleParameter(":procedureID",procedure.ProcedureID),
  1349. new OracleParameter(":nodeNo",procedure.NodeNo),
  1350. new OracleParameter(":defectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1351. new OracleParameter(":createUserID",sUserInfo.UserID),
  1352. };
  1353. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1354. }
  1355. #endregion
  1356. #region 插入缺陷对应工序工种表
  1357. foreach (DataRow row in procedure.DefectProcedureJobsTable.Rows)
  1358. {
  1359. if (row["DefectID"] == DBNull.Value || row["jobsID"] == DBNull.Value)
  1360. {
  1361. continue;
  1362. }
  1363. sqlText = "INSERT INTO TP_PC_DefectProcedureJobs ("
  1364. + "ProductionLineID,"
  1365. + "ProcedureID,"
  1366. + "NodeNo,"
  1367. + "DefectID,"
  1368. + "JobsID,"
  1369. + "CreateUserID"
  1370. + ")"
  1371. + " VALUES("
  1372. + ":productionLineID,"
  1373. + ":procedureID,"
  1374. + ":nodeNo,"
  1375. + ":DefectID,"
  1376. + ":jobsID,"
  1377. + ":createUserID"
  1378. + ")";
  1379. paras = new OracleParameter[]
  1380. {
  1381. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1382. new OracleParameter(":procedureID",procedure.ProcedureID),
  1383. new OracleParameter(":nodeNo",procedure.NodeNo),
  1384. new OracleParameter(":DefectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1385. new OracleParameter(":jobsID",OracleDbType.Int32,row["jobsID"],ParameterDirection.Input),
  1386. new OracleParameter(":createUserID",sUserInfo.UserID),
  1387. };
  1388. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1389. }
  1390. #endregion
  1391. #region 插入生产工序对应窑炉
  1392. if (procedure.ProcedureKilnTable != null)
  1393. {
  1394. foreach (DataRow row in procedure.ProcedureKilnTable.Rows)
  1395. {
  1396. sqlText = "INSERT INTO tp_pc_procedurekiln ("
  1397. + "ProductionLineID,"
  1398. + "ProcedureID,"
  1399. + "NodeNo,"
  1400. + "KilnID,"
  1401. + "CreateUserID"
  1402. + ")"
  1403. + " VALUES("
  1404. + ":productionLineID,"
  1405. + ":procedureID,"
  1406. + ":nodeNo,"
  1407. + ":kilnID,"
  1408. + ":createUserID"
  1409. + ")";
  1410. paras = new OracleParameter[]
  1411. {
  1412. new OracleParameter(":productionLineID",productionLine.ProductionLineID),
  1413. new OracleParameter(":procedureID",procedure.ProcedureID),
  1414. new OracleParameter(":nodeNo",procedure.NodeNo),
  1415. new OracleParameter(":kilnID",OracleDbType.Int32,row["kilnID"],ParameterDirection.Input),
  1416. new OracleParameter(":createUserID",sUserInfo.UserID),
  1417. };
  1418. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1419. }
  1420. }
  1421. #endregion
  1422. }
  1423. #endregion
  1424. oracleTrConn.Commit();
  1425. }
  1426. catch (Exception ex)
  1427. {
  1428. oracleTrConn.Rollback();
  1429. throw ex;
  1430. }
  1431. finally
  1432. {
  1433. // 释放资源
  1434. if (oracleTrConn.ConnState == System.Data.ConnectionState.Open)
  1435. {
  1436. oracleTrConn.Disconnect();
  1437. }
  1438. }
  1439. return returnRows;
  1440. }
  1441. /// <summary>
  1442. /// 保存工序节点
  1443. /// </summary>
  1444. /// <param name="procedureEntity">工序实体</param>
  1445. /// <param name="sUserInfo">用户基本信息</param>
  1446. /// <returns></returns>
  1447. public static int SaveProcedureInfo(ProcedureEntity procedure, SUserInfo sUserInfo)
  1448. {
  1449. int returnRows = 0;
  1450. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  1451. try
  1452. {
  1453. #region 校验时间戳
  1454. // todo
  1455. string sql = "SELECT OPTimeStamp FROM TP_PC_Procedure"
  1456. + " WHERE ProcedureID = " + procedure.ProcedureID + " and OPTimeStamp = :OPTimeStamp and productionlineid=:productionlineid and nodeno=:nodeno";
  1457. OracleParameter[] parmetersSql = new OracleParameter[]
  1458. {
  1459. new OracleParameter(":OPTimeStamp", OracleDbType.TimeStamp, procedure.OPTimeStamp, ParameterDirection.Input),
  1460. new OracleParameter(":productionlineid", OracleDbType.Int32, procedure.ProductionLineID, ParameterDirection.Input),
  1461. new OracleParameter(":nodeno", OracleDbType.Int32, procedure.NodeNo, ParameterDirection.Input),
  1462. };
  1463. DataSet returnDataset = oracleTrConn.GetSqlResultToDs(sql, parmetersSql);
  1464. if (returnDataset != null && returnDataset.Tables[0].Rows.Count == 0)
  1465. {
  1466. oracleTrConn.Commit();
  1467. oracleTrConn.Disconnect();
  1468. return Constant.RETURN_IS_DATACHANGED;
  1469. }
  1470. #endregion
  1471. string sqlText = "";
  1472. #region 更新工序半检信息 xuwei add 2019-12-11
  1473. if (!string.IsNullOrEmpty(procedure.SemiGoodsLevel))
  1474. {
  1475. string[] ids = procedure.SemiGoodsLevel.Split(',');
  1476. string sqlStr = @"
  1477. BEGIN
  1478. DELETE
  1479. TP_PC_PROCEDUREGOODSLEVEL
  1480. WHERE
  1481. PRODUCTIONLINEID = :PRODUCTIONLINEID
  1482. AND PROCEDUREID = :PROCEDUREID;
  1483. ";
  1484. for (int i = 0; i < ids.Length; i++)
  1485. {
  1486. sqlStr += $@"
  1487. INSERT INTO TP_PC_PROCEDUREGOODSLEVEL
  1488. ( PRODUCTIONLINEID, PROCEDUREID, GOODSLEVELTYPEID)
  1489. VALUES
  1490. (:PRODUCTIONLINEID, :PROCEDUREID, {ids[i]});
  1491. ";
  1492. }
  1493. sqlStr += "END;";
  1494. oracleTrConn.ExecuteNonQuery(
  1495. sqlStr,
  1496. new OracleParameter[]
  1497. {
  1498. new OracleParameter(":PRODUCTIONLINEID",procedure.ProductionLineID),
  1499. new OracleParameter(":PROCEDUREID",procedure.ProcedureID)
  1500. }
  1501. );
  1502. }
  1503. #endregion
  1504. #region 更新工序信息
  1505. sqlText = "UPDATE TP_PC_Procedure SET "
  1506. + " ProcedureName=:procedureName,"
  1507. + " ProcedureCode=:ProcedureCode,"
  1508. + " CollectType=:collectType,"
  1509. + " OrganizationID=:organizationID,"
  1510. + " NodeType=:nodeType,"
  1511. + " PieceType=:pieceType,"
  1512. + " IsSpecialRework=:isSpecialRework,"
  1513. + " IsSemireWork=:isSemireWork," //xuwei add 2019-10-14
  1514. + " PrintType=:printType," //xuwei add 2019-11-20
  1515. + " NodeNo=:nodeNo,"
  1516. + " Remarks=:remarks,"
  1517. + " updateUserID=:updateUserID,"
  1518. + " UpdateTime=sysdate,"
  1519. + " misspriority=:misspriority,"
  1520. + " displayno=:displayno,"
  1521. + " UNDOFLAG=:UNDOFLAG,"
  1522. + " DeliverType=:DeliverType,"
  1523. + " MustFlag=:mustFlag,"
  1524. + " BarCodePrintCopies=:BarCodePrintCopies,"
  1525. + " BarCodeFlag=:BarCodeFlag"
  1526. + " WHERE NodeNo=:nodeNo "
  1527. + " AND ProductionLineID=:productionLineID";
  1528. OracleParameter[] paras = new OracleParameter[]
  1529. {
  1530. new OracleParameter(":nodeNo",procedure.NodeNo),
  1531. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1532. new OracleParameter(":procedureName",procedure.ProcedureName),
  1533. new OracleParameter(":ProcedureCode",procedure.ProcedureCode),
  1534. new OracleParameter(":collectType",procedure.CollectType),
  1535. new OracleParameter(":organizationID",procedure.OrganizationID),
  1536. new OracleParameter(":nodeType",procedure.NodeType),
  1537. new OracleParameter(":pieceType",procedure.PieceType),
  1538. new OracleParameter(":isSpecialRework",procedure.IsSpecialRework),
  1539. new OracleParameter(":isSemireWork",procedure.IsSemireWork),//xuwei add 2019-10-14
  1540. new OracleParameter(":printType",procedure.PrintType),//xuwei add 2019-11-20
  1541. new OracleParameter(":nodeNo",procedure.NodeNo),
  1542. new OracleParameter(":remarks",procedure.Remarks),
  1543. new OracleParameter(":updateUserID",sUserInfo.UserID),
  1544. new OracleParameter(":misspriority",procedure.MissPriority),
  1545. new OracleParameter(":displayno",procedure.DisplayNo),
  1546. new OracleParameter(":UNDOFLAG",procedure.UnDo),
  1547. new OracleParameter(":DeliverType",procedure.DeliverType),
  1548. new OracleParameter(":mustFlag",procedure.MustFlag),
  1549. new OracleParameter(":BarCodePrintCopies",procedure.BarCodePrintCopies),
  1550. new OracleParameter(":BarCodeFlag",procedure.BarCodeFlag),
  1551. };
  1552. foreach (OracleParameter item in paras)
  1553. {
  1554. if (item.Value + "" == "")
  1555. {
  1556. item.Value = System.DBNull.Value;
  1557. }
  1558. }
  1559. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1560. #endregion
  1561. paras = new OracleParameter[]
  1562. {
  1563. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1564. new OracleParameter(":nodeno",procedure.NodeNo),
  1565. new OracleParameter(":procedureid",procedure.ProcedureID),
  1566. };
  1567. #region 删除对应产品 然后再插入
  1568. sqlText = "DELETE TP_PC_ProcedureGoods WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1569. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1570. #endregion
  1571. #region 删除对应工号 然后再插入
  1572. sqlText = "DELETE TP_PC_ProcedureUser WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1573. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1574. #endregion
  1575. #region 删除对应缺陷 然后再插入
  1576. sqlText = "DELETE TP_PC_ProcedureDefect WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1577. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1578. #endregion
  1579. #region 删除缺陷对应工序工种表 然后再插入
  1580. sqlText = "DELETE TP_PC_DefectProcedureJobs WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1581. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1582. #endregion
  1583. #region 删除对应窑炉 然后再插入
  1584. sqlText = "DELETE TP_PC_ProcedureKiln WHERE ProductionLineID=:productionLineID and NodeNo=:nodeno and ProcedureID=:procedureid";
  1585. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1586. #endregion
  1587. #region 插入生产工序对应产品表
  1588. foreach (DataRow row in procedure.ProcedureGoodsTable.Rows)
  1589. {
  1590. sqlText = "INSERT INTO TP_PC_ProcedureGoods ("
  1591. + "ProductionLineID,"
  1592. + "ProcedureID,"
  1593. + "NodeNo,"
  1594. + "GOODSID,"
  1595. + "CreateUserID"
  1596. + ")"
  1597. + " VALUES("
  1598. + ":productionLineID,"
  1599. + ":procedureID,"
  1600. + ":nodeNo,"
  1601. + ":goodsID,"
  1602. + ":createUserID"
  1603. + ")";
  1604. paras = new OracleParameter[]
  1605. {
  1606. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1607. new OracleParameter(":procedureID",procedure.ProcedureID),
  1608. new OracleParameter(":nodeNo",procedure.NodeNo),
  1609. new OracleParameter(":goodsID",OracleDbType.Int32,row["goodsID"],ParameterDirection.Input),
  1610. new OracleParameter(":createUserID",sUserInfo.UserID),
  1611. };
  1612. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1613. }
  1614. #endregion
  1615. #region 插入生产工序对应工号表
  1616. foreach (DataRow row in procedure.ProcedureUserTable.Rows)
  1617. {
  1618. sqlText = "INSERT INTO TP_PC_ProcedureUser ("
  1619. + "ProductionLineID,"
  1620. + "ProcedureID,"
  1621. + "NodeNo,"
  1622. + "UserID,"
  1623. + "CreateUserID"
  1624. + ")"
  1625. + " VALUES("
  1626. + ":productionLineID,"
  1627. + ":procedureID,"
  1628. + ":nodeNo,"
  1629. + ":userID,"
  1630. + ":createUserID"
  1631. + ")";
  1632. paras = new OracleParameter[]
  1633. {
  1634. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1635. new OracleParameter(":procedureID",procedure.ProcedureID),
  1636. new OracleParameter(":nodeNo",procedure.NodeNo),
  1637. new OracleParameter(":userID",OracleDbType.Int32,row["userID"],ParameterDirection.Input),
  1638. new OracleParameter(":createUserID",sUserInfo.UserID),
  1639. };
  1640. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1641. }
  1642. #endregion
  1643. #region 插入生产工序对应缺陷表
  1644. foreach (DataRow row in procedure.ProcedureDefectTable.Rows)
  1645. {
  1646. if (row["DefectID"] == DBNull.Value)
  1647. {
  1648. continue;
  1649. }
  1650. sqlText = "INSERT INTO TP_PC_ProcedureDefect ("
  1651. + "ProductionLineID,"
  1652. + "ProcedureID,"
  1653. + "NodeNo,"
  1654. + "DefectID,"
  1655. + "CreateUserID"
  1656. + ")"
  1657. + " VALUES("
  1658. + ":productionLineID,"
  1659. + ":procedureID,"
  1660. + ":nodeNo,"
  1661. + ":defectID,"
  1662. + ":createUserID"
  1663. + ")";
  1664. paras = new OracleParameter[]
  1665. {
  1666. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1667. new OracleParameter(":procedureID",procedure.ProcedureID),
  1668. new OracleParameter(":nodeNo",procedure.NodeNo),
  1669. new OracleParameter(":defectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1670. new OracleParameter(":createUserID",sUserInfo.UserID),
  1671. };
  1672. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1673. }
  1674. #endregion
  1675. #region 插入缺陷对应工序工种表
  1676. foreach (DataRow row in procedure.DefectProcedureJobsTable.Rows)
  1677. {
  1678. if (row["DefectID"] == DBNull.Value || row["jobsID"] == DBNull.Value)
  1679. {
  1680. continue;
  1681. }
  1682. sqlText = "INSERT INTO TP_PC_DefectProcedureJobs ("
  1683. + "ProductionLineID,"
  1684. + "ProcedureID,"
  1685. + "NodeNo,"
  1686. + "DefectID,"
  1687. + "JobsID,"
  1688. + "CreateUserID"
  1689. + ")"
  1690. + " VALUES("
  1691. + ":productionLineID,"
  1692. + ":procedureID,"
  1693. + ":nodeNo,"
  1694. + ":DefectID,"
  1695. + ":jobsID,"
  1696. + ":createUserID"
  1697. + ")";
  1698. paras = new OracleParameter[]
  1699. {
  1700. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1701. new OracleParameter(":procedureID",procedure.ProcedureID),
  1702. new OracleParameter(":nodeNo",procedure.NodeNo),
  1703. new OracleParameter(":DefectID",OracleDbType.Int32,row["DefectID"],ParameterDirection.Input),
  1704. new OracleParameter(":jobsID",OracleDbType.Int32,row["jobsID"],ParameterDirection.Input),
  1705. new OracleParameter(":createUserID",sUserInfo.UserID),
  1706. };
  1707. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1708. }
  1709. #endregion
  1710. #region 插入生产工序对应窑炉
  1711. foreach (DataRow row in procedure.ProcedureKilnTable.Rows)
  1712. {
  1713. sqlText = "INSERT INTO tp_pc_procedurekiln ("
  1714. + "ProductionLineID,"
  1715. + "ProcedureID,"
  1716. + "NodeNo,"
  1717. + "KilnID,"
  1718. + "CreateUserID"
  1719. + ")"
  1720. + " VALUES("
  1721. + ":productionLineID,"
  1722. + ":procedureID,"
  1723. + ":nodeNo,"
  1724. + ":kilnID,"
  1725. + ":createUserID"
  1726. + ")";
  1727. paras = new OracleParameter[]
  1728. {
  1729. new OracleParameter(":productionLineID",procedure.ProductionLineID),
  1730. new OracleParameter(":procedureID",procedure.ProcedureID),
  1731. new OracleParameter(":nodeNo",procedure.NodeNo),
  1732. new OracleParameter(":kilnID",OracleDbType.Int32,row["kilnID"],ParameterDirection.Input),
  1733. new OracleParameter(":createUserID",sUserInfo.UserID),
  1734. };
  1735. returnRows += oracleTrConn.ExecuteNonQuery(sqlText, paras);
  1736. }
  1737. #endregion
  1738. oracleTrConn.Commit();
  1739. }
  1740. catch (Exception ex)
  1741. {
  1742. oracleTrConn.Rollback();
  1743. throw ex;
  1744. }
  1745. finally
  1746. {
  1747. // 释放资源
  1748. if (oracleTrConn.ConnState == System.Data.ConnectionState.Open)
  1749. {
  1750. oracleTrConn.Disconnect();
  1751. }
  1752. }
  1753. return returnRows;
  1754. }
  1755. /// <summary>
  1756. /// 注浆变更
  1757. /// </summary>
  1758. /// <param name="user">登录用户信息</param>
  1759. /// <param name="barcode">原条码</param>
  1760. /// <param name="newBarcode">新条码</param>
  1761. /// <param name="remarks">备注</param>
  1762. /// <returns>操作结果</returns>
  1763. public static ServiceResultEntity SetFPM2105Data(SUserInfo user, int? groutingLineID, int? groutingDailyID, string groutingDailyDetailIDs, DateTime groutingDate, string groutingUserCode, int? goodsID)
  1764. {
  1765. IDBTransaction tran = null;
  1766. try
  1767. {
  1768. ServiceResultEntity sre = new ServiceResultEntity();
  1769. tran = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  1770. OracleParameter[] paras = new OracleParameter[]
  1771. {
  1772. new OracleParameter("in_AccountID", OracleDbType.Int32, user.AccountID, ParameterDirection.Input),
  1773. new OracleParameter("in_UserID", OracleDbType.Int32, user.UserID, ParameterDirection.Input),
  1774. new OracleParameter("in_GroutingLineID", OracleDbType.Int32, groutingLineID, ParameterDirection.Input),
  1775. new OracleParameter("in_GroutingDailyID", OracleDbType.Int32, groutingDailyID, ParameterDirection.Input),
  1776. new OracleParameter("in_GroutingDailyDetailIDs", OracleDbType.Varchar2,groutingDailyDetailIDs, ParameterDirection.Input),
  1777. new OracleParameter("in_GroutingDate", OracleDbType.Date, groutingDate, ParameterDirection.Input),
  1778. new OracleParameter("in_GroutingUserCode", OracleDbType.Varchar2, groutingUserCode, ParameterDirection.Input),
  1779. new OracleParameter("in_GoodsID", OracleDbType.Int32, goodsID, ParameterDirection.Input),
  1780. new OracleParameter("out_Result", OracleDbType.Varchar2, 100, null, ParameterDirection.Output),
  1781. new OracleParameter("out_Message", OracleDbType.Varchar2, 100, null, ParameterDirection.Output),
  1782. };
  1783. DataSet ds = tran.ExecStoredProcedure("PRO_PM_ReplacedGroutingInfo", paras);
  1784. string out_Result = paras[8].Value.ToString();
  1785. if (out_Result != "0")
  1786. {
  1787. sre.Status = Constant.ServiceResultStatus.Other;
  1788. switch (out_Result)
  1789. {
  1790. case "1.0":
  1791. sre.OtherStatus = 1;
  1792. sre.Message = "当前用户没有此成型线的操作权限";
  1793. break;
  1794. case "1.1":
  1795. sre.OtherStatus = 2;
  1796. sre.Message = "此注浆日报中的条码已交坯不能修改成型工号。";
  1797. break;
  1798. case "1.2":
  1799. sre.OtherStatus = 3;
  1800. sre.Message = "工号[" + groutingUserCode + "]不存在或不是生产工号";
  1801. break;
  1802. case "1.3":
  1803. sre.OtherStatus = 7;
  1804. sre.Message = "工号[" + groutingUserCode + "]在" + groutingDate.Date + "没有班次配置。";
  1805. break;
  1806. case "2.1":
  1807. sre.OtherStatus = 4;
  1808. sre.Message = "此产品不存在。";
  1809. break;
  1810. default:
  1811. break;
  1812. }
  1813. }
  1814. tran.Commit();
  1815. return sre;
  1816. }
  1817. catch (Exception ex)
  1818. {
  1819. if (tran != null &&
  1820. tran.ConnState == ConnectionState.Open)
  1821. {
  1822. tran.Rollback();
  1823. }
  1824. throw ex;
  1825. }
  1826. finally
  1827. {
  1828. if (tran != null &&
  1829. tran.ConnState == ConnectionState.Open)
  1830. {
  1831. tran.Disconnect();
  1832. }
  1833. }
  1834. }
  1835. /// <summary>
  1836. /// 注浆变更
  1837. /// </summary>
  1838. /// <param name="user">登录用户信息</param>
  1839. /// <param name="barcode">原条码</param>
  1840. /// <param name="newBarcode">新条码</param>
  1841. /// <param name="remarks">备注</param>
  1842. /// <returns>操作结果</returns>
  1843. public static ServiceResultEntity SetFPM2105CancelBarCodeData(SUserInfo user, string BarCodes)
  1844. {
  1845. IDBTransaction tran = null;
  1846. try
  1847. {
  1848. ServiceResultEntity sre = new ServiceResultEntity();
  1849. tran = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  1850. string[] subBarCode = BarCodes.Split(',');
  1851. string sql = "";
  1852. string returnValue = "";
  1853. bool isError = false;
  1854. for (int i = 0; i < subBarCode.Length; i++)
  1855. {
  1856. if (subBarCode[i] != "")
  1857. {
  1858. sql = "select DELIVERFLAG from TP_PM_GroutingDailyDetail where barcode='" + subBarCode[i] + "'";
  1859. returnValue = tran.GetSqlResultToStr(sql);
  1860. if (returnValue == "1")
  1861. {
  1862. sre.Status = Constant.ServiceResultStatus.Other;
  1863. sre.Message = "条码[" + subBarCode[i] + "]已经交坯,不能取消绑定";
  1864. isError = true;
  1865. break;
  1866. }
  1867. sql = "update TP_PM_GroutingDailyDetail set barcode='' where barcode='" + subBarCode[i] + "'";
  1868. tran.ExecuteNonQuery(sql);
  1869. sql = "delete from TP_PM_UsedBarCode where barcode='" + subBarCode[i] + "'";
  1870. tran.ExecuteNonQuery(sql);
  1871. }
  1872. }
  1873. if (isError) //有错误
  1874. {
  1875. tran.Rollback();
  1876. }
  1877. else
  1878. {
  1879. tran.Commit();
  1880. }
  1881. return sre;
  1882. }
  1883. catch (Exception ex)
  1884. {
  1885. if (tran != null &&
  1886. tran.ConnState == ConnectionState.Open)
  1887. {
  1888. tran.Rollback();
  1889. }
  1890. throw ex;
  1891. }
  1892. finally
  1893. {
  1894. if (tran != null &&
  1895. tran.ConnState == ConnectionState.Open)
  1896. {
  1897. tran.Disconnect();
  1898. }
  1899. }
  1900. }
  1901. }
  1902. }