PCModuleLogicDAL.cs 116 KB

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