| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using CoreFS.CA06;
- using System.Collections;
- using System.IO;
- using System.Diagnostics;
- namespace Core.LZMes.Client.UIB
- {
- public partial class UIB030310 : FrmBase
- {
- private string directoryPath = "C:\\Temp\\ZBS\\";//质保书临时存放
- public UIB030310()
- {
- InitializeComponent();
- }
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- switch (ToolbarKey)
- {
- case "Query":
- this.DoQuery();
- break;
- case "Modify":
- this.DoModify();
- break;
- case "Add":
- this.DoAdd();
- break;
- case "Delete":
- this.DoDelete();
- break;
- case "UpLoad":
- this.UpLoad();
- break;
- case "DownLoad":
- this.DownLoad();
- break;
- case "XDownload":
- this.xmlDownLoadFile();
- break;
- case "XUpLoad":
- this.XmlUPLoad();
- break;
- }
- }
- public void DoQuery()
- {
- try
- {
- ArrayList al = new ArrayList();
- al.Add("UIB030310_01.SELECT");
- al.Add(this.textBox1.Text);
- this.dataSet1.Tables[0].Clear();
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.COM.ComDBQuery";
- ccp.MethodName = "doSimpleQuery";
- ccp.ServerParams = new object[] { al };
- ccp.SourceDataTable = this.dataSet1.Tables[0];
- this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
- loadConfigFile();
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- public void DoModify()
- {
- if (MessageBox.Show("确定修改?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
- return;
- try
- {
- ArrayList al = new ArrayList();
- al.Add("UIB030310_01.UPDATE");
- al.Add(this.tmplNo.Text);//被修改的模板号
- al.Add(this.tmplNm.Text);//模板名
- al.Add(tmplRang.Value.ToString());//适用范围
- al.Add(this.maxCoils.Text);//最大行数
- // al.Add(this.UserInfo.GetUserName());
- al.Add(this.hideTmplNO.Text);//隐藏的模板号
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.COM.ComDBSave";
- ccp.MethodName = "doXmlSave";
- ccp.ServerParams = new object[] { al };
- this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
-
- }
- public void DoDelete()
- {
- try
- {
- //Infragistics.Win.UltraWinGrid.UltraGridRow row = this.ultraGrid1.ActiveRow;
- if (this.ultraGrid1.ActiveRow == null) return;
- if (this.ultraGrid1.ActiveRow.Delete().ToString() == "False")
- return;
- //this.ultraGrid1.ActiveRow.Delete(true);
- ArrayList al = new ArrayList();
- al.Add("UIB030310_01.DELETE");
- al.Add(this.tmplNo.Text);//模板号
-
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.COM.ComDBSave";
- ccp.MethodName = "doXmlSave";
- ccp.ServerParams = new object[] { al };
- this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- }catch(Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
-
- }
- public void DoAdd()
- {
- if (MessageBox.Show("确定增加?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
- return;
- try
- {
- ArrayList al = new ArrayList();
- al.Add("UIB030310_01.INSERT");
- al.Add(this.tmplNo.Text);//模板号
- al.Add(this.tmplNm.Text);//模板名
- al.Add(tmplRang.Value.ToString());//适用范围
- al.Add(this.maxCoils.Text);//最大卷数
- al.Add(this.UserInfo.GetUserName());
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.COM.ComDBSave";
- ccp.MethodName = "doXmlSave";
- ccp.ServerParams = new object[] { al };
- this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- DataRow dr = this.dataSet1.Tables[0].NewRow();
- dr["TMPL_NO"] = this.tmplNo.Text;
- dr["TMPL_CFNM"] = this.tmplNm.Text;
- dr["PROD_LINE"] = tmplRang.Value.ToString();
- dr["COIL_ROWS"] = this.maxCoils.Text;
- this.dataTable1.Rows.Add(dr);
- this.dataTable1.AcceptChanges();
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- //模板上传
- public void UpLoad()
- {
- try
- {
- if (this.textBox2.Text == "")
- {
- MessageBox.Show("请选择需上传的文件");
- return;
- }
- if (MessageBox.Show("确定上传?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
- return;
- FileStream read = new FileStream(this.textBox2.Text.Trim(), FileMode.Open, FileAccess.Read);
- byte[] byData = new byte[read.Length];
- read.Read(byData, 0, (int)read.Length);
- read.Close();
- if (byData == null) { MessageBox.Show("请先选择需要上传的文件!", "提示"); return; }
- //获取文件扩展名
- string[] str = this.textBox2.Text.Trim().Split('.');
- string extName = "."+str[str.Length - 1];
-
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.UIB03.UIB030310";
- ccp.MethodName = "upLoadFile";
- ccp.ServerParams = new object[] { this.tmplNo.Text, byData, extName, this.UserInfo.GetUserName() };
- this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- this.DoQuery();
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- MessageBox.Show("上传失败,请选择正确的文件路径", "提示");
- }
- }
- //模板预览
- public void DownLoad()
- {
- try
- {
- if (this.ultraGrid1.ActiveRow == null) return;
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.UIB03.UIB030310";
- ccp.MethodName = "downLoadFile";
- ccp.ServerParams = new object[] { this.ultraGrid1.ActiveRow.Cells["TMPL_NO"].Text };
- CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- byte[] byData = (byte[])cx.ReturnObject;
-
- //判断文件类型
- string extFileType = this.ultraGrid1.ActiveRow.Cells["EXT_NAME"].Text;
- //if (byData[0] + "" + byData[1] == "208207")//xls文件
- //{
- // extFileType = ".xls";
- //}
- //else if (byData[0] + "" + byData[1] == "8075")//docx文件
- //{
- // extFileType = ".docx";
- //}
- //else if (byData[0] + "" + byData[1] == "6063")//xml
- //{
- // extFileType = ".xml";
- //}
- //else if (byData[0] + "" + byData[1] == "255216")//jpg文件
- //{
- // extFileType = ".jpg";
- //}
- //else if (byData[0] + "" + byData[1] == "13780")//png文件
- //{
- // extFileType = ".png";
- //}
- //else
- //{
- // MessageBox.Show("未知文件类型,无法打开!", "提示");
- // return;
- //}
- System.DateTime dt = System.DateTime.Now;
- string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt);
- string sFile = directoryPath + this.ultraGrid1.ActiveRow.Cells["TMPL_CFNM"].Text + TimeNow + extFileType;
- FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write);
- fs.Write(byData, 0, byData.Length);
- fs.Close();
- ProcessStartInfo p = new ProcessStartInfo(sFile);
- p.WorkingDirectory = Path.GetDirectoryName(sFile);
- Process.Start(p);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- //配置文件上传
- public void XmlUPLoad()
- {
- try
- {
- if (this.textBox3.Text == "")
- {
- MessageBox.Show("请选择需上传的文件");
- return;
- }
- if (MessageBox.Show("确定上传?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
- return;
- FileStream read = new FileStream(this.textBox3.Text.Trim(), FileMode.Open, FileAccess.Read);
- byte[] byData = new byte[read.Length];
- read.Read(byData, 0, (int)read.Length);
- read.Close();
- int index_ = this.textBox3.Text.LastIndexOf("\\");
- string fName = this.textBox3.Text.Substring(index_+1);
- if (byData == null) { MessageBox.Show("请先选择需要上传的文件!", "提示"); return; }
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.UIB03.UIB030310";
- ccp.MethodName = "xmlUpLoad";
- ccp.ServerParams = new object[] { byData, fName };
- this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- MessageBox.Show("上传失败,请选择正确的文件路径" , "提示");
- }
- }
- //配置文件下载
- public void xmlDownLoadFile()
- {
- try
- {
- string selectFile = this.listBox1.Text;//被选择的配置文件
- if (selectFile == "")
- {
- MessageBox.Show("请选择需要下载的文件" , "提示");
- return;
- }
- this.folderBrowserDialog1.ShowDialog();
- string selectPath = this.folderBrowserDialog1.SelectedPath;//选择的路径
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.UIB03.UIB030310";
- ccp.MethodName = "xmlDownLoadFile";
- ccp.ServerParams = new object[] { selectFile };
- CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- byte[] byData = (byte[])cx.ReturnObject;
- System.DateTime dt = System.DateTime.Now;
- string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt);
- string sFile = selectPath +"\\"+ selectFile;
- FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write);
- fs.Write(byData, 0, byData.Length);
- fs.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
- {
- try
- {
- if (this.ultraGrid1.ActiveRow == null) return;
- this.tmplNo.Text = this.ultraGrid1.ActiveRow.Cells["TMPL_NO"].Text;
- this.tmplNm.Text = this.ultraGrid1.ActiveRow.Cells["TMPL_CFNM"].Text;
- this.tmplRang.Value = this.ultraGrid1.ActiveRow.Cells["PROD_LINE"].Value.ToString();
- this.maxCoils.Text = this.ultraGrid1.ActiveRow.Cells["COIL_ROWS"].Text;
- this.hideTmplNO.Text = this.ultraGrid1.ActiveRow.Cells["TMPL_NO"].Text;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- private void tmplNo_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- this.tmplNm.Focus();
- }
- }
- private void tmplNm_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- this.tmplRang.Focus();
- }
- }
- //质保书上传
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- OpenFileDialog Ofd = new OpenFileDialog();
- Ofd.Title = "选择文件";
- Ofd.Filter = "文件 (*.doc;*;docx;*.xls;*.xlsx;*.et;*.png;*.xml;*.jpg)|*.doc;*;docx;*.xls;*.xlsx;*.et;*.png;*.xml;*.jpg";
- //Ofd.Filter = "文件 (*.xls)|*.xls";
- //Ofd.Filter = "文件 (*.*)|*.*";
- if (Ofd.ShowDialog() == DialogResult.OK)
- {
- this.textBox2.Text = Ofd.FileName.ToString();//选取文件路径
-
- }
- }
- catch(Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- private void UIB030310_Load(object sender, EventArgs e)
- {
- try
- {
- loadConfigFile();
- if (!Directory.Exists(directoryPath))//若不存在,则创建临时文件夹
- {
- Directory.CreateDirectory(directoryPath);
- }
- if (Directory.Exists(directoryPath))
- {
- foreach (string f in Directory.GetFileSystemEntries(directoryPath))
- {
- try
- {
- if (File.Exists(f))
- File.Delete(f); //直接删除其中的文件
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- continue;//文件正在使用,则跳过该文件
- }
- }
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- //载入所有配置文件
- public void loadConfigFile()
- {
- try
- {
- this.listBox1.Items.Clear();
- //显示所有配置文件
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "UIB.UIB03.UIB030310";
- ccp.MethodName = "loadUIB030310";
- ccp.ServerParams = new object[] { };
- CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- string[] str = (string[])cx.ReturnObject;
- for (int i = 0; i < str.Length; i++)
- {
- this.listBox1.Items.Add(str[i]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- try
- {
- OpenFileDialog Ofd = new OpenFileDialog();
- Ofd.Title = "选择文件";
- // Ofd.Filter = "文件 (*.doc;*.txt;*.htm;*.xls;*.jpg)|*.doc;*.txt;*.htm;*.xls;*.jpg";
- Ofd.Filter = "文件 (*.*)|*.*";
- if (Ofd.ShowDialog() == DialogResult.OK)
- {
- this.textBox3.Text = Ofd.FileName.ToString();//选取文件路径
-
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- XmlUPLoad();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- this.xmlDownLoadFile();
- }
- //private void button2_Click(object sender, EventArgs e)
- //{
- // try
- // {
- // string idName = "UIB030310";
- // string value = "123";
- // string str;
- // StreamReader sr = new StreamReader("D:\\Temp\\LzUpdate\\1.txt", false);
- // str = sr.ReadToEnd();
- // if (idName.IndexOf(str) != -1)
- // {
- // }
- // sr.Close();
- // StreamWriter sw = new StreamWriter("D:\\Temp\\LzUpdate\\1.txt", true);
- // // sw.Write(xxx);
- // sw.WriteLine(xxx);
- // sw.Flush();
- // sw.Close();
-
-
- // //str = sr.ReadLine().ToString();
-
- // MessageBox.Show(str);
-
- // }
- // catch (Exception ex)
- // {
- // MessageBox.Show(ex.ToString());
- // }
- //}
- //private void button2_Click_1(object sender, EventArgs e)
- //{
- // StreamWriter sw = new StreamWriter("D:\\Temp\\LzUpdate\\1.txt", true);
- // // sw.Write(xxx);
-
- // sw.WriteLine(xxx);
- // sw.Flush();
- // sw.Close();
- // string str;
- // StreamReader sr = new StreamReader("D:\\Temp\\LzUpdate\\1.txt", false);
- // str = sr.ReadToEnd();
- // FileStream fs;
-
- //}
- }
- }
|