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 Infragistics.Win.UltraWinEditors; using Core.StlMes.Client.ZGMil.Signature; using Core.StlMes.Client.ZGMil.Entity; using Core.Mes.Client.Comm.Control; using Infragistics.Win.UltraWinGrid; using Core.Mes.Client.Comm.Tool; using Core.Mes.Client.Comm.Server; using CoreFS.SA06; using System.Collections; using Infragistics.Win; using System.IO; using Core.StlMes.Client.ZGMil.Common; namespace Core.StlMes.Client.ZGMil { public partial class FrmTubeRollFileManage : FrmBase { private string departm = ""; UltraComboEditor ucePline = new UltraComboEditor();//产线名称 private string plineCode; private string[] plineCodes = { }; private string fileName = "";//路径 public FrmTubeRollFileManage() { InitializeComponent(); } private void FrmTubeRollFileManage_Load(object sender, EventArgs e) { NativeMethodNew na = new NativeMethodNew(this.ob); departm = UserInfo.GetDepartment(); plineCode = na.GetPCode(departm);//获取 用户 对应的产线 plineCodes = BaseMethod.GetPlineCode(ValidDataPurviewIds, ob); //plineCode = na.GetPCodePline(this.ValidDataPurviewIds);//获取产线方法 TubeRoll.InitComboEditorValue(ucePline, "com.steering.mes.signature.FrmTubeRollFileManage.queryPlineCode", "PLINE_CODE", this.ob, false, plineCode); TubeRoll.BindColumn(ucePline, "PLINE_CODE", this.Controls, this.ultraGrid1, 0); DoQuery(); } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": DoQuery(); break; case "Add": DoAdd(); break; case "Delete": DoDelete(); break; case "Update": DoUpdare(); break; case "Close": this.Close(); break; } } private void DoQuery() { DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature", new Object[] { plineCodes, this.UserInfo.GetUserName() }, ob); GridHelper.CopyDataToDatatable(dt, this.dataTable1, true); foreach (UltraGridRow ugr in ultraGrid1.Rows) { ugr.Cells["PLINE_CODE"].Appearance.BackColor =Color.Transparent; ugr.Cells["PLINE_CODE"].Appearance.BackHatchStyle = BackHatchStyle.Default; ugr.Cells["PLINE_CODE"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly; //ugr.Cells["COL_GROUP"].Appearance.BackColor = Color.Transparent; //ugr.Cells["COL_GROUP"].Appearance.BackHatchStyle = BackHatchStyle.Default; //ugr.Cells["COL_GROUP"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly; } } private void DoAdd() { ultraGrid1.UpdateData(); ArrayList list1 = new ArrayList(); string pline = ""; string bz = ""; string url = ""; string userName = ""; //int count = 0; IQueryable uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'"); if (uGrid.Count() == 0) { MessageUtil.ShowTips("请选择要新增的数据!"); return; } foreach (UltraGridRow ugr in uGrid) { //if (Convert.ToBoolean(ugr.Cells["CHK"].Text) == true) //{ // count += 1; pline = ugr.Cells["PLINE_CODE"].Value.ToString(); bz = ugr.Cells["COL_GROUP"].Value.ToString(); url = ugr.Cells["URL"].Value.ToString(); userName = ugr.Cells["COL_USER"].Text.Trim(); string gx = ""; if (pline == "") { MessageUtil.ShowTips("产线不能为空!"); return; } if (bz == "") { MessageUtil.ShowTips("班组不能为空!"); return; } if (userName == "") { MessageUtil.ShowTips("签名不能为空!"); return; } if (url == "") { MessageUtil.ShowTips("路径不能为空!"); return; } if (ugr.Cells["PROCESS_NO"].Text.Trim()!= "") { //MessageUtil.ShowTips("工序名称不能为空!"); return; gx = ugr.Cells["PROCESS_NO"].Value.ToString(); } //DataTable dt1 = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.querySameName", new object[] { ugr.Cells["COL_USER"].Value.ToString() }, this.ob); //if (dt1 != null && dt1.Rows.Count > 0) //{ // MessageUtil.ShowWarning("系统暂时不允许相同姓名的数据!\n若如确实存在相同名字情况,请暂时将名字区分一下!"); // return; //} DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature2", new object[] {ugr.Cells["USER_ID"].Text.Trim()}, ob); if (dt.Rows.Count > 0) { MessageUtil.ShowTips("已存在数据,不能进行此操作!"); return; } //StreamReader file = new StreamReader(fileName); //Image file= Image.FromFile(fileName); //file.to ArrayList list = new ArrayList(); list.Add(pline); list.Add(bz); list.Add(url); list.Add(userName); list.Add(ugr.Cells["REMARK"].Text.Trim()); list.Add(gx); list.Add(FileHelper.FileToArray(ugr.Cells["PIR"].Text.ToString())); list.Add(ugr.Cells["USERID_GRADE"].Text.ToString()); list1.Add(list); //} } //if (count == 0) //{ // MessageUtil.ShowTips("请选择要保存的数据!"); // return; //} if (MessageUtil.ShowYesNoAndQuestion("是否保存签名?") == System.Windows.Forms.DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage"; ccp.MethodName = "addMinStgnature"; ccp.ServerParams = new object[] { list1 }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Equals("新增成功!")) { DoQuery(); } } } private void DoDelete() { //int count = 0; ultraGrid1.UpdateData(); ArrayList pram1 = new ArrayList(); IQueryable uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'"); if (uGrid.Count() == 0) { MessageUtil.ShowTips("请选择要删除的数据!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认删除签名文件?") == System.Windows.Forms.DialogResult.No) { return; } foreach (UltraGridRow ugr in uGrid) { //if (Convert.ToBoolean(ugr.Cells["CHK"].Text) == true) //{ // count += 1; string craftFilePathOld = ugr.Cells["URL"].Text; if (FileHelper.Delete(craftFilePathOld) == false) { MessageUtil.ShowWarning("删除工艺文件失败,请重试!"); return; } ArrayList pram = new ArrayList(); pram.Add(ugr.Cells["USER_ID"].Value.ToString()); pram1.Add(pram); //} } //if (count == 0) //{ // MessageUtil.ShowWarning("请选择一条记录!"); // return; //} if (MessageUtil.ShowYesNoAndQuestion("是否删除签名?") == System.Windows.Forms.DialogResult.No) return; int countinsert = ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.deleteMinStgnature", new Object[] { pram1 }, this.ob); if (countinsert > 0) { MessageUtil.ShowTips("删除成功!"); } else { MessageUtil.ShowTips("删除失败!"); return; } DoQuery(); } private void DoUpdare() { ultraGrid1.UpdateData(); //int count = 0; ArrayList pram1 = new ArrayList(); IQueryable uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'"); if (uGrid.Count() == 0) { MessageUtil.ShowTips("请选择要修改的数据!"); return; } foreach (UltraGridRow ugr in uGrid) { //if (Convert.ToBoolean(ugr.Cells["CHK"].Text) == true) //{ // count += 1; //string craftFilePathOld = ugr.Cells["URL"].Text; //if (FileHelper.Delete(craftFilePathOld) == false) //{ // MessageUtil.ShowWarning("删除工艺文件失败,请重试!"); // return; //} //DoUpdateLoad(ugr); string gx=""; if (ugr.Cells["PROCESS_NO"].Text.Trim() != "") { gx = ugr.Cells["PROCESS_NO"].Value.ToString(); } ArrayList pram = new ArrayList(); pram.Add(ugr.Cells["COL_USER"].Value.ToString()); pram.Add(ugr.Cells["REMARK"].Text.Trim()); pram.Add(ugr.Cells["URL"].Value.ToString()); pram.Add(gx); //pram.Add(FileHelper.FileToArray(fileName)); pram.Add(ugr.Cells["USER_ID"].Value.ToString()); pram.Add(ugr.Cells["COL_GROUP"].Value.ToString()); pram.Add(ugr.Cells["USERID_GRADE"].Text.ToString()); //DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.querySameNameByUpdate", new object[] { ugr.Cells["COL_USER"].Value.ToString(), ugr.Cells["USER_ID"].Value.ToString() }, this.ob); //if (dt != null && dt.Rows.Count > 0) //{ // MessageUtil.ShowWarning("系统已存在相同名字的数据,系统暂时不支持!如果确实是不同人,请暂时在名字上加以区分!"); // return; //} pram1.Add(pram); //} } //if (count == 0) //{ // MessageUtil.ShowWarning("请选择一条记录!"); // return; //} if (MessageUtil.ShowYesNoAndQuestion("是否修改签名记录?") == System.Windows.Forms.DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage"; ccp.MethodName = "updateMinStgnature"; ccp.ServerParams = new object[] { pram1 }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Equals("修改成功!")) { DoQuery(); } } //int countinsert = ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.updateMinStgnature", new Object[] { pram1 }, this.ob); //if (countinsert > 0) //{ // MessageUtil.ShowTips("修改成功!"); //} //else //{ // MessageUtil.ShowTips("修改失败!"); return; //} //DoQuery(); } ///// ///// 修改时新增路径 ///// ///// //private void DoUpdateLoad(UltraGridRow row) //{ // string askSubItem = row.GetValue("PLINE_CODE"); // string bz = row.GetValue("COL_GROUP"); // string filePath = "ZGMil/Signature/" + askSubItem + "/" + bz + "/"; // FormFileDown down = new FormFileDown(this.ob, filePath); // down.CtrlFileDown1.FilePath = filePath; // //if (down.CtrlFileDown1.List.Count > 0) // //{ // // MessageUtil.ShowWarning("只能上传一份文件!"); // // return; // //} // List list = new List(); // FileBean bean = new FileBean(); // OpenFileDialog file = new OpenFileDialog(); // file.Multiselect = false; // DialogResult drStat; // drStat = file.ShowDialog(); // if (drStat == DialogResult.OK) // { // fileName = file.FileName; // FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); // long s = fs.Length; // if (s / 1024.0 > 20) // { // MessageUtil.ShowTips("图片大于20KB,请重新上传!"); // return; // } // string filena = System.IO.Path.GetFileName(fileName); // DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature2", new object[] { row.Cells["USER_ID"].Value.ToString() }, ob); // if (dt.Rows.Count > 0) // { // string seturl = dt.Rows[0]["SIGN_ROUTE"].ToString(); // bool isdelete = Core.Mes.Client.Comm.Server.FileHelper.Delete(seturl); // //ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.updateMinStgnature1", new object[] { filePath + filena, fileName, row.Cells["USER_ID"].Value.ToString() }, ob); // CoreClientParam ccp = new CoreClientParam(); // ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage"; // ccp.MethodName = "updateMinStgnature1"; // ccp.ServerParams = new object[] { filePath + filena, fileName, row.Cells["USER_ID"].Value.ToString() }; // ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); // if (ccp.ReturnCode == -1) { MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); return; } // } // bean = new FileBean(); // bean.setFileName(filena); // bean.setPathName(filePath); // bean.setFile(FileHelper.FileToArray(fileName)); // list.Add(bean); // bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list); // if (isSuccess) // { // MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); // } // else // { // MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); // } // ultraGrid1.ActiveCell.Value = filena; // ultraGrid1.ActiveRow.Cells["URL"].Value = filePath + filena; // } //} /// /// 上传 /// /// /// private void craftImg_EditorButtonClick(object sender, EditorButtonEventArgs e) { UltraGridRow row = ultraGrid1.ActiveRow; string askSubItem = row.GetValue("PLINE_CODE"); string bz = row.GetValue("COL_GROUP"); string filePath = "ZGMil/Signature/" + askSubItem + "/" + bz + "/"; if (e.Button.Key.ToLower().Equals("select")) { FormFileDown down = new FormFileDown(this.ob, row.Cells["URL"].Text); down.CtrlFileDown1.Button3.Visible = false; down.ShowDialog(); } if (e.Button.Key.ToLower().Equals("insert")) { if (askSubItem.Equals("") || bz.Equals("")) { MessageUtil.ShowTips("没有产线或班组不允许上传!"); return; } FormFileDown down = new FormFileDown(this.ob, filePath); down.CtrlFileDown1.FilePath = filePath; //if (down.CtrlFileDown1.List.Count > 0) //{ // MessageUtil.ShowWarning("只能上传一份文件!"); // return; //} List list = new List(); FileBean bean = new FileBean(); OpenFileDialog file = new OpenFileDialog(); file.Multiselect = false; DialogResult drStat; drStat = file.ShowDialog(); if (drStat == DialogResult.OK) { fileName = file.FileName; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); long s = fs.Length; if (s/1024.0>20) { MessageUtil.ShowTips("图片大于20KB,请重新上传!"); return; } string filena = System.IO.Path.GetFileName(fileName); DataTable dt = ServerHelper.GetData("com.steering.mes.signature.FrmTubeRollFileManage.queryMinStgnature2", new object[] { row.Cells["USER_ID"].Value.ToString() }, ob); if (dt.Rows.Count > 0) { string seturl = dt.Rows[0]["SIGN_ROUTE"].ToString(); bool isdelete = Core.Mes.Client.Comm.Server.FileHelper.Delete(seturl); //ServerHelper.SetData("com.steering.mes.signature.FrmTubeRollFileManage.updateMinStgnature1", new object[] { filePath + filena, fileName, row.Cells["USER_ID"].Value.ToString() }, ob); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.signature.FrmTubeRollFileManage"; ccp.MethodName = "updateMinStgnature1"; ccp.ServerParams = new object[] { filePath + filena, FileHelper.FileToArray(fileName), row.Cells["USER_ID"].Value.ToString() }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode == -1) { MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); return; } } bean = new FileBean(); bean.setFileName(filena); bean.setPathName(filePath); bean.setFile(FileHelper.FileToArray(fileName)); list.Add(bean); bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list); if (isSuccess) { MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } else { MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } ultraGrid1.ActiveCell.Value = filena; ultraGrid1.ActiveRow.Cells["URL"].Value = filePath + filena; ultraGrid1.ActiveRow.Cells["PIR"].Value = fileName; } } } private void ultraGrid1_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { try { ultraGrid1.UpdateData(); foreach (UltraGridRow r in ultraGrid1.Rows) { r.Cells["CHK"].Value = r.Selected; } } catch { } } } }