UIB030310.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;
  10. using System.Collections;
  11. using System.IO;
  12. using System.Diagnostics;
  13. namespace Core.LZMes.Client.UIB
  14. {
  15. public partial class UIB030310 : FrmBase
  16. {
  17. private string directoryPath = "C:\\Temp\\ZBS\\";//质保书临时存放
  18. public UIB030310()
  19. {
  20. InitializeComponent();
  21. }
  22. public override void ToolBar_Click(object sender, string ToolbarKey)
  23. {
  24. switch (ToolbarKey)
  25. {
  26. case "Query":
  27. this.DoQuery();
  28. break;
  29. case "Modify":
  30. this.DoModify();
  31. break;
  32. case "Add":
  33. this.DoAdd();
  34. break;
  35. case "Delete":
  36. this.DoDelete();
  37. break;
  38. case "UpLoad":
  39. this.UpLoad();
  40. break;
  41. case "DownLoad":
  42. this.DownLoad();
  43. break;
  44. case "XDownload":
  45. this.xmlDownLoadFile();
  46. break;
  47. case "XUpLoad":
  48. this.XmlUPLoad();
  49. break;
  50. }
  51. }
  52. public void DoQuery()
  53. {
  54. try
  55. {
  56. ArrayList al = new ArrayList();
  57. al.Add("UIB030310_01.SELECT");
  58. al.Add(this.textBox1.Text);
  59. this.dataSet1.Tables[0].Clear();
  60. CoreClientParam ccp = new CoreClientParam();
  61. ccp.ServerName = "UIB.COM.ComDBQuery";
  62. ccp.MethodName = "doSimpleQuery";
  63. ccp.ServerParams = new object[] { al };
  64. ccp.SourceDataTable = this.dataSet1.Tables[0];
  65. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  66. loadConfigFile();
  67. }
  68. catch (Exception ex)
  69. {
  70. System.Diagnostics.Debug.WriteLine(ex.ToString());
  71. }
  72. }
  73. public void DoModify()
  74. {
  75. if (MessageBox.Show("确定修改?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  76. return;
  77. try
  78. {
  79. ArrayList al = new ArrayList();
  80. al.Add("UIB030310_01.UPDATE");
  81. al.Add(this.tmplNo.Text);//被修改的模板号
  82. al.Add(this.tmplNm.Text);//模板名
  83. al.Add(tmplRang.Value.ToString());//适用范围
  84. al.Add(this.maxCoils.Text);//最大行数
  85. // al.Add(this.UserInfo.GetUserName());
  86. al.Add(this.hideTmplNO.Text);//隐藏的模板号
  87. CoreClientParam ccp = new CoreClientParam();
  88. ccp.ServerName = "UIB.COM.ComDBSave";
  89. ccp.MethodName = "doXmlSave";
  90. ccp.ServerParams = new object[] { al };
  91. this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  92. }
  93. catch (Exception ex)
  94. {
  95. System.Diagnostics.Debug.WriteLine(ex.ToString());
  96. }
  97. }
  98. public void DoDelete()
  99. {
  100. try
  101. {
  102. //Infragistics.Win.UltraWinGrid.UltraGridRow row = this.ultraGrid1.ActiveRow;
  103. if (this.ultraGrid1.ActiveRow == null) return;
  104. if (this.ultraGrid1.ActiveRow.Delete().ToString() == "False")
  105. return;
  106. //this.ultraGrid1.ActiveRow.Delete(true);
  107. ArrayList al = new ArrayList();
  108. al.Add("UIB030310_01.DELETE");
  109. al.Add(this.tmplNo.Text);//模板号
  110. CoreClientParam ccp = new CoreClientParam();
  111. ccp.ServerName = "UIB.COM.ComDBSave";
  112. ccp.MethodName = "doXmlSave";
  113. ccp.ServerParams = new object[] { al };
  114. this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  115. }catch(Exception ex)
  116. {
  117. System.Diagnostics.Debug.WriteLine(ex.ToString());
  118. }
  119. }
  120. public void DoAdd()
  121. {
  122. if (MessageBox.Show("确定增加?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  123. return;
  124. try
  125. {
  126. ArrayList al = new ArrayList();
  127. al.Add("UIB030310_01.INSERT");
  128. al.Add(this.tmplNo.Text);//模板号
  129. al.Add(this.tmplNm.Text);//模板名
  130. al.Add(tmplRang.Value.ToString());//适用范围
  131. al.Add(this.maxCoils.Text);//最大卷数
  132. al.Add(this.UserInfo.GetUserName());
  133. CoreClientParam ccp = new CoreClientParam();
  134. ccp.ServerName = "UIB.COM.ComDBSave";
  135. ccp.MethodName = "doXmlSave";
  136. ccp.ServerParams = new object[] { al };
  137. this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  138. DataRow dr = this.dataSet1.Tables[0].NewRow();
  139. dr["TMPL_NO"] = this.tmplNo.Text;
  140. dr["TMPL_CFNM"] = this.tmplNm.Text;
  141. dr["PROD_LINE"] = tmplRang.Value.ToString();
  142. dr["COIL_ROWS"] = this.maxCoils.Text;
  143. this.dataTable1.Rows.Add(dr);
  144. this.dataTable1.AcceptChanges();
  145. }
  146. catch (Exception ex)
  147. {
  148. System.Diagnostics.Debug.WriteLine(ex.ToString());
  149. }
  150. }
  151. //模板上传
  152. public void UpLoad()
  153. {
  154. try
  155. {
  156. if (this.textBox2.Text == "")
  157. {
  158. MessageBox.Show("请选择需上传的文件");
  159. return;
  160. }
  161. if (MessageBox.Show("确定上传?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  162. return;
  163. FileStream read = new FileStream(this.textBox2.Text.Trim(), FileMode.Open, FileAccess.Read);
  164. byte[] byData = new byte[read.Length];
  165. read.Read(byData, 0, (int)read.Length);
  166. read.Close();
  167. if (byData == null) { MessageBox.Show("请先选择需要上传的文件!", "提示"); return; }
  168. //获取文件扩展名
  169. string[] str = this.textBox2.Text.Trim().Split('.');
  170. string extName = "."+str[str.Length - 1];
  171. CoreClientParam ccp = new CoreClientParam();
  172. ccp.ServerName = "UIB.UIB03.UIB030310";
  173. ccp.MethodName = "upLoadFile";
  174. ccp.ServerParams = new object[] { this.tmplNo.Text, byData, extName, this.UserInfo.GetUserName() };
  175. this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  176. this.DoQuery();
  177. }
  178. catch (Exception ex)
  179. {
  180. System.Diagnostics.Debug.WriteLine(ex.ToString());
  181. MessageBox.Show("上传失败,请选择正确的文件路径", "提示");
  182. }
  183. }
  184. //模板预览
  185. public void DownLoad()
  186. {
  187. try
  188. {
  189. if (this.ultraGrid1.ActiveRow == null) return;
  190. CoreClientParam ccp = new CoreClientParam();
  191. ccp.ServerName = "UIB.UIB03.UIB030310";
  192. ccp.MethodName = "downLoadFile";
  193. ccp.ServerParams = new object[] { this.ultraGrid1.ActiveRow.Cells["TMPL_NO"].Text };
  194. CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  195. byte[] byData = (byte[])cx.ReturnObject;
  196. //判断文件类型
  197. string extFileType = this.ultraGrid1.ActiveRow.Cells["EXT_NAME"].Text;
  198. //if (byData[0] + "" + byData[1] == "208207")//xls文件
  199. //{
  200. // extFileType = ".xls";
  201. //}
  202. //else if (byData[0] + "" + byData[1] == "8075")//docx文件
  203. //{
  204. // extFileType = ".docx";
  205. //}
  206. //else if (byData[0] + "" + byData[1] == "6063")//xml
  207. //{
  208. // extFileType = ".xml";
  209. //}
  210. //else if (byData[0] + "" + byData[1] == "255216")//jpg文件
  211. //{
  212. // extFileType = ".jpg";
  213. //}
  214. //else if (byData[0] + "" + byData[1] == "13780")//png文件
  215. //{
  216. // extFileType = ".png";
  217. //}
  218. //else
  219. //{
  220. // MessageBox.Show("未知文件类型,无法打开!", "提示");
  221. // return;
  222. //}
  223. System.DateTime dt = System.DateTime.Now;
  224. string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt);
  225. string sFile = directoryPath + this.ultraGrid1.ActiveRow.Cells["TMPL_CFNM"].Text + TimeNow + extFileType;
  226. FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write);
  227. fs.Write(byData, 0, byData.Length);
  228. fs.Close();
  229. ProcessStartInfo p = new ProcessStartInfo(sFile);
  230. p.WorkingDirectory = Path.GetDirectoryName(sFile);
  231. Process.Start(p);
  232. }
  233. catch (Exception ex)
  234. {
  235. MessageBox.Show(ex.ToString());
  236. }
  237. }
  238. //配置文件上传
  239. public void XmlUPLoad()
  240. {
  241. try
  242. {
  243. if (this.textBox3.Text == "")
  244. {
  245. MessageBox.Show("请选择需上传的文件");
  246. return;
  247. }
  248. if (MessageBox.Show("确定上传?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  249. return;
  250. FileStream read = new FileStream(this.textBox3.Text.Trim(), FileMode.Open, FileAccess.Read);
  251. byte[] byData = new byte[read.Length];
  252. read.Read(byData, 0, (int)read.Length);
  253. read.Close();
  254. int index_ = this.textBox3.Text.LastIndexOf("\\");
  255. string fName = this.textBox3.Text.Substring(index_+1);
  256. if (byData == null) { MessageBox.Show("请先选择需要上传的文件!", "提示"); return; }
  257. CoreClientParam ccp = new CoreClientParam();
  258. ccp.ServerName = "UIB.UIB03.UIB030310";
  259. ccp.MethodName = "xmlUpLoad";
  260. ccp.ServerParams = new object[] { byData, fName };
  261. this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  262. }
  263. catch (Exception ex)
  264. {
  265. System.Diagnostics.Debug.WriteLine(ex.ToString());
  266. MessageBox.Show("上传失败,请选择正确的文件路径" , "提示");
  267. }
  268. }
  269. //配置文件下载
  270. public void xmlDownLoadFile()
  271. {
  272. try
  273. {
  274. string selectFile = this.listBox1.Text;//被选择的配置文件
  275. if (selectFile == "")
  276. {
  277. MessageBox.Show("请选择需要下载的文件" , "提示");
  278. return;
  279. }
  280. this.folderBrowserDialog1.ShowDialog();
  281. string selectPath = this.folderBrowserDialog1.SelectedPath;//选择的路径
  282. CoreClientParam ccp = new CoreClientParam();
  283. ccp.ServerName = "UIB.UIB03.UIB030310";
  284. ccp.MethodName = "xmlDownLoadFile";
  285. ccp.ServerParams = new object[] { selectFile };
  286. CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  287. byte[] byData = (byte[])cx.ReturnObject;
  288. System.DateTime dt = System.DateTime.Now;
  289. string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt);
  290. string sFile = selectPath +"\\"+ selectFile;
  291. FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write);
  292. fs.Write(byData, 0, byData.Length);
  293. fs.Close();
  294. }
  295. catch (Exception ex)
  296. {
  297. MessageBox.Show(ex.ToString());
  298. }
  299. }
  300. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  301. {
  302. try
  303. {
  304. if (this.ultraGrid1.ActiveRow == null) return;
  305. this.tmplNo.Text = this.ultraGrid1.ActiveRow.Cells["TMPL_NO"].Text;
  306. this.tmplNm.Text = this.ultraGrid1.ActiveRow.Cells["TMPL_CFNM"].Text;
  307. this.tmplRang.Value = this.ultraGrid1.ActiveRow.Cells["PROD_LINE"].Value.ToString();
  308. this.maxCoils.Text = this.ultraGrid1.ActiveRow.Cells["COIL_ROWS"].Text;
  309. this.hideTmplNO.Text = this.ultraGrid1.ActiveRow.Cells["TMPL_NO"].Text;
  310. }
  311. catch (Exception ex)
  312. {
  313. System.Diagnostics.Debug.WriteLine(ex.ToString());
  314. }
  315. }
  316. private void tmplNo_KeyDown(object sender, KeyEventArgs e)
  317. {
  318. if (e.KeyCode == Keys.Enter)
  319. {
  320. this.tmplNm.Focus();
  321. }
  322. }
  323. private void tmplNm_KeyDown(object sender, KeyEventArgs e)
  324. {
  325. if (e.KeyCode == Keys.Enter)
  326. {
  327. this.tmplRang.Focus();
  328. }
  329. }
  330. //质保书上传
  331. private void button1_Click(object sender, EventArgs e)
  332. {
  333. try
  334. {
  335. OpenFileDialog Ofd = new OpenFileDialog();
  336. Ofd.Title = "选择文件";
  337. Ofd.Filter = "文件 (*.doc;*;docx;*.xls;*.xlsx;*.et;*.png;*.xml;*.jpg)|*.doc;*;docx;*.xls;*.xlsx;*.et;*.png;*.xml;*.jpg";
  338. //Ofd.Filter = "文件 (*.xls)|*.xls";
  339. //Ofd.Filter = "文件 (*.*)|*.*";
  340. if (Ofd.ShowDialog() == DialogResult.OK)
  341. {
  342. this.textBox2.Text = Ofd.FileName.ToString();//选取文件路径
  343. }
  344. }
  345. catch(Exception ex)
  346. {
  347. System.Diagnostics.Debug.WriteLine(ex.ToString());
  348. }
  349. }
  350. private void UIB030310_Load(object sender, EventArgs e)
  351. {
  352. try
  353. {
  354. loadConfigFile();
  355. if (!Directory.Exists(directoryPath))//若不存在,则创建临时文件夹
  356. {
  357. Directory.CreateDirectory(directoryPath);
  358. }
  359. if (Directory.Exists(directoryPath))
  360. {
  361. foreach (string f in Directory.GetFileSystemEntries(directoryPath))
  362. {
  363. try
  364. {
  365. if (File.Exists(f))
  366. File.Delete(f); //直接删除其中的文件
  367. }
  368. catch (Exception ex)
  369. {
  370. System.Diagnostics.Debug.WriteLine(ex.ToString());
  371. continue;//文件正在使用,则跳过该文件
  372. }
  373. }
  374. }
  375. }
  376. catch (Exception ex)
  377. {
  378. System.Diagnostics.Debug.WriteLine(ex.ToString());
  379. }
  380. }
  381. //载入所有配置文件
  382. public void loadConfigFile()
  383. {
  384. try
  385. {
  386. this.listBox1.Items.Clear();
  387. //显示所有配置文件
  388. CoreClientParam ccp = new CoreClientParam();
  389. ccp.ServerName = "UIB.UIB03.UIB030310";
  390. ccp.MethodName = "loadUIB030310";
  391. ccp.ServerParams = new object[] { };
  392. CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  393. string[] str = (string[])cx.ReturnObject;
  394. for (int i = 0; i < str.Length; i++)
  395. {
  396. this.listBox1.Items.Add(str[i]);
  397. }
  398. }
  399. catch (Exception ex)
  400. {
  401. }
  402. }
  403. private void button2_Click(object sender, EventArgs e)
  404. {
  405. try
  406. {
  407. OpenFileDialog Ofd = new OpenFileDialog();
  408. Ofd.Title = "选择文件";
  409. // Ofd.Filter = "文件 (*.doc;*.txt;*.htm;*.xls;*.jpg)|*.doc;*.txt;*.htm;*.xls;*.jpg";
  410. Ofd.Filter = "文件 (*.*)|*.*";
  411. if (Ofd.ShowDialog() == DialogResult.OK)
  412. {
  413. this.textBox3.Text = Ofd.FileName.ToString();//选取文件路径
  414. }
  415. }
  416. catch (Exception ex)
  417. {
  418. System.Diagnostics.Debug.WriteLine(ex.ToString());
  419. }
  420. }
  421. private void button3_Click(object sender, EventArgs e)
  422. {
  423. XmlUPLoad();
  424. }
  425. private void button4_Click(object sender, EventArgs e)
  426. {
  427. this.xmlDownLoadFile();
  428. }
  429. //private void button2_Click(object sender, EventArgs e)
  430. //{
  431. // try
  432. // {
  433. // string idName = "UIB030310";
  434. // string value = "123";
  435. // string str;
  436. // StreamReader sr = new StreamReader("D:\\Temp\\LzUpdate\\1.txt", false);
  437. // str = sr.ReadToEnd();
  438. // if (idName.IndexOf(str) != -1)
  439. // {
  440. // }
  441. // sr.Close();
  442. // StreamWriter sw = new StreamWriter("D:\\Temp\\LzUpdate\\1.txt", true);
  443. // // sw.Write(xxx);
  444. // sw.WriteLine(xxx);
  445. // sw.Flush();
  446. // sw.Close();
  447. // //str = sr.ReadLine().ToString();
  448. // MessageBox.Show(str);
  449. // }
  450. // catch (Exception ex)
  451. // {
  452. // MessageBox.Show(ex.ToString());
  453. // }
  454. //}
  455. //private void button2_Click_1(object sender, EventArgs e)
  456. //{
  457. // StreamWriter sw = new StreamWriter("D:\\Temp\\LzUpdate\\1.txt", true);
  458. // // sw.Write(xxx);
  459. // sw.WriteLine(xxx);
  460. // sw.Flush();
  461. // sw.Close();
  462. // string str;
  463. // StreamReader sr = new StreamReader("D:\\Temp\\LzUpdate\\1.txt", false);
  464. // str = sr.ReadToEnd();
  465. // FileStream fs;
  466. //}
  467. }
  468. }