FormUtility.cs 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:FormUtility.cs
  5. * 2.功能描述:窗体共通类
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/9/2 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. using Dongke.IBOSS.PRD.Basics.BaseControls;
  17. using Dongke.IBOSS.PRD.Basics.BaseResources;
  18. using Dongke.IBOSS.PRD.Client.Controls.FormCommon;
  19. namespace Dongke.IBOSS.PRD.Client.Controls
  20. {
  21. /// <summary>
  22. /// 窗体共通类
  23. /// </summary>
  24. public class FormUtility
  25. {
  26. /// <summary>
  27. /// 获取产品信息后绑定数据源
  28. /// </summary>
  29. /// <param name="dataGridView">绑定的列表对象</param>
  30. /// <param name="rowIndex">行号</param>
  31. /// <param name="searchName">列名</param>
  32. /// <param name="codeValue">该列原来的值</param>
  33. public static DataTable BindGoodsRowDataSource(C_DataGridView dataGridView, int rowIndex,
  34. string searchName, string codeValue)
  35. {
  36. try
  37. {
  38. DataTable returnTable = new DataTable("dataTable");
  39. F_SelectGoods frmSelectGoods = new F_SelectGoods();
  40. frmSelectGoods.SetGoodsCode = codeValue;
  41. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  42. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  43. if ("GoodsCode".Equals(searchName))
  44. {
  45. frmSelectGoods.SetGoodsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  46. }
  47. else
  48. {
  49. return null;
  50. }
  51. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  52. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  53. {
  54. if (!string.IsNullOrEmpty(codeValue))
  55. {
  56. rowItem.Cells[searchName].Value = codeValue;
  57. }
  58. return null;
  59. }
  60. // 防止2次关闭才能关掉
  61. if (codeValue == rowItem.Cells[searchName].Value + "")
  62. {
  63. return null;
  64. }
  65. DialogResult dialogResult = frmSelectGoods.ShowDialog();
  66. // 只有点确定时才进行下面的操作
  67. if (dialogResult.Equals(DialogResult.OK))
  68. {
  69. DataTable selDt = frmSelectGoods.SelTable;
  70. if (selDt == null)
  71. {
  72. return null;
  73. }
  74. if ((DataTable)dataGridView.DataSource == null)
  75. {
  76. return null;
  77. }
  78. // 如果是进行修改的,需要清除当前行信息
  79. if (dataGridView.Rows.Count > rowItem.Index)
  80. {
  81. dataGridView.Rows.RemoveAt(rowIndex);
  82. }
  83. returnTable = selDt.Copy();
  84. if (selDt != null && selDt.Rows.Count != 0)
  85. {
  86. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  87. // 除去新行
  88. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  89. {
  90. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  91. {
  92. continue;
  93. }
  94. if (string.IsNullOrEmpty(dgvTable.Rows[i]["GoodsID"] + ""))
  95. {
  96. dgvTable.Rows.RemoveAt(i);
  97. }
  98. }
  99. bool isContinue = true;
  100. for (int i = 0; i < selDt.Rows.Count; i++)
  101. {
  102. isContinue = true;
  103. if (dgvTable != null)
  104. {
  105. for (int j = 0; j < dgvTable.Rows.Count; j++)
  106. {
  107. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  108. && selDt.Rows[i].RowState != DataRowState.Deleted
  109. && (Convert.ToInt32(selDt.Rows[i]["GoodsID"])
  110. == Convert.ToInt32(dgvTable.Rows[j]["GoodsID"])))
  111. {
  112. isContinue = false;
  113. break;
  114. }
  115. }
  116. }
  117. if (isContinue)
  118. {
  119. DataRow newRow = dgvTable.NewRow();
  120. foreach (DataColumn column in selDt.Columns)
  121. {
  122. if (dgvTable.Columns.Contains(column.ColumnName)
  123. && selDt.Columns.Contains(column.ColumnName)
  124. && !"Sel".Equals(column.ColumnName))
  125. {
  126. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  127. }
  128. }
  129. // 是否有选择
  130. if (dgvTable.Columns.Contains("Sel"))
  131. {
  132. newRow["Sel"] = 0;
  133. }
  134. foreach (DataColumn col in dgvTable.Columns)
  135. {
  136. col.AllowDBNull = true;
  137. }
  138. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  139. }
  140. }
  141. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  142. dataGridView.ProcessRightKey(Keys.Enter);
  143. }
  144. }
  145. else
  146. {
  147. rowItem.Cells[searchName].Value = codeValue;
  148. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  149. if (string.IsNullOrEmpty(codeValue))
  150. {
  151. dataGridView.Rows.RemoveAt(rowItem.Index);
  152. }
  153. // 除去新行
  154. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  155. {
  156. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  157. {
  158. continue;
  159. }
  160. if (string.IsNullOrEmpty(tmpTable.Rows[i]["GoodsID"] + ""))
  161. {
  162. tmpTable.Rows.RemoveAt(i);
  163. }
  164. }
  165. }
  166. return returnTable;
  167. }
  168. catch (Exception ex)
  169. {
  170. throw ex;
  171. }
  172. }
  173. /// <summary>
  174. /// 获取员工信息后绑定数据源
  175. /// </summary>
  176. /// <param name="dataGridView">绑定的列表对象</param>
  177. /// <param name="rowIndex">行号</param>
  178. /// <param name="searchName">列名</param>
  179. /// <param name="codeValue">该列原来的值</param>
  180. /// <param name="codeValue">工号</param>
  181. public static DataTable BindStaffRowDataSource(C_DataGridView dataGridView, int rowIndex,
  182. string searchName, string codeValue, int userId, bool isSelectOne)
  183. {
  184. try
  185. {
  186. DataTable returnTable = new DataTable("dataTable");
  187. S_CMN_010 frmCMN010 = new S_CMN_010();
  188. frmCMN010.UserId = userId;
  189. frmCMN010.IsSelectOne = isSelectOne;
  190. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  191. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  192. if ("StaffCode".Equals(searchName))
  193. {
  194. frmCMN010.StaffCode1 = rowItem.Cells[searchName].EditedFormattedValue + "";
  195. }
  196. else
  197. {
  198. return null;
  199. }
  200. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  201. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  202. {
  203. if (!string.IsNullOrEmpty(codeValue))
  204. {
  205. rowItem.Cells[searchName].Value = codeValue;
  206. }
  207. return null;
  208. }
  209. // 防止2次关闭才能关掉
  210. if (codeValue == rowItem.Cells[searchName].Value + "")
  211. {
  212. return null;
  213. }
  214. DialogResult dialogResult = frmCMN010.ShowDialog();
  215. // 只有点确定时才进行下面的操作
  216. if (dialogResult.Equals(DialogResult.OK))
  217. {
  218. DataTable selDt = frmCMN010.SelTable;
  219. if (selDt == null)
  220. {
  221. return null;
  222. }
  223. if ((DataTable)dataGridView.DataSource == null)
  224. {
  225. return null;
  226. }
  227. //临时待修改
  228. if (isSelectOne == true)
  229. {
  230. dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = selDt.Rows[0]["StaffCode"].ToString();
  231. dataGridView.Rows[rowIndex].Cells["StaffName"].Value = selDt.Rows[0]["StaffName"].ToString();
  232. dataGridView.Rows[rowIndex].Cells["StaffId"].Value = selDt.Rows[0]["StaffId"].ToString();
  233. dataGridView.Rows[rowIndex].Cells["JobsName"].Value = selDt.Rows[0]["JobsName"].ToString();
  234. if (dataGridView.Columns["Jobs"] != null)
  235. {
  236. dataGridView.Rows[rowIndex].Cells["Jobs"].Value = selDt.Rows[0]["Jobs"].ToString();
  237. }
  238. if (dataGridView.Columns["StaffStatus"] != null)
  239. {
  240. dataGridView.Rows[rowIndex].Cells["StaffStatus"].Value = selDt.Rows[0]["StaffStatus"].ToString();
  241. }
  242. if (dataGridView.Columns["StaffStatusName"] != null)
  243. {
  244. dataGridView.Rows[rowIndex].Cells["StaffStatusName"].Value = selDt.Rows[0]["StaffStatusName"].ToString();
  245. }
  246. if (dataGridView.Columns["OrganizationName"] != null)
  247. {
  248. dataGridView.Rows[rowIndex].Cells["OrganizationName"].Value = selDt.Rows[0]["OrganizationName"].ToString();
  249. }
  250. return null;
  251. }
  252. // 如果是进行修改的,需要清除当前行信息
  253. if (dataGridView.Rows.Count > rowItem.Index)
  254. {
  255. dataGridView.Rows.RemoveAt(rowIndex);
  256. }
  257. returnTable = selDt.Copy();
  258. if (selDt != null && selDt.Rows.Count != 0)
  259. {
  260. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  261. // 除去新行
  262. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  263. {
  264. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  265. {
  266. continue;
  267. }
  268. if (string.IsNullOrEmpty(dgvTable.Rows[i]["Staffid"] + ""))
  269. {
  270. dgvTable.Rows.RemoveAt(i);
  271. }
  272. }
  273. bool isContinue = true;
  274. for (int i = 0; i < selDt.Rows.Count; i++)
  275. {
  276. isContinue = true;
  277. if (dgvTable != null)
  278. {
  279. for (int j = 0; j < dgvTable.Rows.Count; j++)
  280. {
  281. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  282. && selDt.Rows[i].RowState != DataRowState.Deleted
  283. && (Convert.ToInt32(selDt.Rows[i]["Staffid"])
  284. == Convert.ToInt32(dgvTable.Rows[j]["Staffid"])))
  285. {
  286. isContinue = false;
  287. break;
  288. }
  289. }
  290. }
  291. if (isContinue)
  292. {
  293. DataRow newRow = dgvTable.NewRow();
  294. foreach (DataColumn column in selDt.Columns)
  295. {
  296. if (dgvTable.Columns.Contains(column.ColumnName)
  297. && selDt.Columns.Contains(column.ColumnName)
  298. && !"Sel".Equals(column.ColumnName))
  299. {
  300. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  301. }
  302. }
  303. // 是否有选择
  304. if (dgvTable.Columns.Contains("Sel"))
  305. {
  306. newRow["Sel"] = 0;
  307. }
  308. foreach (DataColumn col in dgvTable.Columns)
  309. {
  310. col.AllowDBNull = true;
  311. }
  312. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  313. }
  314. }
  315. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  316. dataGridView.ProcessRightKey(Keys.Enter);
  317. }
  318. }
  319. else
  320. {
  321. //临时待修改
  322. if (isSelectOne == true)
  323. {
  324. dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = "";
  325. return null;
  326. }
  327. rowItem.Cells[searchName].Value = codeValue;
  328. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  329. if (string.IsNullOrEmpty(codeValue))
  330. {
  331. dataGridView.Rows.RemoveAt(rowItem.Index);
  332. }
  333. // 除去新行
  334. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  335. {
  336. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  337. {
  338. continue;
  339. }
  340. if (string.IsNullOrEmpty(tmpTable.Rows[i]["Staffid"] + ""))
  341. {
  342. tmpTable.Rows.RemoveAt(i);
  343. }
  344. }
  345. }
  346. return returnTable;
  347. }
  348. catch (Exception ex)
  349. {
  350. throw ex;
  351. }
  352. }
  353. /// <summary>
  354. /// 获取员工信息后绑定数据源
  355. /// </summary>
  356. /// <param name="dataGridView">绑定的列表对象</param>
  357. /// <param name="rowIndex">行号</param>
  358. /// <param name="searchName">列名</param>
  359. /// <param name="codeValue">该列原来的值</param>
  360. /// <param name="codeValue">工号</param>
  361. public static DataTable BindClassStaffRowDataSource(C_DataGridView dataGridView, int rowIndex,
  362. string searchName, string codeValue, int userId, bool isSelectOne)
  363. {
  364. try
  365. {
  366. DataTable returnTable = new DataTable("dataTable");
  367. S_CMN_010 frmCMN010 = new S_CMN_010();
  368. frmCMN010.UserId = userId;
  369. frmCMN010.IsSelectOne = isSelectOne;
  370. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  371. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  372. if ("StaffCode".Equals(searchName))
  373. {
  374. frmCMN010.StaffCode1 = rowItem.Cells[searchName].EditedFormattedValue + "";
  375. }
  376. else
  377. {
  378. return null;
  379. }
  380. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  381. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  382. {
  383. if (!string.IsNullOrEmpty(codeValue))
  384. {
  385. rowItem.Cells[searchName].Value = codeValue;
  386. }
  387. return null;
  388. }
  389. // 防止2次关闭才能关掉
  390. if (codeValue == rowItem.Cells[searchName].Value + "")
  391. {
  392. return null;
  393. }
  394. DialogResult dialogResult = frmCMN010.ShowDialog();
  395. // 只有点确定时才进行下面的操作
  396. if (dialogResult.Equals(DialogResult.OK))
  397. {
  398. DataTable selDt = frmCMN010.SelTable;
  399. if (selDt == null)
  400. {
  401. return null;
  402. }
  403. if ((DataTable)dataGridView.DataSource == null)
  404. {
  405. return null;
  406. }
  407. //临时待修改
  408. if (isSelectOne == true)
  409. {
  410. dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = selDt.Rows[0]["StaffCode"].ToString();
  411. dataGridView.Rows[rowIndex].Cells["StaffName"].Value = selDt.Rows[0]["StaffName"].ToString();
  412. dataGridView.Rows[rowIndex].Cells["StaffId"].Value = selDt.Rows[0]["StaffId"].ToString();
  413. dataGridView.Rows[rowIndex].Cells["SJobsName"].Value = selDt.Rows[0]["JobsName"].ToString();
  414. if (dataGridView.Columns["Jobs"] != null)
  415. {
  416. dataGridView.Rows[rowIndex].Cells["Jobs"].Value = selDt.Rows[0]["Jobs"].ToString();
  417. }
  418. if (dataGridView.Columns["StaffStatus"] != null)
  419. {
  420. dataGridView.Rows[rowIndex].Cells["StaffStatus"].Value = selDt.Rows[0]["StaffStatus"].ToString();
  421. }
  422. if (dataGridView.Columns["StaffStatusName"] != null)
  423. {
  424. dataGridView.Rows[rowIndex].Cells["StaffStatusName"].Value = selDt.Rows[0]["StaffStatusName"].ToString();
  425. }
  426. if (dataGridView.Columns["OrganizationName"] != null)
  427. {
  428. dataGridView.Rows[rowIndex].Cells["OrganizationName"].Value = selDt.Rows[0]["OrganizationName"].ToString();
  429. }
  430. if (dataGridView.Columns["SOrganizationId"] != null)
  431. {
  432. dataGridView.Rows[rowIndex].Cells["SOrganizationId"].Value = selDt.Rows[0]["OrganizationID"].ToString();
  433. }
  434. return null;
  435. }
  436. // 如果是进行修改的,需要清除当前行信息
  437. if (dataGridView.Rows.Count > rowItem.Index)
  438. {
  439. dataGridView.Rows.RemoveAt(rowIndex);
  440. }
  441. returnTable = selDt.Copy();
  442. if (selDt != null && selDt.Rows.Count != 0)
  443. {
  444. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  445. // 除去新行
  446. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  447. {
  448. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  449. {
  450. continue;
  451. }
  452. if (string.IsNullOrEmpty(dgvTable.Rows[i]["Staffid"] + ""))
  453. {
  454. dgvTable.Rows.RemoveAt(i);
  455. }
  456. }
  457. bool isContinue = true;
  458. for (int i = 0; i < selDt.Rows.Count; i++)
  459. {
  460. isContinue = true;
  461. if (dgvTable != null)
  462. {
  463. for (int j = 0; j < dgvTable.Rows.Count; j++)
  464. {
  465. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  466. && selDt.Rows[i].RowState != DataRowState.Deleted
  467. && (Convert.ToInt32(selDt.Rows[i]["Staffid"])
  468. == Convert.ToInt32(dgvTable.Rows[j]["Staffid"])))
  469. {
  470. isContinue = false;
  471. break;
  472. }
  473. }
  474. }
  475. if (isContinue)
  476. {
  477. DataRow newRow = dgvTable.NewRow();
  478. foreach (DataColumn column in selDt.Columns)
  479. {
  480. if (dgvTable.Columns.Contains(column.ColumnName)
  481. && selDt.Columns.Contains(column.ColumnName)
  482. && !"Sel".Equals(column.ColumnName))
  483. {
  484. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  485. }
  486. }
  487. // 是否有选择
  488. if (dgvTable.Columns.Contains("Sel"))
  489. {
  490. newRow["Sel"] = 0;
  491. }
  492. foreach (DataColumn col in dgvTable.Columns)
  493. {
  494. col.AllowDBNull = true;
  495. }
  496. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  497. }
  498. }
  499. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  500. dataGridView.ProcessRightKey(Keys.Enter);
  501. }
  502. }
  503. else
  504. {
  505. //临时待修改
  506. if (isSelectOne == true)
  507. {
  508. dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = "";
  509. return null;
  510. }
  511. rowItem.Cells[searchName].Value = codeValue;
  512. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  513. if (string.IsNullOrEmpty(codeValue))
  514. {
  515. dataGridView.Rows.RemoveAt(rowItem.Index);
  516. }
  517. // 除去新行
  518. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  519. {
  520. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  521. {
  522. continue;
  523. }
  524. if (string.IsNullOrEmpty(tmpTable.Rows[i]["Staffid"] + ""))
  525. {
  526. tmpTable.Rows.RemoveAt(i);
  527. }
  528. }
  529. }
  530. return returnTable;
  531. }
  532. catch (Exception ex)
  533. {
  534. throw ex;
  535. }
  536. }
  537. /// <summary>
  538. /// 获取工号信息后绑定数据源
  539. /// </summary>
  540. /// <param name="dataGridView">绑定的列表对象</param>
  541. /// <param name="rowIndex">行号</param>
  542. /// <param name="searchName">列名</param>
  543. /// <param name="codeValue">该列原来的值</param>
  544. public static DataTable BindUserRowDataSource(C_DataGridView dataGridView, int rowIndex,
  545. string searchName, string codeValue)
  546. {
  547. try
  548. {
  549. DataTable returnTable = new DataTable("dataTable");
  550. S_CMN_013 frmSCMN013 = new S_CMN_013();
  551. frmSCMN013.SetUserCode = codeValue;
  552. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  553. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  554. if ("UserCode".Equals(searchName))
  555. {
  556. frmSCMN013.SetUserCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  557. }
  558. else
  559. {
  560. return null;
  561. }
  562. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  563. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  564. {
  565. if (!string.IsNullOrEmpty(codeValue))
  566. {
  567. rowItem.Cells[searchName].Value = codeValue;
  568. }
  569. return null;
  570. }
  571. // 防止2次关闭才能关掉
  572. if (codeValue == rowItem.Cells[searchName].Value + "")
  573. {
  574. return null;
  575. }
  576. DialogResult dialogResult = frmSCMN013.ShowDialog();
  577. // 只有点确定时才进行下面的操作
  578. if (dialogResult.Equals(DialogResult.OK))
  579. {
  580. DataTable selDt = frmSCMN013.SelTable;
  581. if (selDt == null)
  582. {
  583. return null;
  584. }
  585. if ((DataTable)dataGridView.DataSource == null)
  586. {
  587. return null;
  588. }
  589. // 如果是进行修改的,需要清除当前行信息
  590. if (dataGridView.Rows.Count > rowItem.Index)
  591. {
  592. dataGridView.Rows.RemoveAt(rowIndex);
  593. }
  594. returnTable = selDt.Copy();
  595. if (selDt != null && selDt.Rows.Count != 0)
  596. {
  597. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  598. // 除去新行
  599. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  600. {
  601. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  602. {
  603. continue;
  604. }
  605. if (string.IsNullOrEmpty(dgvTable.Rows[i]["UserID"] + ""))
  606. {
  607. dgvTable.Rows.RemoveAt(i);
  608. }
  609. }
  610. bool isContinue = true;
  611. for (int i = 0; i < selDt.Rows.Count; i++)
  612. {
  613. isContinue = true;
  614. if (dgvTable != null)
  615. {
  616. for (int j = 0; j < dgvTable.Rows.Count; j++)
  617. {
  618. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  619. && selDt.Rows[i].RowState != DataRowState.Deleted
  620. && (Convert.ToInt32(selDt.Rows[i]["UserID"])
  621. == Convert.ToInt32(dgvTable.Rows[j]["UserID"])))
  622. {
  623. isContinue = false;
  624. break;
  625. }
  626. }
  627. }
  628. if (isContinue)
  629. {
  630. DataRow newRow = dgvTable.NewRow();
  631. foreach (DataColumn column in selDt.Columns)
  632. {
  633. if (dgvTable.Columns.Contains(column.ColumnName)
  634. && selDt.Columns.Contains(column.ColumnName)
  635. && !"Sel".Equals(column.ColumnName))
  636. {
  637. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  638. }
  639. }
  640. // 是否有选择
  641. if (dgvTable.Columns.Contains("Sel"))
  642. {
  643. newRow["Sel"] = 0;
  644. }
  645. foreach (DataColumn col in dgvTable.Columns)
  646. {
  647. col.AllowDBNull = true;
  648. }
  649. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  650. }
  651. }
  652. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  653. dataGridView.ProcessRightKey(Keys.Enter);
  654. }
  655. }
  656. else
  657. {
  658. rowItem.Cells[searchName].Value = codeValue;
  659. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  660. if (string.IsNullOrEmpty(codeValue))
  661. {
  662. dataGridView.Rows.RemoveAt(rowItem.Index);
  663. }
  664. // 除去新行
  665. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  666. {
  667. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  668. {
  669. continue;
  670. }
  671. if (string.IsNullOrEmpty(tmpTable.Rows[i]["UserID"] + ""))
  672. {
  673. tmpTable.Rows.RemoveAt(i);
  674. }
  675. }
  676. }
  677. return returnTable;
  678. }
  679. catch (Exception ex)
  680. {
  681. throw ex;
  682. }
  683. }
  684. /// <summary>
  685. /// 获取工号信息后绑定数据源
  686. /// </summary>
  687. /// <param name="dataGridView">绑定的列表对象</param>
  688. /// <param name="rowIndex">行号</param>
  689. /// <param name="searchName">列名</param>
  690. /// <param name="codeValue">该列原来的值</param>
  691. public static DataTable BindUserRowDataSource2(C_DataGridView dataGridView, int rowIndex,
  692. string searchName, string codeValue)
  693. {
  694. try
  695. {
  696. DataTable returnTable = new DataTable("dataTable");
  697. S_CMN_013 frmSCMN013 = new S_CMN_013();
  698. frmSCMN013.SetUserCode = codeValue;
  699. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  700. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  701. if ("UserCode1".Equals(searchName))
  702. {
  703. frmSCMN013.SetUserCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  704. }
  705. else
  706. {
  707. return null;
  708. }
  709. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  710. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  711. {
  712. if (!string.IsNullOrEmpty(codeValue))
  713. {
  714. rowItem.Cells[searchName].Value = codeValue;
  715. }
  716. return null;
  717. }
  718. // 防止2次关闭才能关掉
  719. if (codeValue == rowItem.Cells[searchName].Value + "")
  720. {
  721. return null;
  722. }
  723. DialogResult dialogResult = frmSCMN013.ShowDialog();
  724. // 只有点确定时才进行下面的操作
  725. if (dialogResult.Equals(DialogResult.OK))
  726. {
  727. DataTable selDt = frmSCMN013.SelTable;
  728. if (selDt == null)
  729. {
  730. return null;
  731. }
  732. if ((DataTable)dataGridView.DataSource == null)
  733. {
  734. return null;
  735. }
  736. // 如果是进行修改的,需要清除当前行信息
  737. if (dataGridView.Rows.Count > rowItem.Index)
  738. {
  739. dataGridView.Rows.RemoveAt(rowIndex);
  740. }
  741. returnTable = selDt.Copy();
  742. if (selDt != null && selDt.Rows.Count != 0)
  743. {
  744. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  745. // 除去新行
  746. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  747. {
  748. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  749. {
  750. continue;
  751. }
  752. if (string.IsNullOrEmpty(dgvTable.Rows[i]["UserID"] + ""))
  753. {
  754. dgvTable.Rows.RemoveAt(i);
  755. }
  756. }
  757. bool isContinue = true;
  758. for (int i = 0; i < selDt.Rows.Count; i++)
  759. {
  760. isContinue = true;
  761. if (dgvTable != null)
  762. {
  763. for (int j = 0; j < dgvTable.Rows.Count; j++)
  764. {
  765. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  766. && selDt.Rows[i].RowState != DataRowState.Deleted
  767. && (Convert.ToInt32(selDt.Rows[i]["UserID"])
  768. == Convert.ToInt32(dgvTable.Rows[j]["UserID"])))
  769. {
  770. isContinue = false;
  771. break;
  772. }
  773. }
  774. }
  775. if (isContinue)
  776. {
  777. DataRow newRow = dgvTable.NewRow();
  778. foreach (DataColumn column in selDt.Columns)
  779. {
  780. if (dgvTable.Columns.Contains(column.ColumnName)
  781. && selDt.Columns.Contains(column.ColumnName)
  782. && !"Sel".Equals(column.ColumnName))
  783. {
  784. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  785. }
  786. }
  787. // 是否有选择
  788. if (dgvTable.Columns.Contains("Sel"))
  789. {
  790. newRow["Sel"] = 0;
  791. }
  792. foreach (DataColumn col in dgvTable.Columns)
  793. {
  794. col.AllowDBNull = true;
  795. }
  796. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  797. }
  798. }
  799. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  800. dataGridView.ProcessRightKey(Keys.Enter);
  801. }
  802. }
  803. else
  804. {
  805. rowItem.Cells[searchName].Value = codeValue;
  806. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  807. if (string.IsNullOrEmpty(codeValue))
  808. {
  809. dataGridView.Rows.RemoveAt(rowItem.Index);
  810. }
  811. // 除去新行
  812. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  813. {
  814. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  815. {
  816. continue;
  817. }
  818. if (string.IsNullOrEmpty(tmpTable.Rows[i]["UserID"] + ""))
  819. {
  820. tmpTable.Rows.RemoveAt(i);
  821. }
  822. }
  823. }
  824. return returnTable;
  825. }
  826. catch (Exception ex)
  827. {
  828. throw ex;
  829. }
  830. }
  831. /// <summary>
  832. /// 获取缺陷信息后绑定数据源
  833. /// </summary>
  834. /// <param name="dataGridView">绑定的列表对象</param>
  835. /// <param name="rowIndex">行号</param>
  836. /// <param name="searchName">列名</param>
  837. /// <param name="codeValue">该列原来的值</param>
  838. public static DataTable BindDefectRowDataSource(C_DataGridView dataGridView, int rowIndex,
  839. string searchName, string codeValue)
  840. {
  841. try
  842. {
  843. DataTable returnTable = new DataTable("dataTable");
  844. S_CMN_014 frmSCMN014 = new S_CMN_014();
  845. frmSCMN014.SetDefectCode = codeValue;
  846. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  847. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  848. if ("DefectCode".Equals(searchName))
  849. {
  850. frmSCMN014.SetDefectCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  851. }
  852. else
  853. {
  854. return null;
  855. }
  856. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  857. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  858. {
  859. if (!string.IsNullOrEmpty(codeValue))
  860. {
  861. rowItem.Cells[searchName].Value = codeValue;
  862. }
  863. return null;
  864. }
  865. // 防止2次关闭才能关掉
  866. if (codeValue == rowItem.Cells[searchName].Value + "")
  867. {
  868. return null;
  869. }
  870. DialogResult dialogResult = frmSCMN014.ShowDialog();
  871. // 只有点确定时才进行下面的操作
  872. if (dialogResult.Equals(DialogResult.OK))
  873. {
  874. DataTable selDt = frmSCMN014.SelTable;
  875. if (selDt == null)
  876. {
  877. return null;
  878. }
  879. if ((DataTable)dataGridView.DataSource == null)
  880. {
  881. return null;
  882. }
  883. // 如果是进行修改的,需要清除当前行信息
  884. if (dataGridView.Rows.Count > rowItem.Index)
  885. {
  886. dataGridView.Rows.RemoveAt(rowIndex);
  887. }
  888. returnTable = selDt.Copy();
  889. if (selDt != null && selDt.Rows.Count != 0)
  890. {
  891. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  892. // 除去新行
  893. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  894. {
  895. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  896. {
  897. continue;
  898. }
  899. if (string.IsNullOrEmpty(dgvTable.Rows[i]["DefectID"] + ""))
  900. {
  901. dgvTable.Rows.RemoveAt(i);
  902. }
  903. }
  904. bool isContinue = true;
  905. for (int i = 0; i < selDt.Rows.Count; i++)
  906. {
  907. isContinue = true;
  908. if (dgvTable != null)
  909. {
  910. for (int j = 0; j < dgvTable.Rows.Count; j++)
  911. {
  912. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  913. && selDt.Rows[i].RowState != DataRowState.Deleted
  914. && (Convert.ToInt32(selDt.Rows[i]["DefectID"])
  915. == Convert.ToInt32(dgvTable.Rows[j]["DefectID"])))
  916. {
  917. isContinue = false;
  918. break;
  919. }
  920. }
  921. }
  922. if (isContinue)
  923. {
  924. DataRow newRow = dgvTable.NewRow();
  925. foreach (DataColumn column in selDt.Columns)
  926. {
  927. if (dgvTable.Columns.Contains(column.ColumnName)
  928. && selDt.Columns.Contains(column.ColumnName)
  929. && !"Sel".Equals(column.ColumnName))
  930. {
  931. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  932. }
  933. }
  934. // 是否有选择
  935. if (dgvTable.Columns.Contains("Sel"))
  936. {
  937. newRow["Sel"] = 0;
  938. }
  939. foreach (DataColumn col in dgvTable.Columns)
  940. {
  941. col.AllowDBNull = true;
  942. }
  943. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  944. }
  945. }
  946. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  947. dataGridView.ProcessRightKey(Keys.Enter);
  948. }
  949. }
  950. else
  951. {
  952. rowItem.Cells[searchName].Value = codeValue;
  953. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  954. if (string.IsNullOrEmpty(codeValue))
  955. {
  956. dataGridView.Rows.RemoveAt(rowItem.Index);
  957. }
  958. // 除去新行
  959. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  960. {
  961. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  962. {
  963. continue;
  964. }
  965. if (string.IsNullOrEmpty(tmpTable.Rows[i]["DefectID"] + ""))
  966. {
  967. tmpTable.Rows.RemoveAt(i);
  968. }
  969. }
  970. }
  971. return returnTable;
  972. }
  973. catch (Exception ex)
  974. {
  975. throw ex;
  976. }
  977. }
  978. /// <summary>
  979. /// 获取缺陷信息后绑定数据源(列表可重复)
  980. /// </summary>
  981. /// <param name="dataGridView">绑定的列表对象</param>
  982. /// <param name="rowIndex">行号</param>
  983. /// <param name="searchName">列名</param>
  984. /// <param name="codeValue">该列原来的值</param>
  985. public static DataTable BindDefectRowRepeatDataSource(C_DataGridView dataGridView, int rowIndex,
  986. string searchName, string codeValue)
  987. {
  988. try
  989. {
  990. DataTable returnTable = new DataTable("dataTable");
  991. S_CMN_014 frmSCMN014 = new S_CMN_014();
  992. frmSCMN014.SetDefectCode = codeValue;
  993. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  994. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  995. if ("DefectCode".Equals(searchName) || "MissDefectCode".Equals(searchName))
  996. {
  997. frmSCMN014.SetDefectCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  998. }
  999. else
  1000. {
  1001. return null;
  1002. }
  1003. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  1004. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  1005. {
  1006. if (!string.IsNullOrEmpty(codeValue))
  1007. {
  1008. rowItem.Cells[searchName].Value = codeValue;
  1009. }
  1010. return null;
  1011. }
  1012. // 防止2次关闭才能关掉
  1013. if (codeValue == rowItem.Cells[searchName].Value + "")
  1014. {
  1015. return null;
  1016. }
  1017. DialogResult dialogResult = frmSCMN014.ShowDialog();
  1018. // 只有点确定时才进行下面的操作
  1019. if (dialogResult.Equals(DialogResult.OK))
  1020. {
  1021. DataTable selDt = frmSCMN014.SelTable;
  1022. if (selDt == null)
  1023. {
  1024. return null;
  1025. }
  1026. if ((DataTable)dataGridView.DataSource == null)
  1027. {
  1028. return null;
  1029. }
  1030. // 如果是进行修改的,需要清除当前行信息
  1031. if (dataGridView.Rows.Count > rowItem.Index)
  1032. {
  1033. dataGridView.Rows.RemoveAt(rowIndex);
  1034. }
  1035. returnTable = selDt.Copy();
  1036. if (selDt != null && selDt.Rows.Count != 0)
  1037. {
  1038. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  1039. // 除去新行
  1040. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  1041. {
  1042. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  1043. {
  1044. continue;
  1045. }
  1046. if (string.IsNullOrEmpty(dgvTable.Rows[i]["DefectID"] + ""))
  1047. {
  1048. dgvTable.Rows.RemoveAt(i);
  1049. }
  1050. }
  1051. bool isContinue = true;
  1052. for (int i = 0; i < selDt.Rows.Count; i++)
  1053. {
  1054. isContinue = true;
  1055. //if (dgvTable != null)
  1056. //{
  1057. // for (int j = 0; j < dgvTable.Rows.Count; j++)
  1058. // {
  1059. // if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  1060. // && selDt.Rows[i].RowState != DataRowState.Deleted
  1061. // )
  1062. // //&& (Convert.ToInt32(selDt.Rows[i]["DefectID"])
  1063. // //== Convert.ToInt32(dgvTable.Rows[j]["DefectID"])))
  1064. // {
  1065. // isContinue = false;
  1066. // break;
  1067. // }
  1068. // }
  1069. //}
  1070. if (isContinue)
  1071. {
  1072. DataRow newRow = dgvTable.NewRow();
  1073. foreach (DataColumn column in selDt.Columns)
  1074. {
  1075. if (dgvTable.Columns.Contains(column.ColumnName)
  1076. && selDt.Columns.Contains(column.ColumnName)
  1077. && !"Sel".Equals(column.ColumnName))
  1078. {
  1079. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  1080. }
  1081. }
  1082. // 是否有选择
  1083. if (dgvTable.Columns.Contains("Sel"))
  1084. {
  1085. newRow["Sel"] = 0;
  1086. }
  1087. foreach (DataColumn col in dgvTable.Columns)
  1088. {
  1089. col.AllowDBNull = true;
  1090. }
  1091. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  1092. }
  1093. }
  1094. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  1095. dataGridView.ProcessRightKey(Keys.Enter);
  1096. }
  1097. }
  1098. else
  1099. {
  1100. rowItem.Cells[searchName].Value = codeValue;
  1101. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  1102. if (string.IsNullOrEmpty(codeValue))
  1103. {
  1104. dataGridView.Rows.RemoveAt(rowItem.Index);
  1105. }
  1106. // 除去新行
  1107. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  1108. {
  1109. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  1110. {
  1111. continue;
  1112. }
  1113. if (string.IsNullOrEmpty(tmpTable.Rows[i]["DefectID"] + ""))
  1114. {
  1115. tmpTable.Rows.RemoveAt(i);
  1116. }
  1117. }
  1118. }
  1119. return returnTable;
  1120. }
  1121. catch (Exception ex)
  1122. {
  1123. throw ex;
  1124. }
  1125. }
  1126. /// <summary>
  1127. /// 获取工种信息后绑定数据源(单条绑定)
  1128. /// </summary>
  1129. /// <param name="dataGridView">绑定的列表对象</param>
  1130. /// <param name="rowIndex">行号</param>
  1131. /// <param name="searchName">列名</param>
  1132. /// <param name="codeValue">该列原来的值</param>
  1133. public static DataTable BindJobsOneRowDataSource(C_DataGridView dataGridView, int rowIndex,
  1134. string searchName, string codeValue)
  1135. {
  1136. try
  1137. {
  1138. DataTable returnTable = new DataTable("dataTable");
  1139. S_CMN_008 frmSCMN008 = new S_CMN_008();
  1140. frmSCMN008.SetJobsCode = codeValue;
  1141. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  1142. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  1143. if ("JobsCode".Equals(searchName) || "MissJobsCode".Equals(searchName))
  1144. {
  1145. frmSCMN008.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  1146. }
  1147. else
  1148. {
  1149. return null;
  1150. }
  1151. DialogResult dialogResult = frmSCMN008.ShowDialog();
  1152. // 只有点确定时才进行下面的操作
  1153. if (dialogResult.Equals(DialogResult.OK))
  1154. {
  1155. foreach (DataColumn col in frmSCMN008.DataSource.Columns)
  1156. {
  1157. if (dataGridView.Columns.Contains(col.ColumnName))
  1158. {
  1159. rowItem.Cells[col.ColumnName].Value = frmSCMN008.JobsRow[col.ColumnName];
  1160. }
  1161. }
  1162. }
  1163. else
  1164. {
  1165. rowItem.Cells[searchName].Value = codeValue;
  1166. }
  1167. return returnTable;
  1168. }
  1169. catch (Exception ex)
  1170. {
  1171. throw ex;
  1172. }
  1173. }
  1174. /// <summary>
  1175. /// 获取工种信息后绑定数据源
  1176. /// </summary>
  1177. /// <param name="dataGridView">绑定的列表对象</param>
  1178. /// <param name="rowIndex">行号</param>
  1179. /// <param name="searchName">列名</param>
  1180. /// <param name="codeValue">该列原来的值</param>
  1181. public static DataTable BindJobsRowDataSource(C_DataGridView dataGridView, int rowIndex,
  1182. string searchName, string codeValue)
  1183. {
  1184. try
  1185. {
  1186. DataTable returnTable = new DataTable("dataTable");
  1187. S_CMN_018 frmSCMN018 = new S_CMN_018();
  1188. frmSCMN018.SetJobsCode = codeValue;
  1189. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  1190. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  1191. if ("JobsCode".Equals(searchName))
  1192. {
  1193. frmSCMN018.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  1194. }
  1195. else
  1196. {
  1197. return null;
  1198. }
  1199. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  1200. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  1201. {
  1202. if (!string.IsNullOrEmpty(codeValue))
  1203. {
  1204. rowItem.Cells[searchName].Value = codeValue;
  1205. }
  1206. else
  1207. {
  1208. dataGridView.Rows.RemoveAt(rowIndex);
  1209. }
  1210. return null;
  1211. }
  1212. // 防止2次关闭才能关掉
  1213. if (codeValue == rowItem.Cells[searchName].Value + "")
  1214. {
  1215. return null;
  1216. }
  1217. DialogResult dialogResult = frmSCMN018.ShowDialog();
  1218. // 只有点确定时才进行下面的操作
  1219. if (dialogResult.Equals(DialogResult.OK))
  1220. {
  1221. DataTable selDt = frmSCMN018.SelTable;
  1222. if (selDt == null)
  1223. {
  1224. return null;
  1225. }
  1226. if ((DataTable)dataGridView.DataSource == null)
  1227. {
  1228. return null;
  1229. }
  1230. // 如果是进行修改的,需要清除当前行信息
  1231. if (dataGridView.Rows.Count > rowItem.Index)
  1232. {
  1233. dataGridView.Rows.RemoveAt(rowIndex);
  1234. }
  1235. returnTable = selDt.Copy();
  1236. if (selDt != null && selDt.Rows.Count != 0)
  1237. {
  1238. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  1239. // 除去新行
  1240. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  1241. {
  1242. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  1243. {
  1244. continue;
  1245. }
  1246. if (string.IsNullOrEmpty(dgvTable.Rows[i]["JobsID"] + ""))
  1247. {
  1248. dgvTable.Rows.RemoveAt(i);
  1249. }
  1250. }
  1251. bool isContinue = true;
  1252. for (int i = 0; i < selDt.Rows.Count; i++)
  1253. {
  1254. isContinue = true;
  1255. if (dgvTable != null)
  1256. {
  1257. for (int j = 0; j < dgvTable.Rows.Count; j++)
  1258. {
  1259. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  1260. && selDt.Rows[i].RowState != DataRowState.Deleted
  1261. && (Convert.ToInt32(selDt.Rows[i]["JobsID"])
  1262. == Convert.ToInt32(dgvTable.Rows[j]["JobsID"])))
  1263. {
  1264. isContinue = false;
  1265. break;
  1266. }
  1267. }
  1268. }
  1269. if (isContinue)
  1270. {
  1271. DataRow newRow = dgvTable.NewRow();
  1272. foreach (DataColumn column in selDt.Columns)
  1273. {
  1274. if (dgvTable.Columns.Contains(column.ColumnName)
  1275. && selDt.Columns.Contains(column.ColumnName)
  1276. && !"Sel".Equals(column.ColumnName))
  1277. {
  1278. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  1279. }
  1280. }
  1281. // 是否有选择
  1282. if (dgvTable.Columns.Contains("Sel"))
  1283. {
  1284. newRow["Sel"] = 0;
  1285. }
  1286. foreach (DataColumn col in dgvTable.Columns)
  1287. {
  1288. col.AllowDBNull = true;
  1289. }
  1290. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  1291. }
  1292. }
  1293. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  1294. dataGridView.ProcessRightKey(Keys.Enter);
  1295. }
  1296. }
  1297. else
  1298. {
  1299. rowItem.Cells[searchName].Value = codeValue;
  1300. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  1301. if (string.IsNullOrEmpty(codeValue))
  1302. {
  1303. dataGridView.Rows.RemoveAt(rowItem.Index);
  1304. }
  1305. // 除去新行
  1306. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  1307. {
  1308. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  1309. {
  1310. continue;
  1311. }
  1312. if (string.IsNullOrEmpty(tmpTable.Rows[i]["JobsID"] + ""))
  1313. {
  1314. tmpTable.Rows.RemoveAt(i);
  1315. }
  1316. }
  1317. }
  1318. return returnTable;
  1319. }
  1320. catch (Exception ex)
  1321. {
  1322. throw ex;
  1323. }
  1324. }
  1325. /// <summary>
  1326. /// 获取员工信息后绑定数据源
  1327. /// </summary>
  1328. /// <param name="dataGridView">绑定的列表对象</param>
  1329. /// <param name="rowIndex">行号</param>
  1330. /// <param name="searchName">列名</param>
  1331. /// <param name="codeValue">该列原来的值</param>
  1332. /// <param name="codeValue">工号</param>
  1333. public static DataTable BindManagerRowDataSource(C_DataGridView dataGridView, int rowIndex,
  1334. string searchName, string codeValue, int managerSalaryID, bool isSelectOne)
  1335. {
  1336. try
  1337. {
  1338. DataTable returnTable = new DataTable("dataTable");
  1339. TAT_CMN_001 frmCMN010 = new TAT_CMN_001();
  1340. frmCMN010.ManagerSalaryID = managerSalaryID;
  1341. frmCMN010.IsSelectOne = isSelectOne;
  1342. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  1343. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  1344. if ("StaffCode".Equals(searchName))
  1345. {
  1346. frmCMN010.StaffCode1 = rowItem.Cells[searchName].EditedFormattedValue + "";
  1347. }
  1348. else
  1349. {
  1350. return null;
  1351. }
  1352. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  1353. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  1354. {
  1355. if (!string.IsNullOrEmpty(codeValue))
  1356. {
  1357. rowItem.Cells[searchName].Value = codeValue;
  1358. }
  1359. return null;
  1360. }
  1361. // 防止2次关闭才能关掉
  1362. if (codeValue == rowItem.Cells[searchName].Value + "")
  1363. {
  1364. return null;
  1365. }
  1366. DialogResult dialogResult = frmCMN010.ShowDialog();
  1367. // 只有点确定时才进行下面的操作
  1368. if (dialogResult.Equals(DialogResult.OK))
  1369. {
  1370. DataTable selDt = frmCMN010.SelTable;
  1371. if (selDt == null)
  1372. {
  1373. return null;
  1374. }
  1375. if ((DataTable)dataGridView.DataSource == null)
  1376. {
  1377. return null;
  1378. }
  1379. //临时待修改
  1380. if (isSelectOne == true)
  1381. {
  1382. dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = selDt.Rows[0]["StaffCode"].ToString();
  1383. dataGridView.Rows[rowIndex].Cells["StaffName"].Value = selDt.Rows[0]["StaffName"].ToString();
  1384. dataGridView.Rows[rowIndex].Cells["StaffId"].Value = selDt.Rows[0]["StaffId"].ToString();
  1385. dataGridView.Rows[rowIndex].Cells["JobsName"].Value = selDt.Rows[0]["JobsName"].ToString();
  1386. if (dataGridView.Columns["Jobs"] != null)
  1387. {
  1388. dataGridView.Rows[rowIndex].Cells["Jobs"].Value = selDt.Rows[0]["Jobs"].ToString();
  1389. }
  1390. if (dataGridView.Columns["StaffStatus"] != null)
  1391. {
  1392. dataGridView.Rows[rowIndex].Cells["StaffStatus"].Value = selDt.Rows[0]["StaffStatus"].ToString();
  1393. }
  1394. if (dataGridView.Columns["StaffStatusName"] != null)
  1395. {
  1396. dataGridView.Rows[rowIndex].Cells["StaffStatusName"].Value = selDt.Rows[0]["StaffStatusName"].ToString();
  1397. }
  1398. if (dataGridView.Columns["OrganizationName"] != null)
  1399. {
  1400. dataGridView.Rows[rowIndex].Cells["OrganizationName"].Value = selDt.Rows[0]["OrganizationName"].ToString();
  1401. }
  1402. return null;
  1403. }
  1404. // 如果是进行修改的,需要清除当前行信息
  1405. if (dataGridView.Rows.Count > rowItem.Index)
  1406. {
  1407. dataGridView.Rows.RemoveAt(rowIndex);
  1408. }
  1409. returnTable = selDt.Copy();
  1410. if (selDt != null && selDt.Rows.Count != 0)
  1411. {
  1412. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  1413. // 除去新行
  1414. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  1415. {
  1416. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  1417. {
  1418. continue;
  1419. }
  1420. if (string.IsNullOrEmpty(dgvTable.Rows[i]["Staffid"] + ""))
  1421. {
  1422. dgvTable.Rows.RemoveAt(i);
  1423. }
  1424. }
  1425. bool isContinue = true;
  1426. for (int i = 0; i < selDt.Rows.Count; i++)
  1427. {
  1428. isContinue = true;
  1429. if (dgvTable != null)
  1430. {
  1431. for (int j = 0; j < dgvTable.Rows.Count; j++)
  1432. {
  1433. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  1434. && selDt.Rows[i].RowState != DataRowState.Deleted
  1435. && (Convert.ToInt32(selDt.Rows[i]["Staffid"])
  1436. == Convert.ToInt32(dgvTable.Rows[j]["Staffid"])))
  1437. {
  1438. isContinue = false;
  1439. break;
  1440. }
  1441. }
  1442. }
  1443. if (isContinue)
  1444. {
  1445. DataRow newRow = dgvTable.NewRow();
  1446. foreach (DataColumn column in selDt.Columns)
  1447. {
  1448. if (dgvTable.Columns.Contains(column.ColumnName)
  1449. && selDt.Columns.Contains(column.ColumnName)
  1450. && !"Sel".Equals(column.ColumnName))
  1451. {
  1452. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  1453. }
  1454. }
  1455. // 是否有选择
  1456. if (dgvTable.Columns.Contains("Sel"))
  1457. {
  1458. newRow["Sel"] = 0;
  1459. }
  1460. foreach (DataColumn col in dgvTable.Columns)
  1461. {
  1462. col.AllowDBNull = true;
  1463. }
  1464. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  1465. }
  1466. }
  1467. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  1468. dataGridView.ProcessRightKey(Keys.Enter);
  1469. }
  1470. }
  1471. else
  1472. {
  1473. //临时待修改
  1474. if (isSelectOne == true)
  1475. {
  1476. dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = "";
  1477. return null;
  1478. }
  1479. rowItem.Cells[searchName].Value = codeValue;
  1480. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  1481. if (string.IsNullOrEmpty(codeValue))
  1482. {
  1483. dataGridView.Rows.RemoveAt(rowItem.Index);
  1484. }
  1485. // 除去新行
  1486. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  1487. {
  1488. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  1489. {
  1490. continue;
  1491. }
  1492. if (string.IsNullOrEmpty(tmpTable.Rows[i]["Staffid"] + ""))
  1493. {
  1494. tmpTable.Rows.RemoveAt(i);
  1495. }
  1496. }
  1497. }
  1498. return returnTable;
  1499. }
  1500. catch (Exception ex)
  1501. {
  1502. throw ex;
  1503. }
  1504. }
  1505. /// <summary>
  1506. /// 获取工序信息后绑定数据源
  1507. /// </summary>
  1508. /// <param name="dataGridView">绑定的列表对象</param>
  1509. /// <param name="rowIndex">行号</param>
  1510. /// <param name="searchName">列名</param>
  1511. /// <param name="codeValue">该列原来的值</param>
  1512. /// <param name="flag">多选标记</param>
  1513. /// <param name="dataSource">工序数据源</param>
  1514. public static DataTable BindtProcedureRowDataSource(C_DataGridView dataGridView, int rowIndex,
  1515. string searchName, string codeValue, int flag, DataTable dataSource)
  1516. {
  1517. try
  1518. {
  1519. DataTable returnTable = new DataTable("dataTable");
  1520. S_CMN_016 frmSCMN016 = new S_CMN_016(flag);
  1521. frmSCMN016.SetJobsCode = codeValue;
  1522. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  1523. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  1524. frmSCMN016.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  1525. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  1526. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  1527. {
  1528. if (!string.IsNullOrEmpty(codeValue))
  1529. {
  1530. rowItem.Cells[searchName].Value = codeValue;
  1531. }
  1532. else
  1533. {
  1534. dataGridView.Rows.RemoveAt(rowItem.Index);
  1535. returnTable = (DataTable)dataGridView.DataSource;
  1536. }
  1537. return returnTable;
  1538. }
  1539. // 防止2次关闭才能关掉
  1540. if (codeValue == rowItem.Cells[searchName].Value + "")
  1541. {
  1542. return null;
  1543. }
  1544. frmSCMN016.DataSource = dataSource;
  1545. DialogResult dialogResult = frmSCMN016.ShowDialog();
  1546. // 只有点确定时才进行下面的操作
  1547. if (dialogResult.Equals(DialogResult.OK))
  1548. {
  1549. DataTable selDt = new DataTable();
  1550. //判断是否多选
  1551. if (flag == 1)
  1552. {
  1553. selDt = frmSCMN016.dataDT;
  1554. string filter = "Sel = 1";
  1555. selDt.DefaultView.RowFilter = filter;
  1556. selDt = selDt.DefaultView.ToTable();
  1557. if (selDt == null)
  1558. {
  1559. return null;
  1560. }
  1561. if ((DataTable)dataGridView.DataSource == null)
  1562. {
  1563. return null;
  1564. }
  1565. // 如果是进行修改的,需要清除当前行信息
  1566. if (dataGridView.Rows.Count > rowItem.Index)
  1567. {
  1568. dataGridView.Rows.RemoveAt(rowIndex);
  1569. }
  1570. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  1571. if (selDt != null && selDt.Rows.Count != 0)
  1572. {
  1573. // 除去新行
  1574. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  1575. {
  1576. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  1577. {
  1578. continue;
  1579. }
  1580. if (string.IsNullOrEmpty(dgvTable.Rows[i]["ProcedureID"] + ""))
  1581. {
  1582. dgvTable.Rows.RemoveAt(i);
  1583. }
  1584. }
  1585. bool isContinue = true;
  1586. for (int i = 0; i < selDt.Rows.Count; i++)
  1587. {
  1588. isContinue = true;
  1589. if (dgvTable != null)
  1590. {
  1591. for (int j = 0; j < dgvTable.Rows.Count; j++)
  1592. {
  1593. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  1594. && selDt.Rows[i].RowState != DataRowState.Deleted
  1595. && (Convert.ToInt32(selDt.Rows[i]["ProcedureID"])
  1596. == Convert.ToInt32(dgvTable.Rows[j]["ProcedureID"])))
  1597. {
  1598. isContinue = false;
  1599. break;
  1600. }
  1601. }
  1602. }
  1603. if (isContinue)
  1604. {
  1605. DataRow newRow = dgvTable.NewRow();
  1606. foreach (DataColumn column in selDt.Columns)
  1607. {
  1608. if (dgvTable.Columns.Contains(column.ColumnName)
  1609. && selDt.Columns.Contains(column.ColumnName)
  1610. && !"Sel".Equals(column.ColumnName))
  1611. {
  1612. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  1613. }
  1614. }
  1615. // 是否有选择
  1616. if (dgvTable.Columns.Contains("Sel"))
  1617. {
  1618. newRow["Sel"] = 0;
  1619. }
  1620. foreach (DataColumn col in dgvTable.Columns)
  1621. {
  1622. col.AllowDBNull = true;
  1623. }
  1624. dgvTable.Rows.Add(newRow);
  1625. }
  1626. }
  1627. }
  1628. returnTable = dgvTable;
  1629. }
  1630. else
  1631. {
  1632. // 如果是进行修改的,需要清除当前行信息
  1633. if (dataGridView.Rows.Count > rowItem.Index)
  1634. {
  1635. for (int i = rowIndex; i >= 0; i--)
  1636. {
  1637. dataGridView.Rows.RemoveAt(i);
  1638. }
  1639. }
  1640. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  1641. DataRow newRow = dgvTable.NewRow();
  1642. foreach (DataColumn column in dataSource.Columns)
  1643. {
  1644. if (dgvTable.Columns.Contains(column.ColumnName)
  1645. && dataSource.Columns.Contains(column.ColumnName))
  1646. {
  1647. newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
  1648. }
  1649. }
  1650. foreach (DataColumn col in dgvTable.Columns)
  1651. {
  1652. col.AllowDBNull = false;
  1653. }
  1654. newRow["procedureID"] = frmSCMN016.ProductionLineRow["procedureID"].ToString();
  1655. newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
  1656. newRow["procedureName"] = frmSCMN016.ProductionLineRow["procedureName"].ToString();
  1657. if (dgvTable.Rows.Count > 0)
  1658. {
  1659. newRow["RptProcedureID"] = 0;
  1660. newRow["RptSProcedureID"] = 0;
  1661. }
  1662. dgvTable.Rows.Add(newRow);
  1663. returnTable = dgvTable;
  1664. }
  1665. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  1666. dataGridView.ProcessRightKey(Keys.Enter);
  1667. }
  1668. else
  1669. {
  1670. if (string.IsNullOrEmpty(codeValue))
  1671. {
  1672. dataGridView.Rows.RemoveAt(rowItem.Index);
  1673. }
  1674. returnTable = (DataTable)dataGridView.DataSource;
  1675. // 除去新行
  1676. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  1677. {
  1678. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  1679. {
  1680. continue;
  1681. }
  1682. if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + ""))
  1683. {
  1684. returnTable.Rows.RemoveAt(i);
  1685. }
  1686. }
  1687. }
  1688. return returnTable;
  1689. }
  1690. catch (Exception ex)
  1691. {
  1692. throw ex;
  1693. }
  1694. }
  1695. /// 获取窑炉信息后绑定数据源
  1696. /// </summary>
  1697. /// <param name="dataGridView">绑定的列表对象</param>
  1698. /// <param name="rowIndex">行号</param>
  1699. /// <param name="searchName">列名</param>
  1700. /// <param name="codeValue">该列原来的值</param>
  1701. public static DataTable BindKilnRowDataSource(C_DataGridView dataGridView, int rowIndex,
  1702. string searchName, string codeValue)
  1703. {
  1704. try
  1705. {
  1706. DataTable returnTable = new DataTable("dataTable");
  1707. S_CMN_023 frmSCMN023 = new S_CMN_023();
  1708. frmSCMN023.SetKilnCode = codeValue;
  1709. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  1710. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  1711. if ("kilnCode".Equals(searchName))
  1712. {
  1713. frmSCMN023.SetKilnCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  1714. }
  1715. else
  1716. {
  1717. return null;
  1718. }
  1719. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  1720. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  1721. {
  1722. if (!string.IsNullOrEmpty(codeValue))
  1723. {
  1724. rowItem.Cells[searchName].Value = codeValue;
  1725. }
  1726. return null;
  1727. }
  1728. // 防止2次关闭才能关掉
  1729. if (codeValue == rowItem.Cells[searchName].Value + "")
  1730. {
  1731. return null;
  1732. }
  1733. DialogResult dialogResult = frmSCMN023.ShowDialog();
  1734. // 只有点确定时才进行下面的操作
  1735. if (dialogResult.Equals(DialogResult.OK))
  1736. {
  1737. DataTable selDt = frmSCMN023.SelTable;
  1738. if (selDt == null)
  1739. {
  1740. return null;
  1741. }
  1742. if ((DataTable)dataGridView.DataSource == null)
  1743. {
  1744. return null;
  1745. }
  1746. // 如果是进行修改的,需要清除当前行信息
  1747. if (dataGridView.Rows.Count > rowItem.Index)
  1748. {
  1749. dataGridView.Rows.RemoveAt(rowIndex);
  1750. }
  1751. returnTable = selDt.Copy();
  1752. if (selDt != null && selDt.Rows.Count != 0)
  1753. {
  1754. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  1755. // 除去新行
  1756. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  1757. {
  1758. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  1759. {
  1760. continue;
  1761. }
  1762. if (string.IsNullOrEmpty(dgvTable.Rows[i]["KilnID"] + ""))
  1763. {
  1764. dgvTable.Rows.RemoveAt(i);
  1765. }
  1766. }
  1767. bool isContinue = true;
  1768. for (int i = 0; i < selDt.Rows.Count; i++)
  1769. {
  1770. isContinue = true;
  1771. if (dgvTable != null)
  1772. {
  1773. for (int j = 0; j < dgvTable.Rows.Count; j++)
  1774. {
  1775. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  1776. && selDt.Rows[i].RowState != DataRowState.Deleted
  1777. && (Convert.ToInt32(selDt.Rows[i]["KilnID"])
  1778. == Convert.ToInt32(dgvTable.Rows[j]["KilnID"])))
  1779. {
  1780. isContinue = false;
  1781. break;
  1782. }
  1783. }
  1784. }
  1785. if (isContinue)
  1786. {
  1787. DataRow newRow = dgvTable.NewRow();
  1788. foreach (DataColumn column in selDt.Columns)
  1789. {
  1790. if (dgvTable.Columns.Contains(column.ColumnName)
  1791. && selDt.Columns.Contains(column.ColumnName)
  1792. && !"Sel".Equals(column.ColumnName))
  1793. {
  1794. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  1795. }
  1796. }
  1797. // 是否有选择
  1798. if (dgvTable.Columns.Contains("Sel"))
  1799. {
  1800. newRow["Sel"] = 0;
  1801. }
  1802. foreach (DataColumn col in dgvTable.Columns)
  1803. {
  1804. col.AllowDBNull = true;
  1805. }
  1806. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  1807. }
  1808. }
  1809. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  1810. dataGridView.ProcessRightKey(Keys.Enter);
  1811. }
  1812. }
  1813. else
  1814. {
  1815. rowItem.Cells[searchName].Value = codeValue;
  1816. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  1817. if (string.IsNullOrEmpty(codeValue))
  1818. {
  1819. dataGridView.Rows.RemoveAt(rowItem.Index);
  1820. }
  1821. // 除去新行
  1822. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  1823. {
  1824. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  1825. {
  1826. continue;
  1827. }
  1828. if (string.IsNullOrEmpty(tmpTable.Rows[i]["KilnID"] + ""))
  1829. {
  1830. tmpTable.Rows.RemoveAt(i);
  1831. }
  1832. }
  1833. }
  1834. return returnTable;
  1835. }
  1836. catch (Exception ex)
  1837. {
  1838. throw ex;
  1839. }
  1840. }
  1841. /// <summary>
  1842. /// 获取工号信息后绑定数据源
  1843. /// </summary>
  1844. /// <param name="dataGridView">绑定的列表对象</param>
  1845. /// <param name="rowIndex">行号</param>
  1846. /// <param name="searchName">列名</param>
  1847. /// <param name="codeValue">该列原来的值</param>
  1848. public static DataTable BindUserRowDataSource_FunctionCode(C_DataGridView dataGridView, int rowIndex,
  1849. string searchName, string codeValue)
  1850. {
  1851. try
  1852. {
  1853. DataTable returnTable = new DataTable("dataTable");
  1854. S_CMN_013 frmSCMN013 = new S_CMN_013();
  1855. frmSCMN013.SetUserCode = codeValue;
  1856. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  1857. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  1858. if ("UserCode1".Equals(searchName))
  1859. {
  1860. frmSCMN013.SetUserCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  1861. }
  1862. else
  1863. {
  1864. return null;
  1865. }
  1866. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  1867. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  1868. {
  1869. if (!string.IsNullOrEmpty(codeValue))
  1870. {
  1871. rowItem.Cells[searchName].Value = codeValue;
  1872. }
  1873. return null;
  1874. }
  1875. // 防止2次关闭才能关掉
  1876. if (codeValue == rowItem.Cells[searchName].Value + "")
  1877. {
  1878. return null;
  1879. }
  1880. DialogResult dialogResult = frmSCMN013.ShowDialog();
  1881. // 只有点确定时才进行下面的操作
  1882. if (dialogResult.Equals(DialogResult.OK))
  1883. {
  1884. DataTable selDt = frmSCMN013.SelTable;
  1885. if (selDt == null)
  1886. {
  1887. return null;
  1888. }
  1889. if ((DataTable)dataGridView.DataSource == null)
  1890. {
  1891. return null;
  1892. }
  1893. // 如果是进行修改的,需要清除当前行信息
  1894. if (dataGridView.Rows.Count > rowItem.Index)
  1895. {
  1896. dataGridView.Rows.RemoveAt(rowIndex);
  1897. }
  1898. returnTable = selDt.Copy();
  1899. if (selDt != null && selDt.Rows.Count != 0)
  1900. {
  1901. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  1902. // 除去新行
  1903. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  1904. {
  1905. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  1906. {
  1907. continue;
  1908. }
  1909. if (string.IsNullOrEmpty(dgvTable.Rows[i]["UserID"] + ""))
  1910. {
  1911. dgvTable.Rows.RemoveAt(i);
  1912. }
  1913. }
  1914. bool isContinue = true;
  1915. for (int i = 0; i < selDt.Rows.Count; i++)
  1916. {
  1917. isContinue = true;
  1918. if (dgvTable != null)
  1919. {
  1920. for (int j = 0; j < dgvTable.Rows.Count; j++)
  1921. {
  1922. if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  1923. && selDt.Rows[i].RowState != DataRowState.Deleted
  1924. && (Convert.ToInt32(selDt.Rows[i]["UserID"])
  1925. == Convert.ToInt32(dgvTable.Rows[j]["UserID"])))
  1926. {
  1927. isContinue = false;
  1928. break;
  1929. }
  1930. }
  1931. }
  1932. if (isContinue)
  1933. {
  1934. DataRow newRow = dgvTable.NewRow();
  1935. foreach (DataColumn column in selDt.Columns)
  1936. {
  1937. if (dgvTable.Columns.Contains(column.ColumnName)
  1938. && selDt.Columns.Contains(column.ColumnName)
  1939. && !"Sel".Equals(column.ColumnName))
  1940. {
  1941. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  1942. }
  1943. }
  1944. // 是否有选择
  1945. if (dgvTable.Columns.Contains("Sel"))
  1946. {
  1947. newRow["Sel"] = 0;
  1948. }
  1949. foreach (DataColumn col in dgvTable.Columns)
  1950. {
  1951. col.AllowDBNull = true;
  1952. }
  1953. ((DataTable)dataGridView.DataSource).Rows.Add(newRow);
  1954. }
  1955. }
  1956. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  1957. dataGridView.ProcessRightKey(Keys.Enter);
  1958. }
  1959. }
  1960. else
  1961. {
  1962. rowItem.Cells[searchName].Value = codeValue;
  1963. DataTable tmpTable = (DataTable)dataGridView.DataSource;
  1964. if (string.IsNullOrEmpty(codeValue))
  1965. {
  1966. dataGridView.Rows.RemoveAt(rowItem.Index);
  1967. }
  1968. // 除去新行
  1969. for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
  1970. {
  1971. if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
  1972. {
  1973. continue;
  1974. }
  1975. if (string.IsNullOrEmpty(tmpTable.Rows[i]["UserID"] + ""))
  1976. {
  1977. tmpTable.Rows.RemoveAt(i);
  1978. }
  1979. }
  1980. }
  1981. return returnTable;
  1982. }
  1983. catch (Exception ex)
  1984. {
  1985. throw ex;
  1986. }
  1987. }
  1988. // 工艺配置--工序
  1989. /// <summary>
  1990. /// 获取工序信息后绑定数据源
  1991. /// </summary>
  1992. /// <param name="dataGridView">绑定的列表对象</param>
  1993. /// <param name="rowIndex">行号</param>
  1994. /// <param name="searchName">列名</param>
  1995. /// <param name="codeValue">该列原来的值</param>
  1996. /// <param name="flag">多选标记</param>
  1997. /// <param name="dataSource">工序数据源</param>
  1998. public static DataTable BindtTransferProcedureRowDataSource(C_DataGridView dataGridView, int rowIndex,
  1999. string searchName, string codeValue, int flag, DataTable dataSource)
  2000. {
  2001. try
  2002. {
  2003. DataTable returnTable = new DataTable("dataTable");
  2004. S_CMN_016 frmSCMN016 = new S_CMN_016(flag);
  2005. frmSCMN016.SetJobsCode = codeValue;
  2006. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  2007. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  2008. frmSCMN016.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  2009. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  2010. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  2011. {
  2012. if (!string.IsNullOrEmpty(codeValue))
  2013. {
  2014. if (flag == 1)
  2015. {
  2016. rowItem.Cells[searchName].Value = codeValue;
  2017. }
  2018. else
  2019. {
  2020. rowItem.Cells[searchName].Value = "";
  2021. rowItem.Cells["PERPROCEDUREID"].Value = DBNull.Value;
  2022. }
  2023. }
  2024. else
  2025. {
  2026. dataGridView.Rows.RemoveAt(rowItem.Index);
  2027. returnTable = (DataTable)dataGridView.DataSource;
  2028. }
  2029. return returnTable;
  2030. }
  2031. // 防止2次关闭才能关掉
  2032. if (codeValue == rowItem.Cells[searchName].Value + "")
  2033. {
  2034. return null;
  2035. }
  2036. frmSCMN016.DataSource = dataSource;
  2037. DialogResult dialogResult = frmSCMN016.ShowDialog();
  2038. // 只有点确定时才进行下面的操作
  2039. if (dialogResult.Equals(DialogResult.OK))
  2040. {
  2041. DataTable selDt = new DataTable();
  2042. //判断是否多选
  2043. if (flag == 1)
  2044. {
  2045. selDt = frmSCMN016.dataDT;
  2046. string filter = "Sel = 1";
  2047. selDt.DefaultView.RowFilter = filter;
  2048. selDt = selDt.DefaultView.ToTable();
  2049. if (selDt == null)
  2050. {
  2051. return null;
  2052. }
  2053. if ((DataTable)dataGridView.DataSource == null)
  2054. {
  2055. return null;
  2056. }
  2057. // 如果是进行修改的,需要清除当前行信息 wangx
  2058. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  2059. bool isEdit = false;
  2060. if (dgvTable.Rows.Count > rowItem.Index)
  2061. {
  2062. //dataGridView.Rows.RemoveAt(rowIndex);
  2063. isEdit = true;
  2064. }
  2065. if (selDt != null && selDt.Rows.Count != 0)
  2066. {
  2067. // 除去新行
  2068. for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  2069. {
  2070. if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  2071. {
  2072. continue;
  2073. }
  2074. if (string.IsNullOrEmpty(dgvTable.Rows[i]["ProcedureID"] + "")
  2075. && string.IsNullOrEmpty(dgvTable.Rows[i]["PerprocedureID"] + "")
  2076. && string.IsNullOrEmpty(dgvTable.Rows[i]["OUTTECDEPID"] + "")
  2077. && string.IsNullOrEmpty(dgvTable.Rows[i]["INTECDEPID"] + "")
  2078. && string.IsNullOrEmpty(dgvTable.Rows[i]["DisplayNo"] + ""))
  2079. {
  2080. dgvTable.Rows.RemoveAt(i);
  2081. }
  2082. }
  2083. // 除去新行 end
  2084. bool isContinue = true;
  2085. for (int i = 0; i < selDt.Rows.Count; i++)
  2086. {
  2087. isContinue = true;
  2088. ////if (dgvTable != null)
  2089. ////{
  2090. //// for (int j = 0; j < dgvTable.Rows.Count; j++)
  2091. //// {
  2092. //// if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  2093. //// && selDt.Rows[i].RowState != DataRowState.Deleted
  2094. //// && (Convert.ToInt32(selDt.Rows[i]["ProcedureID"])
  2095. //// == Convert.ToInt32(dgvTable.Rows[j]["ProcedureID"].ToString() == "" ? 0 : dgvTable.Rows[j]["ProcedureID"])))
  2096. //// {
  2097. //// isContinue = false;
  2098. //// break;
  2099. //// }
  2100. //// }
  2101. ////}
  2102. if (isContinue)
  2103. {
  2104. DataRow newRow = null;
  2105. bool isNewRow = true;
  2106. if (isEdit) //存在编辑行
  2107. {
  2108. if (i == 0)
  2109. {
  2110. newRow = dgvTable.Rows[rowIndex];
  2111. isNewRow = false;
  2112. }
  2113. else
  2114. {
  2115. newRow = dgvTable.NewRow();
  2116. }
  2117. }
  2118. else
  2119. {
  2120. newRow = dgvTable.NewRow();
  2121. }
  2122. foreach (DataColumn column in selDt.Columns)
  2123. {
  2124. if (dgvTable.Columns.Contains(column.ColumnName)
  2125. && selDt.Columns.Contains(column.ColumnName)
  2126. && !"Sel".Equals(column.ColumnName))
  2127. {
  2128. // 对应列名赋值
  2129. newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  2130. }
  2131. }
  2132. // 是否有选择
  2133. if (dgvTable.Columns.Contains("Sel"))
  2134. {
  2135. newRow["Sel"] = 0;
  2136. }
  2137. foreach (DataColumn col in dgvTable.Columns)
  2138. {
  2139. col.AllowDBNull = true;
  2140. }
  2141. if (isNewRow)
  2142. //if (dgvTable.Rows.Count <= rowItem.Index)
  2143. dgvTable.Rows.Add(newRow);
  2144. }
  2145. }
  2146. }
  2147. returnTable = dgvTable;
  2148. // 除去新行
  2149. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2150. {
  2151. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2152. {
  2153. continue;
  2154. }
  2155. if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
  2156. && string.IsNullOrEmpty(dgvTable.Rows[i]["PerprocedureID"] + "")
  2157. && string.IsNullOrEmpty(dgvTable.Rows[i]["OUTTECDEPID"] + "")
  2158. && string.IsNullOrEmpty(dgvTable.Rows[i]["INTECDEPID"] + "")
  2159. && string.IsNullOrEmpty(dgvTable.Rows[i]["DisplayNo"] + ""))
  2160. {
  2161. returnTable.Rows.RemoveAt(i);
  2162. }
  2163. }
  2164. }
  2165. else
  2166. {
  2167. // 如果是进行修改的,需要清除当前行信息
  2168. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  2169. bool isEdit = false;
  2170. if (dgvTable.Rows.Count > rowItem.Index)
  2171. {
  2172. isEdit = true;
  2173. //for (int i = rowIndex; i > 0; i--)
  2174. //{
  2175. // dataGridView.Rows.RemoveAt(i);
  2176. //}
  2177. }
  2178. DataRow newRow = null;
  2179. if (isEdit)
  2180. {
  2181. newRow = dgvTable.Rows[rowIndex];
  2182. }
  2183. else
  2184. {
  2185. newRow = dgvTable.NewRow();
  2186. }
  2187. //foreach (DataColumn column in dataSource.Columns)
  2188. //{
  2189. // if (dgvTable.Columns.Contains(column.ColumnName)
  2190. // && dataSource.Columns.Contains(column.ColumnName))
  2191. // {
  2192. // newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
  2193. // }
  2194. //}
  2195. //foreach (DataColumn col in dgvTable.Columns)
  2196. //{
  2197. // col.AllowDBNull = false;
  2198. //}
  2199. newRow["PerprocedureID"] = frmSCMN016.ProductionLineRow["procedureID"].ToString();
  2200. //newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
  2201. newRow["PerprocedureName"] = frmSCMN016.ProductionLineRow["procedureName"].ToString();
  2202. //if (dgvTable.Rows.Count > 0)
  2203. //{
  2204. // newRow["RptProcedureID"] = 0;
  2205. // newRow["RptSProcedureID"] = 0;
  2206. //}
  2207. if (!isEdit)
  2208. {
  2209. dgvTable.Rows.Add(newRow);
  2210. }
  2211. returnTable = dgvTable;
  2212. // 除去新行
  2213. if (!isEdit)
  2214. {
  2215. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2216. {
  2217. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2218. {
  2219. continue;
  2220. }
  2221. if (string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "") && i > rowIndex)
  2222. {
  2223. returnTable.Rows.RemoveAt(i);
  2224. }
  2225. }
  2226. }
  2227. }
  2228. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  2229. dataGridView.ProcessRightKey(Keys.Enter);
  2230. }
  2231. else
  2232. {
  2233. rowItem.Cells[searchName].Value = codeValue;
  2234. if (string.IsNullOrEmpty(codeValue))
  2235. {
  2236. //dataGridView.Rows.RemoveAt(rowItem.Index);
  2237. }
  2238. returnTable = (DataTable)dataGridView.DataSource;
  2239. // 除去新行
  2240. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2241. {
  2242. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2243. {
  2244. continue;
  2245. }
  2246. if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
  2247. && string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "")
  2248. && string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "")
  2249. && string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "")
  2250. && string.IsNullOrEmpty(returnTable.Rows[i]["DisplayNo"] + ""))
  2251. {
  2252. returnTable.Rows.RemoveAt(i);
  2253. }
  2254. }
  2255. }
  2256. return returnTable;
  2257. }
  2258. catch (Exception ex)
  2259. {
  2260. throw ex;
  2261. }
  2262. }
  2263. // 工艺配置--组织机构(出)
  2264. /// <summary>
  2265. /// 获取组织机构信息后绑定数据源
  2266. /// </summary>
  2267. /// <param name="dataGridView">绑定的列表对象</param>
  2268. /// <param name="rowIndex">行号</param>
  2269. /// <param name="searchName">列名</param>
  2270. /// <param name="codeValue">该列原来的值</param>
  2271. /// <param name="flag">多选标记</param>
  2272. /// <param name="dataSource">工序数据源</param>
  2273. public static DataTable BindtTransferOutOrganizationRowDataSource(C_DataGridView dataGridView, int rowIndex,
  2274. string searchName, string codeValue, int flag, DataTable dataSource)
  2275. {
  2276. try
  2277. {
  2278. DataTable returnTable = new DataTable("dataTable");
  2279. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  2280. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  2281. S_CMN_027 frmSCMN001 = new S_CMN_027(flag, rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim());
  2282. // frmSCMN001.CurrentUserOrganizationCode = codeValue;
  2283. //frmSCMN001.CurrentUserOrganizationCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  2284. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  2285. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  2286. {
  2287. if (!string.IsNullOrEmpty(codeValue))
  2288. {
  2289. //rowItem.Cells[searchName].Value = codeValue;
  2290. rowItem.Cells[searchName].Value = "";
  2291. rowItem.Cells["OUTTECDEPID"].Value = DBNull.Value;
  2292. }
  2293. else
  2294. {
  2295. dataGridView.Rows.RemoveAt(rowItem.Index);
  2296. returnTable = (DataTable)dataGridView.DataSource;
  2297. }
  2298. return returnTable;
  2299. }
  2300. // 防止2次关闭才能关掉
  2301. if (codeValue == rowItem.Cells[searchName].Value + "")
  2302. {
  2303. return null;
  2304. }
  2305. frmSCMN001.DataSource = dataSource;
  2306. DialogResult dialogResult = frmSCMN001.ShowDialog();
  2307. // 只有点确定时才进行下面的操作
  2308. if (dialogResult.Equals(DialogResult.OK))
  2309. {
  2310. DataTable selDt = new DataTable();
  2311. //判断是否多选
  2312. if (flag == 1)
  2313. {
  2314. //selDt = frmSCMN001.dataDT;
  2315. //string filter = "Sel = 1";
  2316. //selDt.DefaultView.RowFilter = filter;
  2317. //selDt = selDt.DefaultView.ToTable();
  2318. //if (selDt == null)
  2319. //{
  2320. // return null;
  2321. //}
  2322. //if ((DataTable)dataGridView.DataSource == null)
  2323. //{
  2324. // return null;
  2325. //}
  2326. //// 如果是进行修改的,需要清除当前行信息 wangx
  2327. //DataTable dgvTable = (DataTable)dataGridView.DataSource;
  2328. //bool isEdit = false;
  2329. //if (dgvTable.Rows.Count > rowItem.Index)
  2330. //{
  2331. // //dataGridView.Rows.RemoveAt(rowIndex);
  2332. // isEdit = true;
  2333. //}
  2334. //if (selDt != null && selDt.Rows.Count != 0)
  2335. //{
  2336. // // 除去新行
  2337. // for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
  2338. // {
  2339. // if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
  2340. // {
  2341. // continue;
  2342. // }
  2343. // if (string.IsNullOrEmpty(dgvTable.Rows[i]["ProcedureID"] + "")
  2344. // && string.IsNullOrEmpty(dgvTable.Rows[i]["PerprocedureID"] + ""))
  2345. // {
  2346. // dgvTable.Rows.RemoveAt(i);
  2347. // }
  2348. // }
  2349. // // 除去新行 end
  2350. // bool isContinue = true;
  2351. // for (int i = 0; i < selDt.Rows.Count; i++)
  2352. // {
  2353. // isContinue = true;
  2354. // if (dgvTable != null)
  2355. // {
  2356. // for (int j = 0; j < dgvTable.Rows.Count; j++)
  2357. // {
  2358. // if (dgvTable.Rows[j].RowState != DataRowState.Deleted
  2359. // && selDt.Rows[i].RowState != DataRowState.Deleted
  2360. // && (Convert.ToInt32(selDt.Rows[i]["ProcedureID"])
  2361. // == Convert.ToInt32(dgvTable.Rows[j]["ProcedureID"].ToString() == "" ? 0 : dgvTable.Rows[j]["ProcedureID"])))
  2362. // {
  2363. // isContinue = false;
  2364. // break;
  2365. // }
  2366. // }
  2367. // }
  2368. // if (isContinue)
  2369. // {
  2370. // DataRow newRow = null;
  2371. // bool isNewRow = true;
  2372. // if (isEdit) //存在编辑行
  2373. // {
  2374. // if (i == 0)
  2375. // {
  2376. // newRow = dgvTable.Rows[rowIndex];
  2377. // isNewRow = false;
  2378. // }
  2379. // else
  2380. // {
  2381. // newRow = dgvTable.NewRow();
  2382. // }
  2383. // }
  2384. // else
  2385. // {
  2386. // newRow = dgvTable.NewRow();
  2387. // }
  2388. // foreach (DataColumn column in selDt.Columns)
  2389. // {
  2390. // if (dgvTable.Columns.Contains(column.ColumnName)
  2391. // && selDt.Columns.Contains(column.ColumnName)
  2392. // && !"Sel".Equals(column.ColumnName))
  2393. // {
  2394. // // 对应列名赋值
  2395. // newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
  2396. // }
  2397. // }
  2398. // // 是否有选择
  2399. // if (dgvTable.Columns.Contains("Sel"))
  2400. // {
  2401. // newRow["Sel"] = 0;
  2402. // }
  2403. // foreach (DataColumn col in dgvTable.Columns)
  2404. // {
  2405. // col.AllowDBNull = true;
  2406. // }
  2407. // if (isNewRow)
  2408. // //if (dgvTable.Rows.Count <= rowItem.Index)
  2409. // dgvTable.Rows.Add(newRow);
  2410. // }
  2411. // }
  2412. //}
  2413. //returnTable = dgvTable;
  2414. //// 除去新行
  2415. //for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2416. //{
  2417. // if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2418. // {
  2419. // continue;
  2420. // }
  2421. // if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + ""))
  2422. // {
  2423. // returnTable.Rows.RemoveAt(i);
  2424. // }
  2425. //}
  2426. }
  2427. else
  2428. {
  2429. // 如果是进行修改的,需要清除当前行信息
  2430. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  2431. bool isEdit = false;
  2432. if (dgvTable.Rows.Count > rowItem.Index)
  2433. {
  2434. isEdit = true;
  2435. }
  2436. DataRow newRow = null;
  2437. if (isEdit)
  2438. {
  2439. newRow = dgvTable.Rows[rowIndex];
  2440. }
  2441. else
  2442. {
  2443. newRow = dgvTable.NewRow();
  2444. }
  2445. //foreach (DataColumn column in dataSource.Columns)
  2446. //{
  2447. // if (dgvTable.Columns.Contains(column.ColumnName)
  2448. // && dataSource.Columns.Contains(column.ColumnName))
  2449. // {
  2450. // newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
  2451. // }
  2452. //}
  2453. //foreach (DataColumn col in dgvTable.Columns)
  2454. //{
  2455. // col.AllowDBNull = false;
  2456. //}
  2457. newRow["OUTTECDEPID"] = frmSCMN001.OrganizationRow["ID"].ToString();
  2458. //newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
  2459. newRow["outName"] = frmSCMN001.OrganizationRow["Name"].ToString();
  2460. //if (dgvTable.Rows.Count > 0)
  2461. //{
  2462. // newRow["RptProcedureID"] = 0;
  2463. // newRow["RptSProcedureID"] = 0;
  2464. //}
  2465. if (!isEdit)
  2466. {
  2467. dgvTable.Rows.Add(newRow);
  2468. }
  2469. returnTable = dgvTable;
  2470. // 除去新行
  2471. if (!isEdit)
  2472. {
  2473. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2474. {
  2475. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2476. {
  2477. continue;
  2478. }
  2479. if (string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "") && i > rowIndex)
  2480. {
  2481. returnTable.Rows.RemoveAt(i);
  2482. }
  2483. }
  2484. }
  2485. }
  2486. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  2487. dataGridView.ProcessRightKey(Keys.Enter);
  2488. }
  2489. else
  2490. {
  2491. rowItem.Cells[searchName].Value = codeValue;
  2492. if (string.IsNullOrEmpty(codeValue))
  2493. {
  2494. //dataGridView.Rows.RemoveAt(rowItem.Index);
  2495. }
  2496. returnTable = (DataTable)dataGridView.DataSource;
  2497. // 除去新行
  2498. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2499. {
  2500. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2501. {
  2502. continue;
  2503. }
  2504. if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
  2505. && string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "")
  2506. && string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "")
  2507. && string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "")
  2508. && string.IsNullOrEmpty(returnTable.Rows[i]["DisplayNo"] + ""))
  2509. {
  2510. returnTable.Rows.RemoveAt(i);
  2511. }
  2512. }
  2513. }
  2514. return returnTable;
  2515. }
  2516. catch (Exception ex)
  2517. {
  2518. throw ex;
  2519. }
  2520. }
  2521. // 工艺配置--组织机构(出)
  2522. /// <summary>
  2523. /// 获取组织机构信息后绑定数据源
  2524. /// </summary>
  2525. /// <param name="dataGridView">绑定的列表对象</param>
  2526. /// <param name="rowIndex">行号</param>
  2527. /// <param name="searchName">列名</param>
  2528. /// <param name="codeValue">该列原来的值</param>
  2529. /// <param name="flag">多选标记</param>
  2530. /// <param name="dataSource">工序数据源</param>
  2531. public static DataTable BindtTransferInOrganizationRowDataSource(C_DataGridView dataGridView, int rowIndex,
  2532. string searchName, string codeValue, int flag, DataTable dataSource)
  2533. {
  2534. try
  2535. {
  2536. DataTable returnTable = new DataTable("dataTable");
  2537. DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  2538. int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  2539. S_CMN_027 frmSCMN001 = new S_CMN_027(flag, rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim());
  2540. //S_CMN_027 frmSCMN001 = new S_CMN_027(flag);
  2541. //// frmSCMN001.CurrentUserOrganizationCode = codeValue;
  2542. //DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
  2543. //int columnIndex = dataGridView.CurrentCell.ColumnIndex;
  2544. //frmSCMN001.CurrentUserOrganizationCode = rowItem.Cells[searchName].EditedFormattedValue + "";
  2545. if (rowItem.Cells[searchName].EditedFormattedValue == null ||
  2546. string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
  2547. {
  2548. if (!string.IsNullOrEmpty(codeValue))
  2549. {
  2550. //rowItem.Cells[searchName].Value = codeValue;
  2551. rowItem.Cells[searchName].Value = "";
  2552. rowItem.Cells["INTECDEPID"].Value = DBNull.Value;
  2553. }
  2554. else
  2555. {
  2556. dataGridView.Rows.RemoveAt(rowItem.Index);
  2557. returnTable = (DataTable)dataGridView.DataSource;
  2558. }
  2559. return returnTable;
  2560. }
  2561. // 防止2次关闭才能关掉
  2562. if (codeValue == rowItem.Cells[searchName].Value + "")
  2563. {
  2564. return null;
  2565. }
  2566. frmSCMN001.DataSource = dataSource;
  2567. DialogResult dialogResult = frmSCMN001.ShowDialog();
  2568. // 只有点确定时才进行下面的操作
  2569. if (dialogResult.Equals(DialogResult.OK))
  2570. {
  2571. DataTable selDt = new DataTable();
  2572. // 如果是进行修改的,需要清除当前行信息
  2573. DataTable dgvTable = (DataTable)dataGridView.DataSource;
  2574. bool isEdit = false;
  2575. if (dgvTable.Rows.Count > rowItem.Index)
  2576. {
  2577. isEdit = true;
  2578. }
  2579. DataRow newRow = null;
  2580. if (isEdit)
  2581. {
  2582. newRow = dgvTable.Rows[rowIndex];
  2583. }
  2584. else
  2585. {
  2586. newRow = dgvTable.NewRow();
  2587. }
  2588. //foreach (DataColumn column in dataSource.Columns)
  2589. //{
  2590. // if (dgvTable.Columns.Contains(column.ColumnName)
  2591. // && dataSource.Columns.Contains(column.ColumnName))
  2592. // {
  2593. // newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
  2594. // }
  2595. //}
  2596. //foreach (DataColumn col in dgvTable.Columns)
  2597. //{
  2598. // col.AllowDBNull = false;
  2599. //}
  2600. newRow["INTECDEPID"] = frmSCMN001.OrganizationRow["ID"].ToString();
  2601. //newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
  2602. newRow["InName"] = frmSCMN001.OrganizationRow["Name"].ToString();
  2603. //if (dgvTable.Rows.Count > 0)
  2604. //{
  2605. // newRow["RptProcedureID"] = 0;
  2606. // newRow["RptSProcedureID"] = 0;
  2607. //}
  2608. if (!isEdit)
  2609. {
  2610. dgvTable.Rows.Add(newRow);
  2611. }
  2612. returnTable = dgvTable;
  2613. // 除去新行
  2614. if (!isEdit)
  2615. {
  2616. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2617. {
  2618. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2619. {
  2620. continue;
  2621. }
  2622. if (string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "") && i > rowIndex)
  2623. {
  2624. returnTable.Rows.RemoveAt(i);
  2625. }
  2626. }
  2627. }
  2628. dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
  2629. dataGridView.ProcessRightKey(Keys.Enter);
  2630. }
  2631. else
  2632. {
  2633. rowItem.Cells[searchName].Value = codeValue;
  2634. if (string.IsNullOrEmpty(codeValue))
  2635. {
  2636. //dataGridView.Rows.RemoveAt(rowItem.Index);
  2637. }
  2638. returnTable = (DataTable)dataGridView.DataSource;
  2639. // 除去新行
  2640. for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
  2641. {
  2642. if (returnTable.Rows[i].RowState == DataRowState.Deleted)
  2643. {
  2644. continue;
  2645. }
  2646. if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
  2647. && string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "")
  2648. && string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "")
  2649. && string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "")
  2650. && string.IsNullOrEmpty(returnTable.Rows[i]["DisplayNo"] + ""))
  2651. {
  2652. returnTable.Rows.RemoveAt(i);
  2653. }
  2654. }
  2655. }
  2656. return returnTable;
  2657. }
  2658. catch (Exception ex)
  2659. {
  2660. throw ex;
  2661. }
  2662. }
  2663. }
  2664. }