using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; using directPacking; using System.Text; using netDxf; using System.IO; using System.Data.OleDb; using System.Threading; using System.Linq; using MyGlassEdit.EDIT; using Utility; using MyGlassEdit.EDIT.功能; using MyGlassEdit.ng.optima.model; using MyGlassEdit.ng.optima.server; using ng.optima.server; using MyGlassEdit.EDIT.配置; using Newtonsoft.Json; using ng.optima.config; using MyGlassEdit.ng.optima.helper; namespace MyGlassEdit { public partial class 任务 : Form { #region 公共参数 public static OnePacking pack; public static Order simpleorder; public static OnePacking rootpack; public static 优化版面 banmian; public static 设备驱动 qudong; public static 报告 reportform; public static 人工排版 rengong; public static 手工排版.Form1 shouqie; public Order order = new Order(); public List stockTypeList = new List(); public DataTable polytable; public static int pagenumber = 0; public bool hasSaved = false; public static EdgeModel currentEdge; public static TrimModel currentTrimming; /// /// 是否是execl导入 /// public bool ImportXLSX = false; /// /// 打开的是否是李赛克工程 /// public bool IsLisic = false; /// /// 当前操作的工程号 /// public static string currentOperateProject = ""; public ProjectModel openProject; public string packingName = ""; public string currentGCH = ""; /// /// 手动模式 /// public bool ManualMode = false; /// /// 当前小片行 /// int currentPolyRow = 0; /// /// 当前原片行 /// int currentStockRow = 0; public static bool useOffcut = false;//是否使用了余料 List currentProcessList = new List();//用于记录当前工程的流程卡数据,设置磨量时使用 Dictionary dicRowAndNum = new Dictionary(); #endregion #region 提示类 string strClearInfoConfirm = "是否确定清空当前显示信息"; string strNoOpimtizeAlert = "当前工程状态优化后无法保存,是否确认优化?"; string strProjectIsNull = "工程号为空,不可优化!"; string strNoResult = "没有优化结果"; string strStateError = "工程状态异常,无法保存!"; string strSaved = "当前工程已保存!"; string strSaveSuccess = "保存成功!"; string strProjectNoResult = "当前工程的优化结果不存在"; string filtertext = "请输入关键字"; #endregion public 任务() { int step = 0; string errMsg = ""; try { if (Setting.language == 1) { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en"); strClearInfoConfirm = "Are you sure to clear the current displayed information?"; strNoOpimtizeAlert = "The current project status cannot be saved after optimization. Do you want to confirm the optimization?"; strProjectIsNull = "The project number is empty"; strNoResult = "No optimization results"; strStateError = "Abnormal status, unable to save!"; strSaved = "The current project has been saved"; strSaveSuccess = "Successfully saved"; strProjectNoResult = "The optimization result of the current project does not exist"; filtertext = "Enter Keyword"; } else if (Setting.language == 2) { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ru"); } InitializeComponent(); step = 1; errMsg = "设置读取存在异常,请检查原因"; SystemConfig.ReadSet(); //displayByVersion(); step = 2; errMsg = "初始化异常,请检查原因"; banmian = new 优化版面(this); step = 3; errMsg = "初始化异常,请检查原因"; qudong = new 设备驱动(this); step = 4; errMsg = "报告页初始化异常,请检查原因"; reportform = new 报告(this, ShowPro2); step = 5; rengong = new 人工排版(this); step = 6; shouqie = new 手工排版.Form1(); PermissionControlDisplay(); } catch (Exception ex) { MessageBox.Show(step.ToString() + "\r\n" + errMsg); errorInfo(ex); } } /*异常信息捕获*/ private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); void errorInfo(Exception ex) { StringBuilder sb = new StringBuilder(); while (ex != null) { sb.AppendFormat("捕获到未处理异常:{0}\r\n异常信息:{1}\r\n异常堆栈:{2}\r\n方法{3}", ex.GetType(), ex.Message, ex.StackTrace, ex.TargetSite); ex = ex.InnerException; Logger.Error(ex, "任务.cs:174"); } globel.ShowMessage("errorInfo: " + sb.ToString()); } public void initialize() { //erp模式对按钮进行管理 Setting.freeEdition = false; //VersionTest.freeEdition() || Setting.isBlackDog; //Setting.refreshVersionByDog(); //DogIDTxt.Text = VersionTest.KeyID(); //注册加密狗插拔通知 //RegisterDeviceNotification(); //packingOrder = getFileName(); //packingName = "Project" + packingOrder; FilesPathCheck(); } #region 保存工程文件 public void SaveClick() { return; if (MyGlassEdit.globel.withoutbtfile) { return; } if (任务.rootpack != null) saveProject(任务.rootpack); else saveProject(任务.pack); } public void saveProject(OnePacking pack) { if (pack == null) return; setSimpleOrder(); if (pack.stocks.Count > 0) pack.stocks[0].glassType = cmbGlassType.Text.Trim(); MyGlasFile myglassfile = new MyGlasFile(pack, simpleorder); string filename = Setting.btdir + "\\工程文件\\" + pack.packingName + ".bt"; if (ImportXLSX == false) { //Sava0ptimizedata(pack.packingName); } //if (myglassfile.SaveFile(filename)) { } } #endregion public void setSimpleOrder() { simpleorder = DB.GetPolygonList(polyView, txtProjectNo.Text.ToString(), cmbGlassType.Text.ToString()); } /******************************* * * * * * * * */ public void drawPack() { if (pack == null) return; if (pack.stocks.Count == 0) return; banmian.FormBorderStyle = FormBorderStyle.None; banmian.TopLevel = false; banmian.Dock = DockStyle.Fill; banmian.AutoScaleMode = AutoScaleMode.None; youhuaTab.Controls.Clear(); youhuaTab.Controls.Add(banmian); //banmian.saveProject(pack); banmian.pack = pack; rengong.pack = pack; banmian.drawPack(); alermInfo.Text = (pack.yuanpianbuzu ? "原片不足" : ""); banmian.Show(); mainTab.SelectedIndex = 1; } #region 菜单栏导航切换 private void c1DockingTab1_SelectedIndexChanged(object sender, EventArgs e) { switch (mainTab.SelectedIndex) { case 1://套料图 { if (IsLisic) return; if (pack == null) return; if (pack.stocks.Count == 0) return; banmian.FormBorderStyle = FormBorderStyle.None; banmian.TopLevel = false; banmian.Dock = DockStyle.Fill; banmian.AutoScaleMode = AutoScaleMode.None; youhuaTab.Controls.Clear(); youhuaTab.Controls.Add(banmian); //banmian.saveProject(pack); banmian.drawPack(); banmian.Show(); break; } case 2://人工调整 { if (IsLisic) return; if (pack == null) return; if (pack.stocks.Count == 0) return; rengong = new 人工排版(this); rengong.pack = pack; rengong.FormBorderStyle = FormBorderStyle.None; rengong.TopLevel = false; rengong.Dock = DockStyle.Fill; rengong.AutoScaleMode = AutoScaleMode.None; shoupaiTab.Controls.Clear(); shoupaiTab.Controls.Add(rengong); rengong.Show(); rengong.drawPack(); rengong.pictureBoxmousedown(100, 100); break; } case 3://设备驱动 { if (IsLisic) return; if (pack == null) return; if (pack.stocks.Count == 0) return; qudong.FormBorderStyle = FormBorderStyle.None; qudong.TopLevel = false; qudong.Dock = DockStyle.Fill; qudong.AutoScaleMode = AutoScaleMode.None; cutLineTab.Controls.Clear(); cutLineTab.Controls.Add(qudong); qudong.Show(); qudong.displayDXF(new List()); qudong.displayTree(); break; } case 4: //手工切割 { if (IsLisic) return; // shouqie = new 手工排版.Form1(); shouqie.FormBorderStyle = FormBorderStyle.None; shouqie.TopLevel = false; shouqie.Dock = DockStyle.Fill; shouqie.AutoScaleMode = AutoScaleMode.None; shouqieTab.Controls.Clear(); shouqieTab.Controls.Add(shouqie); shouqie.Show(); break; } case 5://优化报告 { if (IsLisic) return; if (pack == null) return; if (pack.stocks.Count == 0) return; reportform.pack = pack; reportform.FormBorderStyle = FormBorderStyle.None; reportform.TopLevel = false; reportform.Dock = DockStyle.Fill; reportform.AutoScaleMode = AutoScaleMode.None; reportTab.Controls.Clear(); reportTab.Controls.Add(reportform); reportform.ResultTabControl.SelectedIndex = 0; //reportform.showIndex = 0; reportform.Show(); //ddd reportform.printReport(); break; } case 6: //标签 { if (IsLisic) return; if (pack == null) return; if (pack.stocks.Count == 0) return; reportform.pack = pack; reportform.FormBorderStyle = FormBorderStyle.None; reportform.TopLevel = false; reportform.Dock = DockStyle.Fill; reportform.AutoScaleMode = AutoScaleMode.None; biaoqianTab.Controls.Clear(); biaoqianTab.Controls.Add(reportform); reportform.start1.Text = "1"; reportform.end.Text = pack.mergedstocks.Count.ToString(); //reportform.ResultTabControl.SelectedIndex = 1; reportform.ResultTabControl.SelectedIndex = 0; reportform.Show(); break; } } } #endregion #region 窗体加载 private void Optimization_Load(object sender, EventArgs e) { try { ButtonEventLoading(); DGVGlassDetailsRigthClickOperation(2); ConfigDB.ReadEdgeConfig(); ConfigDB.ReadTrimmingConfig(); if (directPacking.Setting.btdir.Contains("D:") && !Directory.Exists("D:\\"))//目录自适应 { directPacking.Setting.btdir = directPacking.Setting.btdir.Replace("D:", "E:"); Setting.UpdateSetting(); } ProhibitColumnSorting(); //mainTab.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.mainTab_DrawItem); initialize(); //displayByVersion(); this.MouseWheel += 任务_MouseWheel; if (polyView.Rows.Count > 0 && polyView.Rows[0].Cells["形状"].Value == null) { setblankmap(polyView.Rows[0].Cells["形状"]); } DoubleBuffered = true; // 启用双缓冲 containerShow(); removeX(); mainTab.SelectedIndex = 0; polyView.AllowUserToAddRows = false; s.Columns.Clear(); //TSMIUserInfo.Text = "" + LoginAdminInfo.login_name; TSMIUserInfo.Text = "" + LoginAdminInfo.name; // 如果需要设置具体的行高(单位为像素),可以使用DataGridView的RowTemplate属性 polyView.RowTemplate.Height = 25; // 将默认行高设置为25像素 stockView.RowTemplate.Height = 25; // 将默认行高设置为25像素 if (globel.UserGroup == "补片") { createPatchProject(); //txtProjectNo.Text = PatchProjectDB.getPatchProjectNo(); //txtProjectNo.Text = ProjectDB.CreateProject(0); //projectnameText.Text = "现补"; //openProject = new ProjectModel() //{ // project_no = txtProjectNo.Text, // state = 10, // strRemark = "现补工程" // //name = projectnameText.Text ="手动工程", //}; } txtFilter.Text = filtertext; } catch (Exception ex) { errorInfo(ex); } } #endregion #region 小片列表禁止自动排序 /// /// 小片列表禁止自动排序 /// void ProhibitColumnSorting() { for (int i = 0; i < this.polyView.Columns.Count; i++) { this.polyView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; if (i > 0 && i < 4) { //this.polyView.Columns[i].Width = 200; polyView.Columns[i].ReadOnly = true; } else if (i > 5 && i < 10) { polyView.Columns[i].ReadOnly = false; } else { polyView.Columns[i].ReadOnly = true; } if (polyView.Columns[i].Name == "流程卡号" || polyView.Columns[i].Name == "楼层编号" || polyView.Columns[i].Name == "单片名称") { polyView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } } } #endregion #region 文件路径校验 /// /// 文件路径校验 /// void FilesPathCheck() { if (!Directory.Exists(Setting.btdir + "\\优化版图\\")) Directory.CreateDirectory(Setting.btdir + "\\优化版图\\"); if (!Directory.Exists(Setting.btdir + "\\优化报告\\")) Directory.CreateDirectory(Setting.btdir + "\\优化报告\\"); if (!Directory.Exists(Setting.btdir + "\\工程文件\\")) Directory.CreateDirectory(Setting.btdir + "\\工程文件\\"); if (!Directory.Exists(Setting.btdir + "\\版图报告\\")) Directory.CreateDirectory(Setting.btdir + "\\版图报告\\"); if (!Directory.Exists(Setting.btdir + "\\模拟计算记录\\")) Directory.CreateDirectory(Setting.btdir + "\\模拟计算记录\\"); if (!Directory.Exists(Setting.btdir + "\\测试日志\\")) Directory.CreateDirectory(Setting.btdir + "\\测试日志\\"); } #endregion void 任务_MouseWheel(object sender, MouseEventArgs e) { if (mainTab.SelectedIndex == 1 && banmian != null) { if (e.Delta > 60) { banmian.PreviousPage(pack); } else if (e.Delta < -60) banmian.nextPage(pack); } } private void setblankmap(DataGridViewCell cell) { Bitmap map = new Bitmap(polyView.Columns["形状"].Width, polyView.Rows[cell.RowIndex].Height); Graphics g = Graphics.FromImage(map); g.Clear(cell.Style.BackColor); cell.Value = map; } private void 增加异形_Click(object sender, EventArgs e) { polyView.AllowUserToAddRows = true; 选择模板 geo = new 选择模板(this); geo.ShowDialog(); if (string.IsNullOrEmpty(txtProjectNo.Text)) { ManualProject(); } } /// /// 手动工程 /// void ManualProject() { int r = new Random().Next(10, 99); openProject = new ProjectModel() { project_no = txtProjectNo.Text = "SD" + DateTime.Now.ToString("yyyyMMdd") + r, state = 1, //name = projectnameText.Text ="手动工程", }; ManualMode = true; //TODO 获取工程号 } #region 优化 public bool packisrect; public string getOrdernameList() { List list = new List(); for (int i = 0; i < polyView.Rows.Count; i++) { if (polyView.AllowUserToAddRows && i == polyView.Rows.Count - 1) break; string ordername = polyView.Rows[i].Cells["宽度"].Value.ToString(); if (!list.Contains(ordername)) list.Add(ordername); } string ordernamelist = ""; for (int i = 0; i < list.Count; i++) if (ordernamelist == "") ordernamelist = list[i];//words[0]存储了客户名-订单名 else ordernamelist = ordernamelist + "," + list[i]; return ordernamelist; } public float[,] getStockSize() { int thick = 0; Int32.TryParse(cmbGlassThick.Text.Trim(), out thick); List stocks = DB.getStockTypeList(stockView, cmbGlassType.Text.Trim(), thick); float[,] result = new float[stocks.Count, 2]; for (int i = 0; i < stocks.Count; i++) { result[i, 0] = stocks[i].Width; result[i, 1] = stocks[i].Height; } return result; } /// /// 设定polyview是否可以编辑 /// /// public void taskEnabled(bool enabled = false) { if (enabled) { for (int j = 0; j < polyView.Rows.Count; j++) { if (polyView.Rows[j].Cells["模板号"].Value != null && polyView.Rows[j].Cells["模板号"].Value.ToString().Trim() == "100") { for (int c = 0; c < polyView.Columns.Count; c++) { if (c < 6 || c > 9) { polyView.Rows[j].Cells[c].ReadOnly = false; polyView.Rows[j].Cells[c].Style.ForeColor = Color.Gray; } } } else { for (int c = 0; c < polyView.Columns.Count; c++) { polyView.Rows[j].Cells[c].ReadOnly = false; polyView.Rows[j].Cells[c].Style.ForeColor = Color.Gray; } } } } else { for (int j = 0; j < polyView.Rows.Count; j++) { if (polyView.Rows[j].Cells["模板号"].Value != null && polyView.Rows[j].Cells["模板号"].Value.ToString().Trim() == "100") { for (int c = 0; c < polyView.Columns.Count; c++) { if (c < 6 || c > 9) { polyView.Rows[j].Cells[c].ReadOnly = true; polyView.Rows[j].Cells[c].Style.ForeColor = Color.Gray; } } } else { for (int c = 0; c < polyView.Columns.Count; c++) { polyView.Rows[j].Cells[c].ReadOnly = true; polyView.Rows[j].Cells[c].Style.ForeColor = Color.Gray; } } polyView.Rows[j].Cells["架号"].ReadOnly = false; } } } public void norenwudan() { setColumnEnabled(); cmbGlassType.Enabled = true; cmbGlassThick.Enabled = true; Setting.renwudantable = null; Setting.glasstype = ""; Setting.thick = ""; ids = null; } public void Optimize(string g_thickness, string g_type) { starttime = DateTime.Now; int thick = 0; Int32.TryParse(g_thickness, out thick); stockTypeList = DB.getStockTypeList(stockView, g_type.Trim(), thick);//得到 stockTypeList order = DB.expandPolygonList(polyView, txtProjectNo.Text, g_type.ToString(), getStockSize(), stockTypeList); for (int i = 0; i < order.polygonList.Count; i++) { if (order.polygonList[i].ordername.Trim() == "") order.polygonList[i].ordername = txtProjectNo.Text.Trim(); } for (int i = 0; i < order.polygonList.Count; i++) { order.polygonList[i].projectname = txtProjectNo.Text.Trim(); } if (order.recOrder()) { directPacking.Setting.isRecPacking = true; } else { directPacking.Setting.isRecPacking = false; } if (Setting.isRectEdition && !directPacking.Setting.isRecPacking) { globel.ShowFromMessage("矩形版本无法优化异形,请联系软件厂家购买异形软件,销售电话13818957981"); return; } SinglePolyOptimize(order, g_thickness, g_type); } private delegate void ProgressBarShow(int i); private void ShowPro(int level) { if (this.InvokeRequired) { this.Invoke(new ProgressBarShow(ShowPro), level); } else { if (level > progressBar1.Maximum) { level = progressBar1.Maximum; } progressBar1.Value = level; if (Setting.language == 0) { optlabel.Text = "优化时间:" + Setting.runningtime.Minutes.ToString() + "分" + Setting.runningtime.Seconds.ToString() + "秒 优化进度(" + (optcount + 1).ToString() + "/" + Setting.optcount.ToString() + "):" + (int)((double)level / progressBar1.Maximum * 100) + "%"; } else { optlabel.Text = "Optimization Time:" + Setting.runningtime.Minutes.ToString() + "min " + Setting.runningtime.Seconds.ToString() + "s Optimization Progress:" + (int)((double)level / progressBar1.Maximum * 100) + "%"; } if (level == progressBar1.Maximum) { optcount++; progressBar1.Value = 0; Setting.polycount = 0; if (optcount == Setting.optcount) { mainTab.SelectedIndex = 1; progressBar1.Visible = false; } } } } private void ShowPro2(int level) { if (this.InvokeRequired) { this.Invoke(new ProgressBarShow(ShowPro2), level); } else { optlabel.Visible = true; if (level > progressBar1.Maximum) level = progressBar1.Maximum; progressBar1.Value = level; if (Setting.printlabel) { if (Setting.language == 0) { optlabel.Text = "标签生成进度:" + (int)((double)level / progressBar1.Maximum * 100) + "%"; } else { optlabel.Text = "Label Progress:" + (int)((double)level / progressBar1.Maximum * 100) + "%"; } } else { if (Setting.language == 0) { optlabel.Text = "生成进度:" + (int)((double)level / progressBar1.Maximum * 100) + "%"; } else { optlabel.Text = "Report Progress:" + (int)((double)level / progressBar1.Maximum * 100) + "%"; } } if (Math.Abs(level - progressBar1.Maximum) < 1) { progressBar1.Value = 0; progressBar1.Visible = false; optlabel.Visible = false; } } } #endregion int optcount; /// /// 单玻异形优化 /// /// /// /// private void SinglePolyOptimize(Order order, string g_thickness, string g_type) { //多原片排样 if (stockTypeList == null || stockTypeList.Count == 0) { //pack = null; globel.ShowFromWarningMessage(Setting.language == 0 ? "请选择原片" : "Please choose raw sheets"); return; } if (order.polygonList.Count == 0) { globel.ShowFromWarningMessage(Setting.language == 0 ? "成品列表为空" : "No piece"); return; } if (!order.canallputin(stockTypeList)) { globel.ShowFromWarningMessage(Setting.language == 0 ? "第【" + order.wrongRownum + "】行成品超过所选原片尺寸,无法完成排样。" : "Raw sheets selected not enough.Row No.【" + order.wrongRownum + "】"); return; } cmbGlassThick.Enabled = false; cmbGlassType.Enabled = false; if (pack != null && pack.optEnviroument.Split(',').Length == 3 && pack.optEnviroument.Split(',')[1] == Functions.getoptParas() && Functions.isEqual(simpleorder.polygonList, DB.GetPolygonList(polyView, txtProjectNo.Text, g_type).polygonList) && Functions.isEqual(pack.originStocks, stockTypeList)) //重新优化 { foreach (Stock stock in pack.stocks) { stock.glassType = g_type.Trim(); stock.Thickness = Convert.ToInt16(g_thickness); } pack.polygonList = DB.expandPolygonList(polyView, this.txtProjectNo.Text, g_type.ToString(), getStockSize(), stockTypeList).polygonList; 优化进度 form = new 优化进度(this, pack); form.Show(); } else { 优化进度 form = new 优化进度(this, null); form.Show(); } } private void polyView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { polyView.CurrentCell = polyView[e.ColumnIndex, e.RowIndex]; polyView.BeginEdit(true); } } private void stockView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { GridViews.DGVAddRowIndex(stockView, e); } /// /// optima优化结果 /// List optimaContent = new List(); private void 优化_Click(object sender, EventArgs e) { if (!ManualMode && openProject == null) { return; } //状态-2 表示已删除 >10表示已经优化保存过 if (openProject.state == -2 || openProject.state > 10) { if (!globel.ShowFromConfirmMessage(strNoOpimtizeAlert)) { return; } } int r = polyView.AllowUserToAddRows ? polyView.RowCount - 1 : polyView.RowCount; if (r == 0) { return; } string gongcheng = txtProjectNo.Text.Trim(); if (string.IsNullOrEmpty(gongcheng)) { globel.ShowFromWarningMessage(strProjectIsNull); return; } if (pack != null && !Setting.settingchaged) { mainTab.SelectedIndex = 1; return; } //saveCommonSize(); //polyView.AllowUserToAddRows = true; if (checkData()) { packisrect = true; for (int i = 0; i < polyView.Rows.Count; i++) { if (polyView.AllowUserToAddRows && i == polyView.Rows.Count - 1) break; if (polyView.Rows[i].Cells["Str"].Value == null) { float width = (float)Convert.ToDouble(polyView.Rows[i].Cells["宽度"].Value.ToString()); float height = (float)Convert.ToDouble(polyView.Rows[i].Cells["高度"].Value.ToString()); int tempnumber = Convert.ToInt32(polyView.Rows[i].Cells["模板号"].Value.ToString()); if (tempnumber == 100) { Polygon poly = Tranform.trans(100, height, 0, 0, width, 0, 0, 0, 0, 0); polyView.Rows[i].Cells["Str"].Value = poly.ABS_Serialize()[0]; } } if (packisrect) { int polynumber; Int32.TryParse(polyView.Rows[i].Cells["模板号"].Value.ToString().Trim(), out polynumber); if (polynumber != 100) packisrect = false; } } packingName = projectnameText.Text + txtProjectNo.Text; Setting.UpdateSetting(); string glass_thickness = cmbGlassThick.Text.Trim(); string glass_type = cmbGlassType.Text.Trim(); Logger.Info($"进行了优化:{txtProjectNo.Text}"); Optimize(glass_thickness, glass_type);//优化 packisrect = true; Setting.settingchaged = false; PorjectLogDB.InsertProjectOperationLog(new PorjectLogModel() { project_no = txtProjectNo.Text.Trim(), operate_no = 3, operate_detail = null }); } } #region 设置成品列表列属性 private void setColumnEnabled() { polyView.Columns["宽度"].Width = 100; polyView.Columns["高度"].Width = 100; polyView.Columns["数量"].Width = 100; for (int j = 0; j < polyView.Columns.Count; j++) { if (j < 5 && j < 10) { polyView.Columns[j].ReadOnly = false; } else if (j != 10 && j != 19) { polyView.Columns[j].ReadOnly = false; polyView.Columns[j].DefaultCellStyle.ForeColor = Color.Black; } else { polyView.Columns[j].ReadOnly = true; polyView.Columns[j].DefaultCellStyle.ForeColor = Color.Gray; } } } #endregion #region 增加成品 public void addToGrid(Polygon poly, string filename = "")//增加操作,来自模板文件 { poly.refresh(); poly.setDistance(); poly.setArea(); DataGridViewRow gridrow = new DataGridViewRow(); foreach (DataGridViewCell c in polyView.Rows[0].Cells) { gridrow.Cells.Add(c.Clone() as DataGridViewCell); } gridrow.Height = 30; poly.setWidthHeight(false, true); gridrow.Cells[0].Value = polyView.Rows.Count.ToString(); //成品号 gridrow.Cells[1].Value = Functions.decimalconvert(poly.width); gridrow.Cells[2].Value = Functions.decimalconvert(poly.height); int btdxfcount = 0; if (poly.orderid.Length > 9 && poly.orderid.Substring(0, 5) == "BTDXF" && Int32.TryParse(poly.orderid.Substring(poly.orderid.LastIndexOf('_') + 1), out btdxfcount)) { gridrow.Cells[3].Value = btdxfcount.ToString(); } else { gridrow.Cells[3].Value = poly.count.ToString();//数量 } gridrow.Cells[4].Value = poly.temp_number.ToString();//形状 gridrow.Cells[5].Value = poly.ABS_Serialize()[0]; gridrow.Cells[6].Value = "0"; gridrow.Cells[7].Value = "0"; gridrow.Cells[8].Value = "0"; gridrow.Cells[9].Value = "0"; gridrow.Cells[11].Value = ""; gridrow.Cells[12].Value = ""; gridrow.Cells[13].Value = poly.orderid; gridrow.Cells[14].Value = ""; gridrow.Cells[15].Value = "0.0"; gridrow.Cells[16].Value = filename; gridrow.Cells[17].Value = ""; gridrow.Cells[18].Value = false; gridrow.Cells[19].Value = Functions.decimalconvert(poly.width * poly.height * Math.Pow(10, -6)); gridrow.Cells[21].Value = poly.originjiahao;//23.10.10 添加 //显示缩略图在最后一列 Polygon temppoly = new Template().getTempPoly(poly.temp_number); temppoly.refresh(); temppoly.setDistance(); temppoly.lineWidth = 1; temppoly.distanceColor = System.Drawing.Color.White; double ratio = 0.7 * (float)gridrow.Height / Math.Max(temppoly.width, temppoly.height); Bitmap tempmap = new Bitmap(gridrow.Height, gridrow.Height); Graphics g = Graphics.FromImage(tempmap); temppoly.drawTemplate(g, ratio); gridrow.Cells[10].Value = tempmap; if (polyView.Rows.Count > 1) { gridrow.Cells[11].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["加工信息"].Value; gridrow.Cells[12].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["客户名称"].Value; if (gridrow.Cells[13].Value.ToString().Trim() == "") gridrow.Cells[13].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["流程卡号"].Value; gridrow.Cells[14].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["产品名称"].Value; gridrow.Cells[15].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["单价"].Value; // gridrow.Cells[16].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["备注"].Value; // gridrow.Cells[17].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["备注"].Value; } polyView.Rows.Add(gridrow); polyView.CurrentCell = polyView[1, polyView.Rows.Count - 2]; polyView.BeginEdit(true); mainTab.SelectedIndex = 0; CountPolyNumberOrArea(); } public void addToGrid(DxfDocument dxf, dxfPolygon currentdxf, int count, string orderid)//增加操作,来自DXF文件 { double minX, maxX, minY, maxY; dxf.FindBoundary(out maxX, out minX, out maxY, out minY); double width = (double)(maxX - minX); double height = (double)(maxY - minY); if ((int)(width + 1) - width <= 0.1) { width = (int)(width + 1); } if ((int)(height + 1) - height <= 0.1) { height = (int)(height + 1); } DataGridViewRow gridrow = new DataGridViewRow(); foreach (DataGridViewCell c in polyView.Rows[0].Cells) { gridrow.Cells.Add(c.Clone() as DataGridViewCell); } gridrow.Cells[0].Value = currentdxf.left + "," + currentdxf.right + "," + currentdxf.top + "," + currentdxf.down; gridrow.Cells[1].Value = Functions.decimalconvert(width); gridrow.Cells[2].Value = Functions.decimalconvert(height); int btdxfcount = 0; if (orderid.Length > 9 && orderid.Substring(0, 5) == "BTDXF" && Int32.TryParse(orderid.Substring(orderid.LastIndexOf('_') + 1), out btdxfcount)) gridrow.Cells[3].Value = btdxfcount.ToString(); else gridrow.Cells[3].Value = count.ToString(); gridrow.Cells[4].Value = "0"; gridrow.Cells[5].Value = currentdxf.ABS_Serialize(); gridrow.Cells[6].Value = "0"; gridrow.Cells[7].Value = "0"; gridrow.Cells[8].Value = "0"; gridrow.Cells[9].Value = "0"; gridrow.Cells[11].Value = ""; gridrow.Cells[12].Value = ""; gridrow.Cells[13].Value = "";//文件名当订单编号 gridrow.Cells[14].Value = ""; gridrow.Cells[15].Value = "0.0"; gridrow.Cells[16].Value = orderid; gridrow.Cells[17].Value = ""; gridrow.Cells[18].Value = false; gridrow.Cells[19].Value = Functions.decimalconvert(width * height * Math.Pow(10, -6)); gridrow.Cells[10].Value = 导入DXF.getdxfmap(System.Drawing.Color.LightSteelBlue, dxf, gridrow.Height, gridrow.Height); gridrow.Cells[21].Value = "A01";//架子号 if (polyView.Rows.Count > 1) { gridrow.Cells[11].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["加工信息"].Value; gridrow.Cells[12].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["客户名称"].Value; if (gridrow.Cells[13].Value.ToString().Trim() == "") gridrow.Cells[13].Value = polyView.Rows[polyView.Rows.Count - 2].Cells["流程卡号"].Value; //gridrow.Cells[14].Value = polyView.Rows[polyView.Rows.Count - 2].Cells[14].Value; //gridrow.Cells[15].Value = polyView.Rows[polyView.Rows.Count - 2].Cells[15].Value; //gridrow.Cells[16].Value = polyView.Rows[polyView.Rows.Count - 2].Cells[16].Value; //gridrow.Cells[17].Value = polyView.Rows[polyView.Rows.Count - 2].Cells[17].Value; } polyView.Rows.Add(gridrow); polyView.CurrentCell = polyView[1, polyView.Rows.Count - 2]; polyView.BeginEdit(true); mainTab.SelectedIndex = 0; CountPolyNumberOrArea(); } #region 修改小片图形 public bool updateToGrid(Polygon poly, int i) { int cw = 0;//用于错误位置判断 try { cw = 1; poly.refresh(); poly.setDistance(); poly.setArea(); cw = 2; int yxHeight = 25; polyView.Rows[i].Cells["Str"].Value = poly.ABS_Serialize()[0]; polyView.Rows[i].Cells[4].Value = poly.temp_number.ToString();//形状 //显示缩略图在最后一列 Polygon temppoly = new Template().getTempPoly(poly.temp_number); temppoly.refresh(); temppoly.setDistance(); temppoly.lineWidth = 1; temppoly.distanceColor = System.Drawing.Color.White; double ratio = 0.7 * (float)yxHeight / Math.Max(temppoly.width, temppoly.height); Bitmap tempmap = new Bitmap(yxHeight, yxHeight); Graphics g = Graphics.FromImage(tempmap); temppoly.drawTemplate(g, ratio); polyView.Rows[i].Cells[10].Value = tempmap; //polyView.CurrentCell = polyView[1, polyView.Rows.Count - 2]; cw = 10; polyView.BeginEdit(true); mainTab.SelectedIndex = 0; cw = 11; return true; } catch (Exception ex) { globel.ShowFromErrorMessage(cw + ":" + ex.Message); //throw; return false; } } #endregion private void polyView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { int rowNum = polyView.AllowUserToAddRows ? polyView.Rows.Count - 1 : polyView.Rows.Count; if (e.ColumnIndex >= 0 && polyView.Columns[e.ColumnIndex].Name == "形状" && e.RowIndex <= rowNum)//双击预览 { if (polyView.AllowUserToAddRows && e.RowIndex == polyView.Rows.Count - 1) return; currentPolyRow = e.RowIndex; if (currentPolyRow < 0 || currentPolyRow >= polyView.Rows.Count) return; //2023.10.31 新增 //模板号为空的跳过 //模板号为0的异形,可选择异形模板 //str列为空的跳过 if (polyView.Rows[currentPolyRow].Cells["模板号"].Value == null) { return; } if (globel.ShapeOptima) { if (polyView.Rows[currentPolyRow].Cells["模板号"].Value.ToString() == "0") { float k = Convert.ToInt64(polyView.Rows[currentPolyRow].Cells["宽度"].Value); float g = Convert.ToInt64(polyView.Rows[currentPolyRow].Cells["高度"].Value); updateyixing_Click(e.RowIndex, k, g); return; } } if (polyView.Rows[currentPolyRow].Cells["Str"].Value == null) { return; } //结束 if (Convert.ToInt32(polyView.Rows[currentPolyRow].Cells["模板号"].Value.ToString().Trim()) != 0 && polyView.Rows[currentPolyRow].Cells["Str"].Value != null //23.10.10 添加 ) { Polygon poly = new Polygon(); poly.ABS_Deserialize(polyView.Rows[currentPolyRow].Cells["Str"].Value.ToString()); Polygon p = poly.Expand(false); 预览 yulan = new 预览(p.ABS_Serialize()[0], Convert.ToInt32(polyView.Rows[currentPolyRow].Cells["模板号"].Value.ToString().Trim())); yulan.ShowDialog(); } else { 预览 yulan = new 预览(polyView.Rows[currentPolyRow].Cells["Str"].Value.ToString(), Convert.ToInt32(polyView.Rows[currentPolyRow].Cells["模板号"].Value.ToString().Trim())); yulan.ShowDialog(); } } return; if (globel.ShapeOptima) { //双击最后一行录入异形 if (e.ColumnIndex >= 0 && (polyView.Columns[e.ColumnIndex].Name == "宽度" || polyView.Columns[e.ColumnIndex].Name == "高度") && e.RowIndex < polyView.Rows.Count) { // if (polyView.AllowUserToAddRows && e.RowIndex == polyView.Rows.Count - 1) return; currentPolyRow = e.RowIndex; if (currentPolyRow == polyView.Rows.Count - 1) addyixing_Click(sender, e); else { } } } } DateTime starttime; #endregion #region 导入Excel //从【Optima】的表格读取成品 void inputPolygonFromOptima(string filename, string sheetname) { try { string strCon = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; OleDbConnection strConn = new OleDbConnection(strCon); string strSql = "select * from [" + sheetname + "]"; try { strConn.Open(); } catch { strCon = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; strConn = new OleDbConnection(strCon); strConn.Open(); } OleDbDataAdapter strCom = new OleDbDataAdapter(strSql, strConn); DataSet ds = new DataSet(); strCom.Fill(ds, "[" + sheetname + "]"); strConn.Close(); string s1 = ""; DataRow row; for (int i = 0; i < ds.Tables["[" + sheetname + "]"].Rows.Count; i++) { s1 = ""; row = ds.Tables["[" + sheetname + "]"].Rows[i]; s1 += i.ToString(); for (int j = 0; j < row.ItemArray.Length; j++) { s1 += "$" + row[j].ToString().Trim(); } polyView.Rows.Add(DisplayPack.PolyNewRowFromOptima(polyView, s1)); } } catch { return; } } //从【派尔】的表格读取成品 void inputPolygonFromPier(string filename, string sheetname) { try { string strCon = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; OleDbConnection strConn = new OleDbConnection(strCon); string strSql = "select * from [" + sheetname + "]"; try { strConn.Open(); } catch { strCon = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; strConn = new OleDbConnection(strCon); strConn.Open(); } OleDbDataAdapter strCom = new OleDbDataAdapter(strSql, strConn); DataSet ds = new DataSet(); strCom.Fill(ds, "[" + sheetname + "]"); strConn.Close(); string s1 = ""; DataRow row; for (int i = 0; i < ds.Tables["[" + sheetname + "]"].Rows.Count; i++) { s1 = ""; row = ds.Tables["[" + sheetname + "]"].Rows[i]; s1 += i.ToString(); for (int j = 0; j < row.ItemArray.Length; j++) { s1 += "$" + row[j].ToString().Trim(); } polyView.Rows.Add(DisplayPack.PolyNewRowFromPier(polyView, s1)); } } catch { return; } } //从【比藤矩形】的表格读取成品 void inputPolygonFromBtRect(string filename, string sheetname) { try { string strCon = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; OleDbConnection strConn = new OleDbConnection(strCon); string strSql = "select * from [" + sheetname + "]"; try { strConn.Open(); } catch { strCon = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; strConn = new OleDbConnection(strCon); strConn.Open(); } OleDbDataAdapter strCom = new OleDbDataAdapter(strSql, strConn); DataSet ds = new DataSet(); strCom.Fill(ds, "[" + sheetname + "]"); strConn.Close(); string s1 = ""; DataRow row; for (int i = 0; i < ds.Tables["[" + sheetname + "]"].Rows.Count; i++) { s1 = ""; row = ds.Tables["[" + sheetname + "]"].Rows[i]; s1 += i.ToString(); for (int j = 0; j < row.ItemArray.Length; j++) { s1 += "$" + row[j].ToString().Trim(); } polyView.Rows.Add(DisplayPack.PolyNewRowFromBtRect(polyView, s1)); } } catch { return; } } //从【比藤】的表格读取成品 public Dictionary> ids;//行号及对应的小片编号 void inputPolygonFromBitteng(string filename, string sheetname, bool fromerp = false) { //try //{ if (fromerp) { ids = new Dictionary>(); } string strCon = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; OleDbConnection strConn = new OleDbConnection(strCon); string strSql = "select * from [" + sheetname + "]"; try { strConn.Open(); } catch { strCon = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; strConn = new OleDbConnection(strCon); strConn.Open(); } OleDbDataAdapter strCom = new OleDbDataAdapter(strSql, strConn); DataSet ds = new DataSet(); strCom.Fill(ds, "[" + sheetname + "]"); strConn.Close(); string s1 = ""; DataRow row; for (int i = 0; i < ds.Tables["[" + sheetname + "]"].Rows.Count; i++) { s1 = ""; row = ds.Tables["[" + sheetname + "]"].Rows[i]; s1 += (i + 1).ToString(); for (int j = 0; j < row.ItemArray.Length; j++) { s1 += "^" + row[j].ToString().Trim(); } if (fromerp) { ids.Add(i + 1, new List() { Convert.ToInt32(row[13].ToString().Trim()) }); } DataGridViewRow newrow = DisplayPack.PolyNewRowBitteng(polyView, s1.Replace("enter", "\r\n")); if (newrow != null) polyView.Rows.Add(DisplayPack.PolyNewRowBitteng(polyView, s1.Replace("enter", "\r\n"))); else globel.ShowFromWarningMessage("试图导入第" + polyView.Rows.Count + "行出现错误,改行可能为dxf小片,请直接从dxf文件导入!", false); } //} //catch //{ // return; //} } void inputPolygonFromBeiBo(string filename, string sheetname, bool fromerp = false) { //try //{ if (fromerp) { ids = new Dictionary>(); } string strCon = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; OleDbConnection strConn = new OleDbConnection(strCon); string strSql = "select * from [" + sheetname + "]"; try { strConn.Open(); } catch { strCon = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; strConn = new OleDbConnection(strCon); strConn.Open(); } OleDbDataAdapter strCom = new OleDbDataAdapter(strSql, strConn); DataSet ds = new DataSet(); strCom.Fill(ds, "[" + sheetname + "]"); strConn.Close(); string s1 = ""; DataRow row; for (int i = 0; i < ds.Tables["[" + sheetname + "]"].Rows.Count; i++) { s1 = ""; row = ds.Tables["[" + sheetname + "]"].Rows[i]; s1 += (i + 1).ToString(); for (int j = 0; j < row.ItemArray.Length; j++) { s1 += "^" + row[j].ToString().Trim(); } if (fromerp) { ids.Add(i + 1, new List() { Convert.ToInt32(row[13].ToString().Trim()) }); } DataGridViewRow newrow = DisplayPack.PolyNewRowBeiBo(polyView, s1.Replace("enter", "\r\n")); if (newrow != null) polyView.Rows.Add(DisplayPack.PolyNewRowBeiBo(polyView, s1.Replace("enter", "\r\n"))); else globel.ShowFromWarningMessage("试图导入第" + polyView.Rows.Count + "行出现错误,改行可能为dxf小片,请直接从dxf文件导入!", false); } //} //catch //{ // return; //} } private bool rightTable(string filename) { List files = GetExcelSheetName(filename); if (files == null) return false; string sheetname = files[0]; string strCon = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + filename + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1'"; OleDbConnection strConn = new OleDbConnection(strCon); string strSql = "select * from [" + sheetname + "]"; try { strConn.Open(); } catch (Exception er) { globel.ShowErrorMessage("rightTable\r\n" + er.Message); return false; strCon = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + filename + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1'"; strConn = new OleDbConnection(strCon); strConn.Open(); } OleDbDataAdapter strCom = new OleDbDataAdapter(strSql, strConn); DataSet ds = new DataSet(); strCom.Fill(ds, "[" + sheetname + "]"); strConn.Close(); List columnnames = new List(); for (int i = 0; i < ds.Tables["[" + sheetname + "]"].Columns.Count; i++) { columnnames.Add(ds.Tables["[" + sheetname + "]"].Rows[0][i].ToString().Trim()); } return BeiBoExecl(columnnames, filename, sheetname); //return ExeclChecking(columnnames, filename, sheetname); } bool BeiBoExecl(List columnnames, string filename, string sheetname) { if (columnnames.Count >= 14 && ( columnnames[1] == "宽度" && columnnames[2] == "高度" && columnnames[3] == "数量" && columnnames[4] == "图号" && //columnnames[5] == "长磨1" && //columnnames[6] == "长磨2" && //columnnames[7] == "短磨1" && //columnnames[8] == "短磨2" && //columnnames[9] == "加工信息" && //columnnames[10] == "客户名称" && //columnnames[11] == "订单编号" && //columnnames[12] == "产品名称" && //columnnames[13] == "单价" && //columnnames[14] == "备注" && //columnnames[15] == "楼层编号"&& columnnames[16] == "架号")) { string name = Path.GetFileNameWithoutExtension(filename); if (filename.Contains("成品列表")) projectnameText.Text = name.Substring(0, name.IndexOf("成品列表")); else projectnameText.Text = name; inputPolygonFromBeiBo(filename, sheetname); return true; } return false; } bool ExeclChecking(List columnnames, string filename, string sheetname) { //派尔的固定格式 if (columnnames.Count >= 11 && columnnames[0] == "客户名称" && columnnames[1] == "订单编号" && columnnames[2] == "宽" && columnnames[3] == "高" && columnnames[4] == "数量" && columnnames[5] == "加工要求" && columnnames[6] == "产品名称" && columnnames[7] == "上磨边" && columnnames[8] == "下磨边" && columnnames[9] == "左磨边" && columnnames[10] == "右磨边") { string xlsfileName = Path.GetFileNameWithoutExtension(filename); projectnameText.Text = xlsfileName; inputPolygonFromPier(filename, sheetname); return true; } else if (columnnames.Count >= 19 && columnnames[0] == "产品类别(材料)" && columnnames[1] == "宽" && columnnames[2] == "高" && columnnames[3] == "数量" && columnnames[4] == "订单号" && columnnames[5] == "客户名称" && columnnames[6] == "产品名称(注释1)" && columnnames[7] == "加工要求(注释2)" && columnnames[8] == "孔数" && columnnames[9] == "单边磨边量" && columnnames[10] == "四边磨X1" && columnnames[11] == "四边磨Y1" && columnnames[12] == "四边磨X2" && columnnames[13] == "四边磨Y2" && columnnames[14] == "玻璃架号" && columnnames[15] == "楼层号(注释3)" && columnnames[16] == "图号(注释4)" && columnnames[17] == "条码号(注释5)" && columnnames[18] == "交货日期") { projectnameText.Text = Path.GetFileNameWithoutExtension(filename); inputPolygonFromOptima(filename, sheetname); return true; } //比藤的矩形固定格式 else if (columnnames.Count >= 14 && ( columnnames[0] == "宽度" && columnnames[1] == "高度" && columnnames[2] == "数量" && columnnames[3] == "长磨1" && columnnames[4] == "短磨1" && columnnames[5] == "长磨2" && columnnames[6] == "短磨2" && columnnames[7] == "加工信息" && columnnames[8] == "客户名称" && columnnames[9] == "订单编号" && columnnames[10] == "产品名称" && columnnames[11] == "单价" && columnnames[12] == "备注" && columnnames[13] == "楼层编号" || columnnames[0] == "X Dim" && columnnames[1] == "Y Dim" && columnnames[2] == "QTY" && columnnames[3] == "Long Grind1" && columnnames[4] == "Short Grind1" && columnnames[5] == "Long Grind2" && columnnames[6] == "Short Grind2" && columnnames[7] == "Note" && columnnames[8] == "Customer" && columnnames[9] == "Order" && columnnames[10] == "Product" && columnnames[11] == "Price" && columnnames[12] == "Remarks" && columnnames[13] == "Floor No.")) { projectnameText.Text = Path.GetFileNameWithoutExtension(filename); inputPolygonFromBtRect(filename, sheetname); return true; } //比藤的固定格式 else if (columnnames.Count >= 18 && ( columnnames[0] == "宽度" && columnnames[1] == "高度" && columnnames[2] == "数量" && columnnames[3] == "图号" && columnnames[4] == "长磨1" && columnnames[5] == "短磨1" && columnnames[6] == "长磨2" && columnnames[7] == "短磨2" && columnnames[8] == "加工信息" && columnnames[9] == "客户名称" && columnnames[10] == "订单编号" && columnnames[11] == "产品名称" && columnnames[12] == "单价" && columnnames[13] == "备注" && columnnames[14] == "楼层编号" && columnnames[15] == "架号" && columnnames[16] == "Str" && columnnames[17] == "Str2" || columnnames[0] == "X Dim" && columnnames[1] == "Y Dim" && columnnames[2] == "QTY" && columnnames[3] == "Shape" && columnnames[3] == "Long Grind1" && columnnames[4] == "Short Grind1" && columnnames[5] == "Long Grind2" && columnnames[6] == "Short Grind2" && columnnames[8] == "Note" && columnnames[9] == "Customer" && columnnames[10] == "Order" && columnnames[11] == "Product" && columnnames[12] == "Price" && columnnames[13] == "Remarks" && columnnames[14] == "Floor No." && columnnames[15] == "Rack" && columnnames[16] == "Str" && columnnames[17] == "Str2")) { string name = Path.GetFileNameWithoutExtension(filename); if (filename.Contains("成品列表")) projectnameText.Text = name.Substring(0, name.IndexOf("成品列表")); else if (filename.Contains("Parts List")) projectnameText.Text = name.Substring(0, name.IndexOf("Parts List")); else projectnameText.Text = name; inputPolygonFromBitteng(filename, sheetname); return true; } //MyGlassERP的固定格式(比比藤多一列ID) else if (columnnames.Count >= 15 && columnnames[0] == "长" && columnnames[1] == "高" && columnnames[2] == "数量" && columnnames[3] == "模板号" && columnnames[4] == "上磨边" && columnnames[5] == "下磨边" && columnnames[6] == "左磨边" && columnnames[7] == "右磨边" && columnnames[8] == "加工信息" && columnnames[9] == "客户名称" && columnnames[10] == "订单编号" && columnnames[11] == "产品名称" && columnnames[12] == "str" && columnnames[13] == "ID" && columnnames[14] == "工艺") { projectnameText.Text = Path.GetFileNameWithoutExtension(filename); inputPolygonFromBitteng(filename, sheetname, true); return true; } else { return false; } } public List GetExcelSheetName(string filename) { List names = new List(); string strCon = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; OleDbConnection strConn = new OleDbConnection(strCon); try { strConn.Open(); } catch { try { strCon = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + filename + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; strConn = new OleDbConnection(strCon); strConn.Open(); } catch (Exception eee) { globel.ShowErrorMessage("GetExcelSheetName\r\n" + eee.Message); return null; } } System.Data.DataTable sheetNames = strConn.GetOleDbSchemaTable (System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); strConn.Close(); foreach (DataRow dr in sheetNames.Rows) { names.Add(dr[2].ToString()); } return names; } #endregion #region 录入成品和原片更方便 private void stockView_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (stockView.IsCurrentCellDirty) { stockView.CommitEdit(DataGridViewDataErrorContexts.Commit); } } private void stockView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { Setting.settingchaged = true; if (stockView.CurrentCell != null && stockView.CurrentCell.Value != null) if (stockView.CurrentCell.ColumnIndex == 0) { } if (e.RowIndex >= 0) { bool ok = stockView.Rows[e.RowIndex].Cells[0].Value == null ? false : (Boolean)stockView.Rows[e.RowIndex].Cells[0].Value; if (ok) { //stockView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; //stockView.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.White; stockView.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red; } else { if (e.RowIndex % 2 == 1) { stockView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(213, 234, 255); } else { stockView.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.SystemColors.Control; } stockView.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.FromArgb(46, 67, 103); } } //else if (stockView.Columns[stockView.CurrentCell.ColumnIndex].Name == "四边一致1") //{ // if (stockView.CurrentRow != null && stockView.CurrentRow.Cells[3].Value != null) // { // stockView.CurrentRow.Cells["X2修边"].Value = stockView.CurrentRow.Cells["X1修边"].Value; // stockView.CurrentRow.Cells["Y1修边"].Value = stockView.CurrentRow.Cells["X1修边"].Value; // stockView.CurrentRow.Cells["Y2修边"].Value = stockView.CurrentRow.Cells["X1修边"].Value; // } //} //else if (stockView.CurrentRow != null && stockView.CurrentRow.Cells["四边一致1"].Value != null && (Boolean)stockView.CurrentRow.Cells["四边一致1"].Value == true) //{ // if (stockView.CurrentCell.ColumnIndex > 5 && stockView.CurrentCell.ColumnIndex < 9) // { // for (int i = 5; i < 9; i++) // { // if (i != stockView.CurrentCell.ColumnIndex) // stockView.CurrentRow.Cells[i].Value = stockView.CurrentCell.Value; // } // } //} } private void removeX() { foreach (DataGridViewRow row in polyView.Rows) { if (row.Cells["宽度"].Value == null) { row.Cells["形状"].Value = Functions.getblankImage(row.Cells["形状"]); } } } #region 统计面积数量 /// /// 统计小片的数量和面积 /// public void CountPolyNumberOrArea() { double area, circle, totalarea = 0, totalcircle = 0; int shuliang, totalshuliang = 0; int rowNum = polyView.AllowUserToAddRows ? polyView.Rows.Count - 1 : polyView.Rows.Count; //没有成品数据时跳过 if (rowNum == 0) { return; } foreach (DataGridViewRow row in polyView.Rows) { if (row.Cells["面积"].Value != null && double.TryParse(row.Cells["面积"].Value.ToString().Trim(), out area)) { totalarea += area; } if (row.Cells["周长"].Value != null && double.TryParse(row.Cells["周长"].Value.ToString().Trim(), out circle)) { totalcircle += circle; } if (row.Cells["数量"].Value != null && int.TryParse(row.Cells["数量"].Value.ToString().Trim(), out shuliang)) { totalshuliang += shuliang; } } areaTxt.Text = Math.Round(totalarea, 3).ToString() + " "; zhouchangTxt.Text = Math.Round(totalcircle, 2).ToString() + " "; countTxt.Text = totalshuliang + " "; } #endregion #region polyView_RowsAdded private void polyView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { removeX(); //默认填写单价 if (polyView.Rows[e.RowIndex].Cells["单价"].Value == null || polyView.Rows[e.RowIndex].Cells["单价"].Value.ToString().Trim() == "") polyView.Rows[e.RowIndex].Cells["单价"].Value = "0.0"; //自动计算面积 double w, h; int c; if (polyView.Rows[e.RowIndex].Cells["宽度"].Value != null && double.TryParse(polyView.Rows[e.RowIndex].Cells["宽度"].Value.ToString(), out w) && polyView.Rows[e.RowIndex].Cells["高度"].Value != null && double.TryParse(polyView.Rows[e.RowIndex].Cells["高度"].Value.ToString(), out h) && polyView.Rows[e.RowIndex].Cells["数量"].Value != null && int.TryParse(polyView.Rows[e.RowIndex].Cells["数量"].Value.ToString(), out c)) { polyView.Rows[e.RowIndex].Cells["面积"].Value = Math.Round(w * h * Math.Pow(10, -6), 2) * c; //polyView.Rows[e.RowIndex].Cells["面积"].Value = Functions.decimalconvert(Math.Round( w * h * c*Math.Pow(10, -6),3)); polyView.Rows[e.RowIndex].Cells["周长"].Value = Functions.decimalconvert((2 * w + 2 * h) * c * Math.Pow(10, -3)); //countPolyArea(); } //填写默认的加工信息等信息 for (int i = 11; i < 15; i++) if (polyView.Rows[e.RowIndex].Cells[i].Value == null) polyView.Rows[e.RowIndex].Cells[i].Value = ""; if (polyView.Rows[e.RowIndex].Cells["备注"].Value == null) polyView.Rows[e.RowIndex].Cells["备注"].Value = ""; if (polyView.Rows[e.RowIndex].Cells["楼层编号"].Value == null) polyView.Rows[e.RowIndex].Cells["楼层编号"].Value = ""; //根据是否为矩形以及是否设置统一磨边来配置宽高以及磨边以及四边一致是否可以编辑 if (polyView.Rows[e.RowIndex].Cells["模板号"].Value != null) { if (polyView.Rows[e.RowIndex].Cells["模板号"].Value.ToString().Trim() == "100") { Functions.setCellNotReadonly(polyView.Rows[e.RowIndex].Cells["宽度"]); Functions.setCellNotReadonly(polyView.Rows[e.RowIndex].Cells["高度"]); //if (rectgrindcheck.Checked) //{ // Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells[6]); // Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells[7]); // Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells[8]); // Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells[9]); //} //else { Functions.setCellNotReadonly(polyView.Rows[e.RowIndex].Cells["长磨1"]); Functions.setCellNotReadonly(polyView.Rows[e.RowIndex].Cells["短磨1"]); Functions.setCellNotReadonly(polyView.Rows[e.RowIndex].Cells["长磨2"]); Functions.setCellNotReadonly(polyView.Rows[e.RowIndex].Cells["短磨2"]); } } else { Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["宽度"]); Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["高度"]); Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["长磨1"]); Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["短磨1"]); Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["长磨2"]); Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["短磨2"]); Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["四边一致"]); } } //面积不允许编辑 Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["面积"]); Functions.setCellReadonly(polyView.Rows[e.RowIndex].Cells["周长"]); if (polyView.Rows[polyView.Rows.Count - 1].Cells["形状"].Value == null) { setblankmap(polyView.Rows[polyView.Rows.Count - 1].Cells["形状"]); } //CountPolyNumberOrArea(); } #endregion private void newRectRow(int index, int shapeNo) { DataGridViewRow row = polyView.Rows[index]; Functions.setCellReadonly(row.Cells["面积"]); Functions.setCellReadonly(row.Cells["周长"]); #region //if (index > 0) //{ // row.Cells["宽度"].Value = polyView.Rows[index - 1].Cells["宽度"].Value; // row.Cells["高度"].Value = polyView.Rows[index - 1].Cells["高度"].Value; // row.Cells["数量"].Value = polyView.Rows[index - 1].Cells["数量"].Value; // row.Cells["长磨1"].Value = polyView.Rows[index - 1].Cells["长磨1"].Value; // row.Cells["长磨2"].Value = polyView.Rows[index - 1].Cells["长磨2"].Value; // row.Cells["短磨1"].Value = polyView.Rows[index - 1].Cells["短磨1"].Value; // row.Cells["短磨2"].Value = polyView.Rows[index - 1].Cells["短磨2"].Value; // row.Cells["加工信息"].Value = polyView.Rows[index - 1].Cells["加工信息"].Value; // row.Cells["客户名称"].Value = polyView.Rows[index - 1].Cells["客户名称"].Value; // //row.Cells["流程卡号"].Value = polyView.Rows[index - 1].Cells["流程卡号"].Value; // row.Cells["产品名称"].Value = polyView.Rows[index - 1].Cells["产品名称"].Value; // // row.Cells["单价"].Value = polyView.Rows[index - 1].Cells["单价"].Value; // row.Cells["备注"].Value = polyView.Rows[index - 1].Cells["备注"].Value; // row.Cells["楼层编号"].Value = polyView.Rows[index - 1].Cells["楼层编号"].Value; //} //else //{ //if (row.Cells["宽度"].Value == null) // row.Cells["宽度"].Value = "1000"; //if (row.Cells["高度"].Value == null) // row.Cells["高度"].Value = "1000"; //if (row.Cells["数量"].Value == null) // row.Cells["数量"].Value = "1"; //if (row.Cells["长磨1"].Value == null) // row.Cells["长磨1"].Value = "0"; //if (row.Cells["长磨2"].Value == null) // row.Cells["长磨2"].Value = "0"; //if (row.Cells["短磨1"].Value == null) // row.Cells["短磨1"].Value = "0"; //if (row.Cells["短磨2"].Value == null) // row.Cells["短磨2"].Value = "0"; //} #endregion CreateThumbnail(shapeNo, row); for (int i = 11; i < 18; i++) if (row.Cells[i].Value == null || row.Cells[i].Value.ToString() == "") row.Cells[i].Value = i != 15 ? "" : "0.0"; if (row.Cells[18].Value == null) row.Cells[18].Value = false; int count; if (!int.TryParse(row.Cells[3].Value.ToString().Trim(), out count)) { row.Cells[3].Value = "0"; count = 0; } } /// /// 创建图形行中显示缩略图 /// /// 图号 /// 行 void CreateThumbnail(int number, DataGridViewRow gridrow) { gridrow.Cells["模板号"].Value = number + ""; Polygon temppoly = new Template().getTempPoly(number); temppoly.refresh(); temppoly.setDistance(); temppoly.lineWidth = 1; temppoly.distanceColor = number == 100 ? System.Drawing.Color.White : Color.Orange; double ratio = 0.7 * (float)gridrow.Height / Math.Max(temppoly.width, temppoly.height); Bitmap tempmap = new Bitmap(gridrow.Height, gridrow.Height); Graphics g = Graphics.FromImage(tempmap); temppoly.drawTemplate(g, ratio); gridrow.Cells[10].Value = tempmap; } #region 刷新成品列表列 private void refreshSTR(DataGridViewRow row) { try { if (polyView.CurrentRow.Cells["模板号"].Value != null && polyView.CurrentRow.Cells["模板号"].Value.ToString() == "100") { int width = Convert.ToInt32(row.Cells["宽度"].Value.ToString()); int height = Convert.ToInt32(row.Cells["高度"].Value.ToString()); int count = Convert.ToInt32(row.Cells["数量"].Value.ToString()); Polygon poly = Tranform.trans(100, height, 0, 0, width, 0, 0, 0, 0, 0); poly.count = count; if (row.Cells["Str"].Value != null) { Polygon p = new Polygon(); p.ABS_Deserialize(row.Cells["Str"].Value.ToString()); poly.poly_id = p.poly_id; row.Cells["Str"].Value = poly.ABS_Serialize()[0];//Str} } } } catch (Exception exc) { } } #endregion #region 数据校验 private bool checkData() { bool result = true; //文件名不能包含【.】,否则影响连续切割 if (projectnameText.Text.Trim().Contains(".")) { globel.ShowFromWarningMessage(Setting.language == 0 ? "工程名称包含关键字符【.】,请修改。" : "The projectname contains key character【.】,Please modify your input.", false); return false; } if (string.IsNullOrWhiteSpace(cmbGlassThick.Text.Trim()) || string.IsNullOrWhiteSpace(cmbGlassThick.Text.Trim())) { globel.ShowFromWarningMessage("玻璃厚度和玻璃类型不可为空,请输入玻璃厚度和玻璃类型"); return false; } polyView.EndEdit(); if (polyView.CurrentRow != null) refreshSTR(polyView.CurrentRow); stockView.EndEdit(); bool Alert = true; foreach (DataGridViewRow row in polyView.Rows) { if (polyView.AllowUserToAddRows && row.Index + 1 == polyView.Rows.Count) { continue; } //if (row.Cells["模板号"].Value == null || row.Cells["模板号"].Value.ToString() == "" || row.Cells["模板号"].Value.ToString() == "0") //{ // globel.ShowFromWarningMessage("当前工程中存在异形小片,暂不可优化!"); // return false; //} if (row.Cells["楼层编号"].Value.ToString().Contains("'") || row.Cells["楼层编号"].Value.ToString().Contains("\"")) { globel.ShowFromWarningMessage("当前工程第【" + (row.Index + 1) + "】行【楼层号】包含 ' 或 \" 特殊字符,可能会导致优化后无法保存,请修改后再次优化!", false); return false; } /* 23.10.10 测试异形时注释 if (row.Cells["模板号"].Value.ToString() != "100") { globel.ShowFromWarningMessage("当前工程包含异形图形,不可优化!"); return false; }*/ for (int i = 1; i < 10; i++) { if (i != 4 && i != 5) if (row.Cells[i].Value == null || row.Cells[i].Value.ToString() == "")//数据为空 { globel.ShowFromWarningMessage("成品信息第【" + (row.Index + 1).ToString() + "】行【" + polyView.Columns[i].HeaderText + "】数据填写不正确", false, "操作信息提示"); return false; } else { try { double a = Convert.ToDouble(row.Cells[i].Value);//填入非法字符 if (a == 0 && (i == 1 || i == 2)) { globel.ShowFromWarningMessage("成品信息第【" + (row.Index + 1).ToString() + "】行【" + polyView.Columns[i].HeaderText + "】数据填写不正确", false, "操作信息提示"); return false; } } catch (Exception ec) { globel.ShowFromWarningMessage("成品信息第【" + (row.Index + 1).ToString() + "】行【" + polyView.Columns[i].HeaderText + "】数据填写不正确", false, "操作信息提示"); return false; } } if (row.Cells[21].Value == null || row.Cells[21].Value.ToString() == "") { globel.ShowFromWarningMessage("成品信息第【" + (row.Index + 1).ToString() + "】行 架子号数据填写不正确", false, "操作信息提示"); return false; } } if (polyView.AllowUserToAddRows && row.Index == polyView.Rows.Count - 1) break; if (Convert.ToDouble(row.Cells["宽度"].Value.ToString().Trim()) >= globel.PolyEdgeGreaterThanNumRemind || Convert.ToDouble(row.Cells["高度"].Value.ToString().Trim()) >= globel.PolyEdgeGreaterThanNumRemind) { if (Alert) { if (globel.ShowFromConfirmMessage("当前成品列表中包含有单边大于 " + globel.PolyEdgeGreaterThanNumRemind + "的成品\r\n\r\n是否继续优化?")) { Alert = false; } else { return false; } } } } /*原片信息检测*/ foreach (DataGridViewRow row in stockView.Rows) //if (row.Index != stockView.Rows.Count - 1 && row.Cells[0].Value != null && (Boolean)row.Cells[0].Value == true) if (row.Index != stockView.Rows.Count && row.Cells[0].Value != null && (Boolean)row.Cells[0].Value == true) for (int i = 1; i < row.Cells.Count; i++) { bool stockTF = row.Cells["类型"].Value.ToString().Trim() == cmbGlassType.Text.Trim(); if (row.Cells["类型"].Value != null && !stockTF) { if (Setting.language == 0) globel.ShowFromErrorMessage("第【" + (row.Index + 1).ToString() + "】行原片类型与优化的成品类型不符", "数据验证:"); else globel.ShowFromErrorMessage("Wrong type or thickness of data in row【" + (row.Index + 1).ToString() + "】", "Prompt:"); return false; } bool isTrue = row.Cells["厚度"].Value != null && StringUtil.compareEqual(row.Cells["厚度"].Value.ToString().Trim(), cmbGlassThick.Text.Trim()); //if (row.Cells["厚度"].Value != null && Convert.ToDouble( row.Cells["厚度"].Value.ToString().Trim()) != Convert.ToDouble(GetNumbers(cmbGlassThick.Text.Trim()))) if (!isTrue) { if (Setting.language == 0) globel.ShowFromErrorMessage("第【" + (row.Index + 1).ToString() + "】行原片厚度与优化的成品厚度不符"); else globel.ShowFromErrorMessage("Wrong type or thickness of data in row【" + (row.Index + 1).ToString() + "】"); return false; } if (stockView.Columns[i].Name != "膜系" && stockView.Columns[i].Name != "库位" && stockView.Columns[i].Name != "余料" && stockView.Columns[i].Name != "用量" && stockView.Columns[i].Name != "供应商" && stockView.Columns[i].Name != "类型" && stockView.Columns[i].Name != "物料代码" && stockView.Columns[i].Name != "单价2" && stockView.Columns[i].Name != "名称" && stockView.Columns[i].Name != "状态") if (row.Cells[i].Value == null || row.Cells[i].Value.ToString() == "") { if (Setting.language == 0) globel.ShowFromErrorMessage("第【" + (row.Index + 1).ToString() + "】行【" + stockView.Columns[i].HeaderText + "】原片数据填写不正确"); else globel.ShowFromErrorMessage("Data Error of Common-Glass Raw Sheets! Row: " + (row.Index + 1).ToString() + ",Column: " + stockView.Columns[i].HeaderText, "Prompt"); return false; } else { try { double a = Convert.ToDouble(row.Cells[i].Value); if (a == 0 && (i == 1 || i == 2)) { if (Setting.language == 0) globel.ShowFromErrorMessage("原片信息第【" + (row.Index + 1).ToString() + "】行【" + stockView.Columns[i].HeaderText + "】数据填写不正确"); else globel.ShowFromErrorMessage("Data Error of Common-Glass Raw Sheets! Row: " + (row.Index + 1).ToString() + ",Column: " + stockView.Columns[i].HeaderText); return false; } } catch (Exception ec) { if (Setting.language == 0) globel.ShowFromErrorMessage("原片信息第【" + (row.Index + 1).ToString() + "】行【" + stockView.Columns[i].HeaderText + "】数据填写不正确"); else globel.ShowFromErrorMessage("Data Error of Common-Glass Raw Sheets! Row: " + (row.Index + 1).ToString() + ",Column: " + stockView.Columns[i].HeaderText, "Prompt"); return false; } } } return result; } #endregion private void polyView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { Setting.settingchaged = true; if (polyView.Columns[e.ColumnIndex].Name == "数量")//数量改变 { if (polyView.Rows[e.RowIndex].Cells["数量"].Value == null) return; string sl = GetNumbers(polyView.Rows[e.RowIndex].Cells["数量"].Value.ToString().Trim()); if (ImportXLSX == false) { polyView.Rows[e.RowIndex].Cells["数量"].Value = string.IsNullOrEmpty(sl) ? dicRowAndNum[e.RowIndex] : Convert.ToInt32(sl) > dicRowAndNum[e.RowIndex] ? dicRowAndNum[e.RowIndex] : Convert.ToInt32(sl); } else { polyView.Rows[e.RowIndex].Cells["数量"].Value = sl; } double w, h; int c; if (polyView.Rows[e.RowIndex].Cells["宽度"].Value != null && double.TryParse(polyView.Rows[e.RowIndex].Cells["宽度"].Value.ToString(), out w) && polyView.Rows[e.RowIndex].Cells["高度"].Value != null && double.TryParse(polyView.Rows[e.RowIndex].Cells["高度"].Value.ToString(), out h) && polyView.Rows[e.RowIndex].Cells["数量"].Value != null && int.TryParse(polyView.Rows[e.RowIndex].Cells["数量"].Value.ToString(), out c)) { polyView.Rows[e.RowIndex].Cells["面积"].Value = Functions.decimalconvert(w * h * c * Math.Pow(10, -6)); polyView.Rows[e.RowIndex].Cells["周长"].Value = Functions.decimalconvert((2 * w + 2 * h) * c * Math.Pow(10, -3)); CountPolyNumberOrArea(); } } } catch { } } //按一下动一下 private void polyView_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (polyView.IsCurrentCellDirty) { polyView.CommitEdit(DataGridViewDataErrorContexts.Commit); } } #endregion private void polyView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { //检测是被表示的控件还是DataGridViewTextBoxEditingControl if (e.Control is DataGridViewTextBoxEditingControl) { DataGridViewTextBoxEditingControl textbox = (DataGridViewTextBoxEditingControl)e.Control; textbox.KeyPress -= new KeyPressEventHandler(Functions.int_KeyPress); textbox.KeyPress -= new KeyPressEventHandler(Functions.double_KeyPress); //检测对应列 string header = polyView.CurrentCell.OwningColumn.Name.Trim(); if (header == "宽度" || header == "高度" || header == "长磨1" || header == "长磨2" || header == "短磨1" || header == "短磨2" || header == "单价") { // KeyPress事件处理器追加 textbox.KeyPress += new KeyPressEventHandler(Functions.double_KeyPress); } else if (header == "数量") { textbox.KeyPress += new KeyPressEventHandler(Functions.int_KeyPress); } } } private void stockView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { //检测是被表示的控件还是DataGridViewTextBoxEditingControl if (e.Control is DataGridViewTextBoxEditingControl) { DataGridViewTextBoxEditingControl textbox = (DataGridViewTextBoxEditingControl)e.Control; textbox.KeyPress -= new KeyPressEventHandler(Functions.double_KeyPress); //检测对应列 string header = stockView.CurrentCell.OwningColumn.Name.Trim(); if (header == "大片宽" || header == "大片高" || header == "X1修边" || header == "X2修边" || header == "Y1修边" || header == "Y2修边") { // KeyPress事件处理器追加 textbox.KeyPress += new KeyPressEventHandler(Functions.double_KeyPress); } else if (header == "库存量") { textbox.KeyPress += new KeyPressEventHandler(Functions.int_KeyPress); } } } #region 打开工程--读文件(未使用) public bool _openfile(string content, string name) { MyGlasFile myglassfile = new MyGlasFile(); myglassfile.ReadFileContent(content); if (myglassfile.MGFile.Count == 0) { globel.ShowFromWarningMessage(Setting.language == 0 ? "读取文件出错" : "File Error!", false); return false; } OnePacking openpack = ReadFile.LoadPackInfo(name, myglassfile); if (openpack != null) { Order simpleorder = new Order(); myglassfile.wangmeiLoadOriginalInfo(this, ref simpleorder, content); pack = openpack; //2023-6-5注释,用于展开成品数据 setSimpleOrder(); pagenumber = 0; drawPack(); if (reportform != null) reportform.end.Text = pack.mergedstocks.Count.ToString(); cmbGlassType.Text = pack.mergedstocks[0].glassType; cmbGlassThick.Text = pack.mergedstocks[0].Thickness + ""; Setting.justOpened = openpack.getcopy(); return true; } return false; } public bool openfile(string filename)//打开工程文件 { string name = Path.GetFileNameWithoutExtension(filename); MyGlasFile myglassfile = new MyGlasFile(); myglassfile.ReadFile(filename); if (myglassfile.MGFile.Count == 0) { globel.ShowFromWarningMessage(Setting.language == 0 ? "读取文件出错" : "File Error!", false); return false; } OnePacking openpack = ReadFile.LoadPackInfo(filename, myglassfile); if (openpack != null) { Order simpleorder = new Order(); myglassfile.LoadOriginalInfo(filename, this, ref simpleorder); pack = openpack; setSimpleOrder(); pagenumber = 0; drawPack(); if (reportform != null) reportform.end.Text = pack.mergedstocks.Count.ToString(); cmbGlassType.Text = pack.mergedstocks[0].glassType; cmbGlassThick.Text = pack.mergedstocks[0].Thickness + ""; Setting.justOpened = openpack.getcopy(); return true; } return false; } #endregion private void polyView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) { CountPolyNumberOrArea(); } public void DataGridViewEnableCopy() { int I = polyView.GetCellCount(DataGridViewElementStates.Selected); if (I > 0 && polyView.GetClipboardContent() != null) { Clipboard.SetDataObject(polyView.GetClipboardContent()); } else if (polyView.CurrentCell != null && polyView.CurrentCell.Value != null && polyView.CurrentCell.Value.ToString() != "") { try { Clipboard.SetText(polyView.CurrentCell.Value.ToString()); } catch (Exception) { } } } public void DataGirdViewCellPaste(DataGridView p_Data) { if (polyView.CurrentCell == null) { } else { if (!Clipboard.GetText().Contains("\n") && !Clipboard.GetText().Contains("\r") && !Clipboard.GetText().Contains("\t")) { int col = polyView.CurrentCell.ColumnIndex; int row = polyView.CurrentCell.RowIndex; polyView.CurrentCell.Value = Clipboard.GetText(); polyView.CurrentCell = polyView[1, 0]; polyView.BeginEdit(false); polyView.CurrentCell = polyView[col, row]; polyView.BeginEdit(false); return; } int insertRowIndex = polyView.CurrentCell.RowIndex; int insertColIndex = polyView.CurrentCell.ColumnIndex; double height, width; bool b1, b2; // 获取剪切板的内容,并按行分割 string pasteText = Clipboard.GetText(); if (string.IsNullOrEmpty(pasteText)) return; string[] l = pasteText.Split(new char[] { '\n', '\r' }); List lines = new List(); foreach (string li in l) if (li.Trim() != "") lines.Add(li); while (polyView.Rows.Count < insertRowIndex + lines.Count + 1) { polyView.Rows.Add(DisplayPack.PolyNewRectRow(polyView)); } int index = 0; foreach (string line in lines) { if (line.Trim() == "") continue; if (string.IsNullOrEmpty(line.Trim())) continue; // 按 Tab 分割数据 string[] vals = line.Split(new char[] { '\t', ',' }); for (int col = insertColIndex; col < Math.Min(insertColIndex + vals.Length - 1, polyView.ColumnCount); col++)//前三列是宽高数量 { if (col == 10 || col == 18 || col == 19 || col == 20) continue; if (col >= 4 && insertColIndex < 4) polyView.Rows[insertRowIndex + index].Cells[col + 2].Value = vals[col - insertColIndex]; else { polyView.Rows[insertRowIndex + index].Cells[col].Value = vals[col - insertColIndex]; if (col == 1 || col == 2) { b1 = double.TryParse(polyView[2, insertRowIndex + index].Value.ToString().Trim(), out height); b2 = double.TryParse(polyView[1, insertRowIndex + index].Value.ToString().Trim(), out width); if (b1 && b2) { Polygon poly = Tranform.trans(100, (float)height, 0, 0, (float)width, 0, 0, 0, 0, 0); polyView[5, insertRowIndex + index].Value = poly.ABS_Serialize()[0]; } } } } //第四列是架号 polyView.Rows[insertRowIndex + index].Cells["架号"].Value = vals[3]; index++; } } } #region //复制 注释 //protected override bool ProcessCmdKey(ref Message msg, Keys keyData) //{ // //if (Control.ModifierKeys == Keys.Control && keyData == (Keys.LButton|Keys.ShiftKey|Keys.Control)) return true; // if (keyData == Keys.Enter || keyData == Keys.Down) //监听回车事件 // { // if (this.polyView.IsCurrentCellInEditMode) //如果当前单元格处于编辑模式 // { // if (polyView.Columns[polyView.CurrentCell.ColumnIndex].Name == "数量" || // polyView.Columns[polyView.CurrentCell.ColumnIndex].Name == "右磨边" || // polyView.Columns[polyView.CurrentCell.ColumnIndex].Name == "产品名称") // polyView.CurrentCell = polyView[1, polyView.CurrentCell.RowIndex + 1]; // else // { // int column = polyView.CurrentCell.ColumnIndex + 1; // while (polyView.Columns[column].Visible == false) // column++; // polyView.CurrentCell = polyView[column, polyView.CurrentCell.RowIndex]; // } // polyView.BeginEdit(true); // } // else if (this.stockView.IsCurrentCellInEditMode) //如果当前单元格处于编辑模式 // { // if (keyData == Keys.Down && stockView.CurrentRow.Index == stockView.Rows.Count - 2) // { // stockView.CurrentCell = stockView[0, stockView.CurrentCell.RowIndex + 1]; // stockView.BeginEdit(true); // } // } // else // { // return base.ProcessCmdKey(ref msg, keyData); // } // return true; // } // else if (keyData == (Keys)131158)//Ctrl+V组合键 // { // if (this.polyView.IsCurrentCellInEditMode) //如果当前单元格处于编辑模式 // { // DataGirdViewCellPaste(polyView); // return true; // } // else // { // //继续原来base.ProcessCmdKey中的处理 // return base.ProcessCmdKey(ref msg, keyData); // } // } // else if (keyData == (Keys)131139)//Ctrl+C组合键 // { // DataGridViewEnableCopy(); // return true; // //else // //{ // // //继续原来base.ProcessCmdKey中的处理 // // return base.ProcessCmdKey(ref msg, keyData); // //} // } // else // { // //继续原来base.ProcessCmdKey中的处理 // return base.ProcessCmdKey(ref msg, keyData); // } //} #endregion public System.Data.DataTable GetDgvToTable() { try { System.Data.DataTable dt = new System.Data.DataTable(); DataColumn xuhao = new DataColumn("序号"); dt.Columns.Add(xuhao); for (int count = 1; count < 5; count++) { DataColumn dc = new DataColumn(polyView.Columns[count].HeaderText.ToString()); dt.Columns.Add(dc); } for (int count = 6; count < 10; count++) { DataColumn dc = new DataColumn(polyView.Columns[count].HeaderText.ToString()); dt.Columns.Add(dc); } for (int count = 11; count < 18; count++) { DataColumn dc = new DataColumn(polyView.Columns[count].HeaderText.ToString()); dt.Columns.Add(dc); } DataColumn dcStr = new DataColumn(Setting.language == 0 ? "架号" : "Rack"); dt.Columns.Add(dcStr); //dcStr = new DataColumn("Str"); //dt.Columns.Add(dcStr); //dcStr = new DataColumn("Str2"); //dt.Columns.Add(dcStr); //dt.Columns[12].ColumnName = "产品类型"; for (int count = 0; count < polyView.Rows.Count; count++) { if (polyView.AllowUserToAddRows && count == polyView.Rows.Count - 1) break; DataRow dr = dt.NewRow(); dr[0] = polyView.Rows[count].Cells["序号"].Value != null ? polyView.Rows[count].Cells["序号"].Value.ToString() : "";//序号 dr[1] = polyView.Rows[count].Cells["宽度"].Value.ToString();//长 dr[2] = polyView.Rows[count].Cells["高度"].Value.ToString();//宽 dr[3] = polyView.Rows[count].Cells["数量"].Value.ToString();//数量 dr[4] = polyView.Rows[count].Cells["模板号"].Value.ToString();//模板号 dr[5] = polyView.Rows[count].Cells["长磨1"].Value != null ? polyView.Rows[count].Cells["长磨1"].Value.ToString() : "0";//上 dr[6] = polyView.Rows[count].Cells["长磨2"].Value != null ? polyView.Rows[count].Cells["短磨1"].Value.ToString() : "0";//下 dr[7] = polyView.Rows[count].Cells["短磨1"].Value != null ? polyView.Rows[count].Cells["长磨2"].Value.ToString() : "0";//左 dr[8] = polyView.Rows[count].Cells["短磨2"].Value != null ? polyView.Rows[count].Cells["短磨2"].Value.ToString() : "0";//右 dr[9] = polyView.Rows[count].Cells["加工信息"].Value != null ? polyView.Rows[count].Cells["加工信息"].Value.ToString() : "";//加工信息 dr[10] = polyView.Rows[count].Cells["流程卡号"].Value != null ? polyView.Rows[count].Cells["流程卡号"].Value.ToString() : "";//订单编号 dr[11] = polyView.Rows[count].Cells["客户名称"].Value != null ? polyView.Rows[count].Cells["客户名称"].Value.ToString() : "";//客户名称 dr[12] = polyView.Rows[count].Cells["产品名称"].Value != null ? polyView.Rows[count].Cells["产品名称"].Value.ToString() : "";//产品名称 dr[13] = polyView.Rows[count].Cells["单价"].Value != null ? polyView.Rows[count].Cells["单价"].Value.ToString() : "";//单价 dr[14] = polyView.Rows[count].Cells["备注"].Value != null ? polyView.Rows[count].Cells["备注"].Value.ToString() : "";//备注 dr[15] = polyView.Rows[count].Cells["楼层编号"].Value != null ? polyView.Rows[count].Cells["楼层编号"].Value.ToString() : "";//楼层编号 dr[16] = polyView.Rows[count].Cells["架号"].Value != null ? polyView.Rows[count].Cells["架号"].Value.ToString() : "";//架号 //string str = polyView.Rows[count].Cells[5].Value.ToString().Replace("\r\n", "enter"); //dr[16] = str.Substring(0, str.Length / 2);//Str //dr[17] = str.Substring(str.Length / 2);//Str2 dt.Rows.Add(dr); //return dt; } return dt; } catch (Exception ex) { globel.ShowErrorMessage(ex.Message); throw; } return null; } //TODO 小片表列变更 public System.Data.DataTable GetDgvToTableCSV(DataGridView dgv) { System.Data.DataTable dt = new System.Data.DataTable(); for (int count = 1; count < 5; count++) { DataColumn dc = new DataColumn(dgv.Columns[count].HeaderText.ToString()); dt.Columns.Add(dc); } for (int count = 6; count < 10; count++) { DataColumn dc = new DataColumn(dgv.Columns[count].HeaderText.ToString()); dt.Columns.Add(dc); } for (int count = 11; count < 18; count++) { DataColumn dc = new DataColumn(dgv.Columns[count].HeaderText.ToString()); dt.Columns.Add(dc); } DataColumn dcStr = new DataColumn(Setting.language == 0 ? "架号" : "Rack"); dt.Columns.Add(dcStr); dcStr = new DataColumn("Str"); dt.Columns.Add(dcStr); for (int count = 0; count < dgv.Rows.Count - 1; count++) { DataRow dr = dt.NewRow(); dr[0] = polyView.Rows[count].Cells["宽度"].Value.ToString();//长 dr[1] = polyView.Rows[count].Cells["高度"].Value.ToString();//宽 dr[2] = polyView.Rows[count].Cells["数量"].Value.ToString();//数量 dr[3] = polyView.Rows[count].Cells["模板号"].Value.ToString();//模板号 dr[4] = polyView.Rows[count].Cells["长磨1"].Value != null ? polyView.Rows[count].Cells["长磨1"].Value.ToString() : "0";//上 dr[5] = polyView.Rows[count].Cells["长磨2"].Value != null ? polyView.Rows[count].Cells["短磨1"].Value.ToString() : "0";//下 dr[6] = polyView.Rows[count].Cells["短磨1"].Value != null ? polyView.Rows[count].Cells["长磨2"].Value.ToString() : "0";//左 dr[7] = polyView.Rows[count].Cells["短磨2"].Value != null ? polyView.Rows[count].Cells["短磨2"].Value.ToString() : "0";//右 dr[8] = polyView.Rows[count].Cells["加工信息"].Value != null ? polyView.Rows[count].Cells["加工信息"].Value.ToString() : "";//加工信息 dr[9] = polyView.Rows[count].Cells["流程卡号"].Value != null ? polyView.Rows[count].Cells["流程卡号"].Value.ToString() : "";//订单编号 dr[10] = polyView.Rows[count].Cells["客户名称"].Value != null ? polyView.Rows[count].Cells["客户名称"].Value.ToString() : "";//客户名称 dr[11] = polyView.Rows[count].Cells["产品名称"].Value != null ? polyView.Rows[count].Cells["产品名称"].Value.ToString() : "";//产品名称 dr[12] = polyView.Rows[count].Cells["单价"].Value != null ? polyView.Rows[count].Cells["单价"].Value.ToString() : "";//单价 dr[13] = polyView.Rows[count].Cells["备注"].Value != null ? polyView.Rows[count].Cells["备注"].Value.ToString() : "";//备注 dr[14] = polyView.Rows[count].Cells["楼层编号"].Value != null ? polyView.Rows[count].Cells["楼层编号"].Value.ToString() : "";//楼层编号 dr[15] = polyView.Rows[count].Cells["架号"].Value != null ? polyView.Rows[count].Cells["架号"].Value.ToString() : "";//架号 //string str = dgv.Rows[count].Cells[5].Value.ToString(); //dr[16] = str.Replace("\r\n", "enter").Replace(",", "^");//Str dt.Rows.Add(dr); } return dt; } #region 导入导出CSV文件 //导出CSV public void ExportCSV(string filename) { FileStream file = new FileStream(filename + ".csv", FileMode.Create); StreamWriter writer = new StreamWriter(file); DataTable dt = GetDgvToTableCSV(polyView); string s = ""; foreach (DataColumn dc in dt.Columns) s += "," + dc.ColumnName; s = s.Substring(1); writer.WriteLine(s); foreach (DataRow row in dt.Rows) { s = ""; for (int i = 0; i < dt.Columns.Count; i++) s += "," + row[i].ToString().Trim(); s = s.Substring(1); writer.WriteLine(s); } writer.Flush(); writer.Close(); file.Close(); System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(filename + ".csv")); } public void ImportCSV(string filename) { StreamReader reader = new StreamReader(filename, System.Text.Encoding.Default); string s = reader.ReadLine(); if (s.Contains("宽度,高度,数量,图号,长磨1,短磨1,长磨2,短磨2") || s.Contains("X Dim,Y Dim,QTY,Shape,X1 Grind,Y1 Grind,X2 Grind,Y2 Grind")) { string xlsfileName = Path.GetFileNameWithoutExtension(filename); projectnameText.Text = xlsfileName; s = reader.ReadLine(); while (s != null && s.Trim() != "") { s = "0`" + s.Replace(",", "`"); polyView.Rows.Add(DisplayPack.PolyNewRowBittengCSV(polyView, s.Replace("enter", "\r\n"))); s = reader.ReadLine(); } } else { DataTable dt = new DataTable(); string[] array = s.Split(','); List columns = new List(); for (int i = 0; i < array.Length; i++) { if (i != array.Length - 1 && array[i].Trim().Length > 1 && array[i].Trim().Substring(0, 1) == "\"" && array[i + 1].Trim().Length > 1 && array[i + 1].Trim().Substring(array.Length - 1, 1) == "\"") { columns.Add(array[i].Substring(1) + array[i + 1].Substring(0, array.Length - 1)); i++; } else columns.Add(array[i]); } foreach (string c in columns) dt.Columns.Add(c); DataRow row; while (s != null && s.Trim() != "") { row = dt.NewRow(); array = s.Split(','); columns = new List(); for (int i = 0; i < array.Length; i++) { if (i != array.Length - 1 && array[i].Trim().Length > 1 && array[i].Trim().Substring(0, 1) == "\"" && array[i + 1].Trim().Length > 1 && array[i + 1].Trim().Substring(array.Length - 1, 1) == "\"") { columns.Add(array[i].Substring(1) + array[i + 1].Substring(0, array.Length - 1)); i++; } else columns.Add(array[i]); if (columns.Count == dt.Columns.Count) break; } for (int i = 0; i < columns.Count; i++) if (i < dt.Columns.Count) row[i] = columns[i]; dt.Rows.Add(CopyRow(dt, row)); s = reader.ReadLine(); } 从Excel导入成品信息 form = new 从Excel导入成品信息(dt, filename, this); form.ShowDialog(); } } DataRow CopyRow(DataTable dt, DataRow r) { DataRow row = dt.NewRow(); row.ItemArray = (object[])r.ItemArray.Clone(); return row; } #endregion private string getStrByRow(DataGridViewRow row) { string str = row.Cells["Str"].Value.ToString(); string laiyuan = row.Cells["模板号"].Value.ToString().Trim(); if (row.Cells["架号"].Value == null) row.Cells["架号"].Value = ""; if (row.Cells["客户名称"].Value == null) row.Cells["客户名称"].Value = ""; if (row.Cells["订单编号"].Value == null) row.Cells["订单编号"].Value = ""; if (row.Cells["产品名称"].Value == null) row.Cells["产品名称"].Value = ""; if (row.Cells["备注"].Value == null) row.Cells["备注"].Value = ""; if (row.Cells["楼层编号"].Value == null) row.Cells["楼层编号"].Value = ""; if (row.Cells["单价"].Value == null) row.Cells["单价"].Value = "0.0"; if (row.Cells["加工信息"].Value == null) row.Cells["加工信息"].Value = ""; #region 来自模板 if (laiyuan != "0")//模板 { Polygon poly = new Polygon(); poly.ABS_Deserialize(str); poly.isRect = (laiyuan == "100"); if (poly.isRect == true)//矩形 { poly.width = (float)Convert.ToDouble(row.Cells["宽度"].Value.ToString()); poly.height = (float)Convert.ToDouble(row.Cells["高度"].Value.ToString()); poly = Tranform.trans(100, poly.height, poly.h1, poly.h2, poly.width, poly.g1, poly.g2, poly.r, poly.r1, poly.r2); poly.width = (float)Convert.ToDouble(row.Cells["宽度"].Value.ToString()); poly.height = (float)Convert.ToDouble(row.Cells["高度"].Value.ToString()); poly.realwidth = poly.width; poly.realheight = poly.height; poly.isRect = true; } if (poly.isRect) { if (Functions.getpointlength(poly.getPointByIndex(0), poly.getPointByIndex(1)) >= Functions.getpointlength(poly.getPointByIndex(1), poly.getPointByIndex(2))) { poly.getPointByIndex(0).L = (float)Convert.ToDouble(row.Cells["长磨1"].Value.ToString()); poly.getPointByIndex(2).L = (float)Convert.ToDouble(row.Cells["长磨2"].Value.ToString()); poly.getPointByIndex(1).L = (float)Convert.ToDouble(row.Cells["短磨1"].Value.ToString()); poly.getPointByIndex(3).L = (float)Convert.ToDouble(row.Cells["短磨2"].Value.ToString()); } else { poly.getPointByIndex(1).L = (float)Convert.ToDouble(row.Cells["长磨1"].Value.ToString()); poly.getPointByIndex(3).L = (float)Convert.ToDouble(row.Cells["长磨2"].Value.ToString()); poly.getPointByIndex(0).L = (float)Convert.ToDouble(row.Cells["短磨1"].Value.ToString()); poly.getPointByIndex(2).L = (float)Convert.ToDouble(row.Cells["短磨2"].Value.ToString()); } if (Math.Max(poly.points[0].L, poly.points[1].L) > 0 || Math.Max(poly.points[2].L, poly.points[3].L) > 0) { poly.mobians = new float[4]; poly.mobians[0] = poly.getPointByIndex(0).L; poly.mobians[1] = poly.getPointByIndex(1).L; poly.mobians[2] = poly.getPointByIndex(2).L; poly.mobians[3] = poly.getPointByIndex(3).L; } } poly.originjiahao = row.Cells["架号"].Value.ToString().Trim(); poly.customname = row.Cells["客户名称"].Value.ToString().Trim(); poly.orderid = row.Cells["订单编号"].Value.ToString().Trim(); poly.productname = row.Cells["产品名称"].Value.ToString().Trim(); poly.remarks = row.Cells["备注"].Value.ToString().Trim(); poly.floornumber = row.Cells["楼层编号"].Value.ToString().Trim(); poly.price = Convert.ToDouble(row.Cells["单价"].Value.ToString().Trim()); poly.lable = row.Cells["加工信息"].Value.ToString(); poly.xuhao = row.Cells["序号"].Value.ToString(); poly.fixMiniRec(); return poly.ABS_Serialize()[0]; } #endregion #region 来自dxf else { try { dxfPolygon dxfpoly = new dxfPolygon(); dxfpoly.ABS_Deserialize(str); Polygon poly = dxfpoly.ToPolygon(); poly.realwidth = (float)Convert.ToDouble(row.Cells["宽度"].ToString()); poly.realheight = (float)Convert.ToDouble(row.Cells["高度"].ToString()); poly.originjiahao = row.Cells["架号"].ToString().Trim(); poly.customname = row.Cells["客户名称"].ToString().Trim(); poly.orderid = row.Cells["订单编号"].ToString().Trim(); poly.productname = row.Cells["产品名称"].ToString().Trim(); poly.count = Convert.ToInt32(row.Cells["数量"]); poly.remarks = row.Cells["备注"].ToString().Trim(); poly.floornumber = row.Cells["楼层编号"].ToString().Trim(); poly.price = Convert.ToDouble(row.Cells["单价"].ToString().Trim()); poly.lable = row.Cells["加工信息"].ToString(); poly.xuhao = row.Cells["序号"].ToString(); poly.fixMiniRec(); poly.width = (float)Math.Max(Convert.ToDouble(row.Cells["宽度"].Value.ToString()), Convert.ToDouble(row.Cells["高度"].Value.ToString())); poly.height = (float)Math.Min(Convert.ToDouble(row.Cells["宽度"].Value.ToString()), Convert.ToDouble(row.Cells["高度"].Value.ToString())); Polygon expanded = poly.Expand(false); return expanded.ABS_Serialize()[1]; } catch (Exception ex) { return ""; } } #endregion } public void setXiubian() { for (int i = 0; i < polyView.Rows.Count; i++) { if (polyView.AllowUserToAddRows && i == polyView.Rows.Count - 1) break; DataGridViewRow row = polyView.Rows[i]; string laiyuan = row.Cells[4].Value.ToString().Trim(); string str; if (row.Cells["Str"].Value == null) str = ""; else str = row.Cells["Str"].Value.ToString().Trim(); string xiubianinfo; if (str != "" && laiyuan != "100") { if (laiyuan == "0") { dxfPolygon poly = new dxfPolygon(); poly.ABS_Deserialize(str); poly.top = Setting.pinjiexiubian; poly.down = Setting.pinjiexiubian; poly.left = Setting.pinjiexiubian; poly.right = Setting.pinjiexiubian; row.Cells["Str"].Value = poly.ABS_Serialize(); } else { Polygon poly = new Polygon(); poly.ABS_Deserialize(str); xiubianinfo = Functions.getXiubianInfo(Convert.ToInt32(laiyuan)); poly.left = 0; poly.right = 0; poly.top = 0; poly.down = 0; if (xiubianinfo.Contains("上")) poly.down = Setting.pinjiexiubian; if (xiubianinfo.Contains("下")) poly.top = Setting.pinjiexiubian; if (xiubianinfo.Contains("左")) poly.left = Setting.pinjiexiubian; if (xiubianinfo.Contains("右")) poly.right = Setting.pinjiexiubian; row.Cells["Str"].Value = poly.ABS_Serialize()[0]; } } } } private string transEn2Cha(String s) { switch (s) { case "Quantity": return "数量"; case "Long Grind1": return "长磨1"; case "Long Grind2": return "长磨2"; case "Short Grind1": return "短磨1"; case "Short Grind2": return "短磨2"; case "Note": return "加工信息"; case "Customer": return "客户名称"; case "Order": return "订单编号"; case "Product": return "产品名称"; case "Price": return "单价"; case "Remarks": return "备注"; case "Floor No.": return "楼层编号"; default: return s; } } private string getMobianInfo(string str, string temp) { if (temp == "") { dxfPolygon dxfpoly = new dxfPolygon(); dxfpoly.ABS_Deserialize(str); return dxfpoly.top + "^" + dxfpoly.down + "^" + dxfpoly.left + "^" + dxfpoly.right; } else { Polygon temppoly = new Polygon(); temppoly.ABS_Deserialize(str); return temppoly.top + "^" + temppoly.down + "^" + temppoly.left + "^" + temppoly.right; } } private void 复用第一行数据ToolStripMenuItem_Click(object sender, EventArgs e) { if (polyView.SelectedCells.Count > 0) { try { Dictionary rowindexs = new Dictionary(); Dictionary value = new Dictionary();//columnindex,值 for (int i = 0; i < polyView.SelectedCells.Count; i++) if (polyView.SelectedCells[i].Value == null) polyView.SelectedCells[i].Value = ""; foreach (DataGridViewCell cell in polyView.SelectedCells) { if (!value.ContainsKey(cell.ColumnIndex)) { value.Add(cell.ColumnIndex, cell.Value.ToString()); rowindexs.Add(cell.ColumnIndex, cell.RowIndex); } else if (cell.RowIndex < rowindexs[cell.ColumnIndex]) { value[cell.ColumnIndex] = cell.Value.ToString(); rowindexs[cell.ColumnIndex] = cell.RowIndex; } } for (int i = 0; i < polyView.SelectedCells.Count; i++) { polyView.SelectedCells[i].Value = value[polyView.SelectedCells[i].ColumnIndex]; } } catch { } } } int currentsortindex = -1, sortmode = 0; private void polyView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.ColumnIndex <= 2) { if (globel.ShowFromConfirmMessage("排序操作不可逆,将会丢失现有顺序,是否继续操作?")) { if (currentsortindex == e.ColumnIndex) { if (sortmode == 0) { polyView.Sort(polyView.Columns[e.ColumnIndex], System.ComponentModel.ListSortDirection.Ascending); sortmode = 1; } else { polyView.Sort(polyView.Columns[e.ColumnIndex], System.ComponentModel.ListSortDirection.Descending); sortmode = 0; } } else { polyView.Sort(polyView.Columns[e.ColumnIndex], System.ComponentModel.ListSortDirection.Ascending); sortmode = 1; currentsortindex = e.ColumnIndex; } } } } #region 导出 private void exportexcel_Click(object sender, EventArgs e)//导出到excel { if (polyView.Rows.Count == 1) { return; } polyView.EndEdit(); if (polyView.CurrentRow != null) refreshSTR(polyView.CurrentRow); System.Data.DataTable dt = GetDgvToTable(); string fileName = txtProjectNo.Text + "成品列表数据_" + DateTime.Now.ToString("yyyyMMddHHmmss"); string filePath = ""; if (globel.DataReportMode == "数据流") { filePath = DataGrieViewReport.StreamReport(dt, fileName); } else { filePath = DataGrieViewReport.OfficeReport(dt, fileName); } if (!string.IsNullOrWhiteSpace(filePath)) { if (globel.ShowFromConfirmMessage(txtProjectNo.Text + "成品列表数据文档保存成功\r\n文档路径:" + filePath + "\r\n\r\n是否打开文件?")) { fileUtil.SysOpenFile(filePath); } } } #endregion #region 导入 private void importexcel_Click(object sender, EventArgs e)//导入excel { polyView.AllowUserToAddRows = true; OpenFileDialog dia = new OpenFileDialog { InitialDirectory = Setting.btdir, Title = "Select File", Filter = "Excel File|*.xls;*.xlsx;*.csv", Multiselect = true, RestoreDirectory = true }; if (dia.ShowDialog() == DialogResult.OK) { polyView.Rows.Clear(); if (Path.GetExtension(dia.FileName) == ".csv") { ImportCSV(dia.FileName); ManualMode = true; } else if (!rightTable(dia.FileName)) { 选择工作表 form = new 选择工作表(dia.FileName, this); form.ShowDialog(); } ManualProject(); } } #endregion #region 粘贴、复制 private void paste_Click(object sender, EventArgs e)//粘贴 { DataGirdViewCellPaste(polyView); } private void copy_Click(object sender, EventArgs e)//复制 { DataGridViewEnableCopy(); } #endregion #region 添加\修改异形 private void addyixing_Click(object sender, EventArgs e)//添加异形 { 选择模板 geo = new 选择模板(this); geo.ShowDialog(); } private void updateyixing_Click(int i, float w = 0, float h = 0) { 选择模板 geo = new 选择模板(this, i, w, h); geo.ShowDialog(); } #endregion public static bool isremoving = false; private void 删除当前行ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in polyView.SelectedRows) { try { isremoving = true; if (pack == null) { Logger.Info($"删除了行{row.Index};玻璃ID:{row.Cells["备注"].Value}"); polyView.Rows.Remove(row); Setting.settingchaged = true; } else { globel.ShowFromWarningMessage("已经优化的工程不允许删除小片,可以尝试将小片数量改为0"); return; } isremoving = false; } catch { isremoving = false; } } if (!Setting.danji && polyView.Rows.Count <= 1) { norenwudan(); } } #region 更新原片库的用量 /// /// 更新优化使用的原片用量 /// public void updateStockList()//更新原片库的用量 { if (pack == null) return; List stocklist = Functions.mergeSameSize(pack.mergedstocks); int rowCount = stockView.AllowUserToAddRows ? stockView.Rows.Count - 1 : stockView.Rows.Count; int stockNum = 0;//原片数量 double stockArea = 0; foreach (Stock stock in stocklist) { for (int i = 0; i < rowCount; i++) { //if (stockView.Rows[i].Cells["大片宽"].Value.ToString().Trim() == stock.Width.ToString().Trim() && // stockView.Rows[i].Cells["大片高"].Value.ToString().Trim() == stock.Height.ToString().Trim() && // stockView.Rows[i].Cells["厚度"].Value.ToString().Trim() == stock.Thickness.ToString().Trim() && // (stockView.Rows[i].Cells["物料代码"].Value == null || // stockView.Rows[i].Cells["物料代码"].Value != null && stockView.Rows[i].Cells["物料代码"].Value.ToString().Trim() == stock.wuliaodaima.ToString().Trim()) // ) //row.Cells[0].Value != null && (Boolean)row.Cells[0].Value == true if (stockView.Rows[i].Cells[0].Value != null && (Boolean)stockView.Rows[i].Cells[0].Value == true) { if (stockView.Rows[i].Cells["物料代码"].Value != null && stockView.Rows[i].Cells["物料代码"].Value.ToString().Trim() == stock.wuliaodaima.ToString().Trim()) { //if (MessageBox.Show("确认原片类型 【" + stock.Width.ToString() + "X" + stock.Height + " " + stock.Thickness + "mm " + stock.glassType + " 】减少" + stock.lingliaoCount + "片吗?", // "确认减少原片库存量", MessageBoxButtons.OKCancel) == DialogResult.OK) { //stockView.Rows[i].Cells["库存量"].Value = Convert.ToInt32(stockView.Rows[i].Cells["库存量"].Value) - stock.lingliaoCount; stockView.Rows[i].Cells["用量"].Value = stock.lingliaoCount; stockNum += stock.lingliaoCount; } } } else { stockView.Rows[i].Cells["用量"].Value = ""; } } stockArea += stock.realheight * stock.realwidth * stock.lingliaoCount; } YPMJ.Text = stockArea * Math.Pow(10, -6) + ""; YPSL.Text = stockNum + ""; } #endregion #region 主菜单 #region 主导航颜色变化 string currentClickTsmi;//当前点击的导航 /// /// 主导航鼠标进入颜色变更 /// /// 导航Text public void MianNavbarChangeColor(string nName) { foreach (ToolStripMenuItem item in menuStrip1.Items) { if (item.Text == currentClickTsmi) { continue; } if (item.Text == nName || item.Name == "TSMIUserInfo") { item.BackColor = ColorUtil.bgQColor; item.ForeColor = ColorUtil.bgSColor; } else { item.BackColor = ColorUtil.bgSColor; item.ForeColor = ColorUtil.bgQColor; } } } /// /// 主导航鼠标点击后颜色 /// /// public void MainNavbarClickChangeColor(ToolStripMenuItem tsmi) { currentClickTsmi = tsmi.Text; foreach (ToolStripMenuItem item in menuStrip1.Items) { if (item == tsmi) { item.BackColor = ColorUtil.bgClickColor; item.ForeColor = ColorUtil.bgSColor; } else if (item.Name != "TSMIUserInfo") { item.BackColor = ColorUtil.bgSColor; item.ForeColor = ColorUtil.bgQColor; } } } #endregion #region 主导航点击 //文件 private void 录入成品ToolStripMenuItem_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(录入成品ToolStripMenuItem); mainTab.SelectedIndex = 0; } //打印 private void 优化版面ToolStripMenuItem_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(优化版面ToolStripMenuItem); if (pack != null) { mainTab.SelectedIndex = 1; } } //调整 private void 手工排版ToolStripMenuItem_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(手工排版ToolStripMenuItem); if (pack != null) { mainTab.SelectedIndex = 2; } } //数控 private void 设备驱动ToolStripMenuItem_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(设备驱动menu); if (pack != null) { mainTab.SelectedIndex = 3; } } //手工 private void 手工切割ToolStripMenuItem_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(手工切割ToolStripMenuItem); mainTab.SelectedIndex = 4; } //设置 private void 设置_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(TSMISystemSet); 参数设定 setupform = new 参数设定(this); setupform.ShowDialog(); } //报告 private void 成品标签ToolStripMenuItem_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(打印标签ToolStripMenuItem); if (pack != null) { mainTab.SelectedIndex = 5; } } //关于 private void TSMIAbout_Click(object sender, EventArgs e) { MainNavbarClickChangeColor(TSMIAbout); 关于 about = new 关于(); about.ShowDialog(); } #endregion #region 主导航鼠标进入 private void 手工切割ToolStripMenuItem_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(手工切割ToolStripMenuItem.Text); } private void 打印标签ToolStripMenuItem_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(打印标签ToolStripMenuItem.Text); } private void 设备驱动menu_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(设备驱动menu.Text); } private void 手工排版ToolStripMenuItem_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(手工排版ToolStripMenuItem.Text); } private void 优化版面ToolStripMenuItem_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(优化版面ToolStripMenuItem.Text); } private void 录入成品ToolStripMenuItem_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(录入成品ToolStripMenuItem.Text); } private void 系统设置ToolStripMenuItem_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(TSMISystemSet.Text); } private void TSMIAbout_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(TSMIAbout.Text); } private void TSMIUserInfo_MouseEnter(object sender, EventArgs e) { MianNavbarChangeColor(TSMIUserInfo.Text); } #endregion private void 缩略图ToolStripMenuItem_Click(object sender, EventArgs e) { if (banmian == null) return; if (pack == null) return; banmian.smallpic = true; banmian.drawPack(); mainTab.SelectedIndex = 1; } #region 最前一页 private void TSMIFirstPage_Click(object sender, EventArgs e) { if (banmian == null) return; if (pack == null) return; 任务.pagenumber = 0; drawPack(); mainTab.SelectedIndex = 1; } #endregion private void toolStripMenuItem18_Click(object sender, EventArgs e) { if (banmian == null) return; if (pack == null) return; 任务.pagenumber = pack.mergedstocks.Count - 1; drawPack(); mainTab.SelectedIndex = 1; } private void toolStripMenuItem16_Click(object sender, EventArgs e) { if (banmian == null) return; banmian.PreviousPage(banmian.pack); banmian.drawPack(); mainTab.SelectedIndex = 1; } private void toolStripMenuItem17_Click(object sender, EventArgs e) { if (banmian == null) return; banmian.nextPage(banmian.pack); banmian.drawPack(); mainTab.SelectedIndex = 1; } private void 操作提示ToolStripMenuItem_Click(object sender, EventArgs e) { if (rengong == null) return; 人工操作提示 tishi = new 人工操作提示(); tishi.ShowDialog(); if (pack != null) { mainTab.SelectedIndex = 2; } } private void 新增版面ToolStripMenuItem_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.新增版面_Click(sender, e); mainTab.SelectedIndex = 2; } private void 删除版面ToolStripMenuItem_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.删除版面_Click(sender, e); mainTab.SelectedIndex = 2; } private void 增加加工次数_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.增加多版_Click(sender, e); mainTab.SelectedIndex = 2; } private void 导出未排版小片ToolStripMenuItem_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.导出剩余_Click(sender, e); mainTab.SelectedIndex = 2; } private void 撤销自动排版结果ToolStripMenuItem_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.全部撤回_Click(sender, e); mainTab.SelectedIndex = 2; } private void X镜像_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.X镜像_Click(sender, e); mainTab.SelectedIndex = 2; } private void Y镜像_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.Y镜像_Click(sender, e); mainTab.SelectedIndex = 2; } private void X镜像当前版_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.X镜像当前版_Click(sender, e); mainTab.SelectedIndex = 2; } private void Y镜像当前版_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.Y镜像当前版_Click(sender, e); mainTab.SelectedIndex = 2; } private void 保存修改ToolStripMenuItem_Click(object sender, EventArgs e) { if (rengong == null) return; if (pack == null) return; rengong.保存_Click(sender, e); mainTab.SelectedIndex = 2; } public void 刷新刀路ToolStripMenuItem_Click(object sender, EventArgs e) { if (qudong == null) return; qudong.pack = 任务.pack; if (pack == null) return; qudong.重新自动生成ToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 3; } private void 截断连续线ToolStripMenuItem_Click(object sender, EventArgs e) { if (qudong == null) return; if (pack == null) return; qudong.截断连续线ToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 3; } private void 删除刀路ToolStripMenuItem_Click(object sender, EventArgs e) { if (qudong == null) return; if (pack == null) return; qudong.删除对象_Click(sender, e); mainTab.SelectedIndex = 3; } private void 反向刀路ToolStripMenuItem_Click(object sender, EventArgs e) { if (qudong == null) return; if (pack == null) return; qudong.反向_Click(sender, e); mainTab.SelectedIndex = 3; } public void 保存图片_Click(object sender, EventArgs e) { if (pack == null) return; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { if (!File.Exists(folderBrowserDialog1.SelectedPath + "\\" + pack.packingName)) Directory.CreateDirectory(folderBrowserDialog1.SelectedPath + "\\" + pack.packingName); for (int i = 0; i < pack.mergedstocks.Count; i++) { Bitmap dismap = pack.mergedstocks[i].getbitmapFromPolys(banmian.pictureBox1.Width - 50, banmian.pictureBox1.Height - 70, Color.WhiteSmoke, true); Bitmap resultmap = new Bitmap(banmian.pictureBox1.Width, banmian.pictureBox1.Height); Stock currentstock = pack.mergedstocks[i]; float stockratio = Math.Min((banmian.pictureBox1.Width - 50) / (currentstock.Width + currentstock.Right + currentstock.Left), (banmian.pictureBox1.Height - 70) / (currentstock.Height + currentstock.Up + currentstock.Down)); double Ytrans = (banmian.pictureBox1.Height - dismap.Height) / 2.0 + currentstock.Up * stockratio; Graphics r = Graphics.FromImage(resultmap); r.Clear(Color.WhiteSmoke); r.DrawImage(dismap, new Point((resultmap.Width - dismap.Width) / 2, (int)Ytrans + 40)); string str = pack.getMergedinfostring(i); Font font = new System.Drawing.Font("微软雅黑", 11); SizeF size = r.MeasureString(str, font); if (size.Width > (int)(stockratio * pack.mergedstocks[i].Width)) str = pack.getShortInfostring(任务.pagenumber); r.DrawString(str, font, new SolidBrush(Color.DarkBlue), (resultmap.Width - dismap.Width) / 2, 10); //return resultmap; //Bitmap dismap = pack.mergedstocks[i].getbitmapFromPolys(pack.mergedstocks[i].Width / 2, pack.mergedstocks[i].Height / 2, Color.WhiteSmoke, true); //Bitmap resultmap = new Bitmap((int)pack.mergedstocks[i].Width / 2 + 50, (int)pack.mergedstocks[i].Height / 2 + 50); //Graphics r = Graphics.FromImage(resultmap); //r.Clear(Color.White); //r.DrawImage(dismap, new System.Drawing.Point((resultmap.Width - dismap.Width) / 2, 40)); //string str = pack.getMergedinfostring(i); //Font font = new System.Drawing.Font("微软雅黑", 12); //SizeF size = r.MeasureString(str, font); //r.DrawString(str, font, new SolidBrush(Color.Black), (resultmap.Width - dismap.Width) / 2, 10); resultmap.Save(folderBrowserDialog1.SelectedPath + "\\" + pack.packingName + "\\" + (i + 1).ToString() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg); } } } private void 一行一列ToolStripMenuItem_Click(object sender, EventArgs e) { if (ImportXLSX || txtProjectNo.Text.Contains("SD")) { globel.ShowFromWarningMessage("手动工程不支持当前操作!"); return; }; if (reportform == null) return; reportform.pack = pack; if (reportform.pack == null) return; if (!IsContinue()) return; ToolStripDropDownItem item = (ToolStripDropDownItem)sender; Setting.bantustart = 0; Setting.bantuend = 49; switch (item.Text) { case "打印优化报告(T)": case "Print Report(T)": reportform.printreport.Checked = true; reportform.bantucheck.Checked = false; reportform.printReport(); break; case "一行一列": case "one row one column": reportform.printreport.Checked = false; reportform.bantucheck.Checked = true; Setting.optrow = 1; Setting.optcol = 1; Setting.UpdateSetting(); reportform.printReport(); break; case "二行一列": case "two rows one column": reportform.printreport.Checked = false; reportform.bantucheck.Checked = true; Setting.optrow = 2; Setting.optcol = 1; Setting.UpdateSetting(); reportform.printReport(); break; case "三行一列": case "three rows one column": reportform.printreport.Checked = false; reportform.bantucheck.Checked = true; Setting.optrow = 3; Setting.optcol = 1; Setting.UpdateSetting(); reportform.printReport(); break; case "二行二列": case "two rows two columns": reportform.printreport.Checked = false; reportform.bantucheck.Checked = true; Setting.optrow = 2; Setting.optcol = 2; Setting.UpdateSetting(); reportform.printReport(); break; case "三行二列": case "three rows two columns": reportform.printreport.Checked = false; reportform.bantucheck.Checked = true; Setting.optrow = 3; Setting.optcol = 2; Setting.UpdateSetting(); reportform.printReport(); break; case "四行二列": case "four rows two columns": reportform.printreport.Checked = false; reportform.bantucheck.Checked = true; Setting.optrow = 4; Setting.optcol = 2; Setting.UpdateSetting(); reportform.printReport(); break; } mainTab.SelectedIndex = 6; if (pack.mergedstocks.Count > 50) { reportform.panel1.Visible = true; reportform.second.Visible = true; if (pack.mergedstocks.Count <= 100) reportform.second.Text = "51-" + pack.mergedstocks.Count + "版"; } else { reportform.panel1.Visible = false; reportform.second.Visible = false; } if (pack.mergedstocks.Count > 100) { reportform.third.Visible = true; if (pack.mergedstocks.Count <= 150) reportform.third.Text = "101-" + pack.mergedstocks.Count + "版"; } else { reportform.third.Visible = false; } if (pack.mergedstocks.Count > 150) { reportform.forth.Visible = true; if (pack.mergedstocks.Count <= 200) reportform.forth.Text = "151-" + pack.mergedstocks.Count + "版"; } else { reportform.forth.Visible = false; } if (pack.mergedstocks.Count > 200) { reportform.fifth.Visible = true; if (pack.mergedstocks.Count <= 250) reportform.fifth.Text = "201-" + pack.mergedstocks.Count + "版"; } else { reportform.fifth.Visible = false; } } private void 设计标签样式ToolStripMenuItem_Click(object sender, EventArgs e) { 新建标签 biaoqianform = new 新建标签(pack, 任务.simpleorder); biaoqianform.ShowDialog(); } public void editStyle(int styleindex)//新建标签样式 { 新建标签 create = new 新建标签(Setting.biaoqianstyles[styleindex].name, pack, 任务.simpleorder); create.ShowDialog(); } private void 选择标签样式ToolStripMenuItem_Click(object sender, EventArgs e) { 查看标签 setupform = new 查看标签(this); setupform.ShowDialog(); } private void 生成流程卡ToolStripMenuItem_Click(object sender, EventArgs e) { if (reportform == null) return; if (pack == null) return; reportform.printlck_Click(sender, e); mainTab.SelectedIndex = 4; } private void 新增版图ToolStripMenuItem_Click(object sender, EventArgs e) { if (shouqie == null) return; shouqie.新建版图ToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 4; } private void 删除版图ToolStripMenuItem_Click(object sender, EventArgs e) { if (shouqie == null) return; shouqie.删除版图ToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 4; } private void 新建ToolStripMenuItem1_Click(object sender, EventArgs e) { if (shouqie == null) return; shouqie.新建ToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 4; } private void 维宏ToolStripMenuItem_Click(object sender, EventArgs e) { if (shouqie == null) return; shouqie.维宏ToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 4; } private void oPTIMAToolStripMenuItem_Click(object sender, EventArgs e) { if (shouqie == null) return; shouqie.oPTToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 4; } private void 宝伦ToolStripMenuItem_Click(object sender, EventArgs e) { if (shouqie == null) return; shouqie.宝伦ToolStripMenuItem_Click(sender, e); mainTab.SelectedIndex = 4; } #endregion #region 导入DXF private void 导入DXF_Click(object sender, EventArgs e) { polyView.AllowUserToAddRows = true; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { 导入DXF dxfinport = new 导入DXF(this, folderBrowserDialog1.SelectedPath, true); dxfinport.ShowDialog(); } ManualProject(); } private void 导入单个DXFToolStripMenuItem_Click(object sender, EventArgs e)//导入单个DXF文件 { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "DXF file|*.dxf"; if (dialog.ShowDialog() == DialogResult.OK) { FileInfo file = new FileInfo(dialog.FileName); DxfDocument dxf = DxfDocument.Load(file.FullName); dxf.YMirror(); StreamReader reader = new StreamReader(dxf.ToStream()); string dxftext = reader.ReadToEnd();//把DXF转化成字符串 reader.Close(); dxfPolygon currentdxf = new dxfPolygon(); currentdxf.dxftext = dxftext; // selectedTemp = currentdxf.ToPolygon(); string dxffilename = file.FullName; string orderid = Path.GetFileNameWithoutExtension(file.Name); Polygon dxfpoly = null; try { dxfpoly = dxf.ToPolygon();//将dxf转为Polygon,仅限三角形和四边形,转了之后就可以组合优化了 //dxfpoly.down = (float)Convert.ToDouble(DownTxt.Text); //dxfpoly.top = (float)Convert.ToDouble(TopTxt.Text); //dxfpoly.left = (float)Convert.ToDouble(LeftTxt.Text); //dxfpoly.right = (float)Convert.ToDouble(RightTxt.Text); } catch { } int pjcount = 1; if (!(orderid.Split('_').Length == 4 && Int32.TryParse(orderid.Split('_')[3], out pjcount))) { pjcount = 1; } if (dxfpoly != null) { dxfpoly.count = pjcount; addToGrid(dxfpoly); } else addToGrid(dxf, currentdxf, pjcount, orderid); List results = new List(); foreach (netDxf.Entities.EntityObject o in dxf.addedEntity.Values) { if (o.Type == netDxf.Entities.EntityType.LightWeightPolyline) { netDxf.Entities.LwPolyline line = (netDxf.Entities.LwPolyline)o; int n = line.Vertexes.Count; double x = line.Vertexes[0].Location.X; } } ManualProject(); } } private void 分割后导入DXFToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "DXF file|*.dxf"; if (dialog.ShowDialog() == DialogResult.OK) { 分割DXF dxfinport = new 分割DXF(this, dialog.FileName); dxfinport.ShowDialog(); } } #endregion private void projectnameText_TextChanged(object sender, EventArgs e) { if (projectnameText.Text.Contains("[") || projectnameText.Text.Contains("_") || projectnameText.Text.Contains("*") || projectnameText.Text.Contains("+") || projectnameText.Text.Contains("#") || projectnameText.Text.Contains("%") || projectnameText.Text.Contains("(") || projectnameText.Text.Contains(")")) { globel.ShowWarningMessage("工程名称只能包含数字、中文和英文字符"); projectnameText.Text = ""; } } private void 插入相同行数量为0ToolStripMenuItem_Click(object sender, EventArgs e) { if (polyView.SelectedRows.Count == 0) return; polyView.Rows.Insert(polyView.SelectedRows[0].Index + 1, polyView.SelectedRows[0].Clone()); DataGridViewRow gridrow = polyView.Rows[polyView.SelectedRows[0].Index + 1]; for (int j = 0; j < polyView.Columns.Count; j++) gridrow.Cells[j].Value = (polyView.SelectedRows[0].Cells[j].Value == null ? "" : polyView.SelectedRows[0].Cells[j].Value); gridrow.Cells["数量"].Value = 0; Setting.settingchaged = true; } #region XY镜像 private void x镜像ToolStripMenuItem_Click(object sender, EventArgs e) { DataGridViewRow gridrow = polyView.Rows[polyView.CurrentCell.RowIndex]; Polygon p = new Polygon(); p.ABS_Deserialize(gridrow.Cells["Str"].Value.ToString()); p.X_mirror(); gridrow.Cells["Str"].Value = p.ABS_Serialize()[0]; Setting.settingchaged = true; } private void y镜像ToolStripMenuItem_Click(object sender, EventArgs e) { DataGridViewRow gridrow = polyView.Rows[polyView.CurrentCell.RowIndex]; Polygon p = new Polygon(); p.ABS_Deserialize(gridrow.Cells["Str"].Value.ToString()); p.Y_mirror(); gridrow.Cells["Str"].Value = p.ABS_Serialize()[0]; Setting.settingchaged = true; } #endregion #region 标签设计 private void TSMILabelPlan_Click(object sender, EventArgs e) { 新建标签 biaoqianform = new 新建标签(pack, 任务.simpleorder); biaoqianform.ShowDialog(); } #endregion #region 标签选择 private void TSMILableSelected_Click(object sender, EventArgs e) { 查看标签 setupform = new 查看标签(this); setupform.ShowDialog(); } #endregion #region 成品明细 private void TSMIFinishedProductName_Click(object sender, EventArgs e) { //reportform.成品明细_Click(sender, e); //mainTab.SelectedIndex = 6; } #endregion #region 打印版图和报告 private void TSMIPrintRangeAndReport_Click(object sender, EventArgs e) { /*if (ImportXLSX) { globel.ShowFromWarningMessage("手动工程不支持当前操作!", false); return; };*/ if (reportform == null) return; reportform.pack = pack; if (reportform.pack == null) return; if (!IsContinue()) return; ToolStripDropDownItem item = (ToolStripDropDownItem)sender; Setting.bantustart = 0; Setting.bantuend = 49; reportform.ResultTabControl.SelectedIndex = 0; switch (item.Text) { case "一行一列": case "one row one column": LayoutRowOrCol(1, 1, 0); break; case "二行一列": case "two rows one column": LayoutRowOrCol(2, 1, 0); break; case "三行一列": case "three rows one column": LayoutRowOrCol(3, 1, 0); break; case "二行二列": case "two rows two columns": LayoutRowOrCol(2, 2, 0); break; case "三行二列": case "three rows two columns": LayoutRowOrCol(3, 2, 0); break; case "四行二列": case "four rows two columns": LayoutRowOrCol(4, 2, 0); break; } MoreLayoutShowFun(); } #region 版图行和列设置 public void LayoutRowOrCol(int row, int column, int mode) { Setting.optrow = row; Setting.optcol = column; Setting.UpdateSetting(); if (mode == 1) { reportform.printReport(); } else { reportform.PrintReportAndLayout(); } } #endregion #region 大数量版图展示方法 /// /// 大数量版图展示方法 /// public void MoreLayoutShowFun() { mainTab.SelectedIndex = 6; if (pack.mergedstocks.Count > 50) { reportform.panel1.Visible = true; reportform.second.Visible = true; if (pack.mergedstocks.Count <= 100) reportform.second.Text = "51-" + pack.mergedstocks.Count + "版"; } else { reportform.panel1.Visible = false; reportform.second.Visible = false; } if (pack.mergedstocks.Count > 100) { reportform.third.Visible = true; if (pack.mergedstocks.Count <= 150) reportform.third.Text = "101-" + pack.mergedstocks.Count + "版"; } else { reportform.third.Visible = false; } if (pack.mergedstocks.Count > 150) { reportform.forth.Visible = true; if (pack.mergedstocks.Count <= 200) reportform.forth.Text = "151-" + pack.mergedstocks.Count + "版"; } else { reportform.forth.Visible = false; } if (pack.mergedstocks.Count > 200) { reportform.fifth.Visible = true; if (pack.mergedstocks.Count <= 250) reportform.fifth.Text = "201-" + pack.mergedstocks.Count + "版"; } else { reportform.fifth.Visible = false; } } #endregion #endregion #region 保存 private void uBtnSave_Click(object sender, EventArgs e) { try { Logger.Info($"进行了保存操作:{txtProjectNo.Text}"); if (pack == null) { globel.ShowFromWarningMessage(strNoResult); Logger.Info($"{strNoResult}"); return; } if (!IsContinue()) { return; } if (openProject != null && openProject.state == 20) { Logger.Info($"工程已保存"); globel.SHowNewFromOkMessage("工程已保存!", true); return; } if (globel.UserGroup == "补片") { MyGlasFile myglassfile = new MyGlasFile(pack, simpleorder); //string line = myglassfile.ToBtString();//调整前的结果 string line = myglassfile.toResultString();//调整后的结果,24.11.12 添加 openProject.glass_total = Convert.ToInt32(countTxt.Text.Trim()); StringBuilder sql = new StringBuilder(); foreach (DataGridViewRow dgvr in stockView.Rows) { if (dgvr.Cells[0].Value != null && (Boolean)dgvr.Cells[0].Value == true) { int type = dgvr.Cells["状态"].Value.ToString() == "余料" ? 0 : 1; string wldm = dgvr.Cells["物料代码"].Value.ToString(); string w = dgvr.Cells["大片宽"].Value.ToString(); string g = dgvr.Cells["大片高"].Value.ToString(); string yl = dgvr.Cells["用量"].Value == null ? "0" : dgvr.Cells["用量"].Value.ToString(); string left_trim = dgvr.Cells["X1修边"].Value.ToString(); string down_trim = dgvr.Cells["Y1修边"].Value.ToString(); string right_trim = dgvr.Cells["X2修边"].Value.ToString(); string up_trim = dgvr.Cells["Y2修边"].Value.ToString(); if (yl != "0") { sql.AppendFormat("Insert into optimize_use (project_no,raw_stock_code,type,width,height,use_count,not_use_count,creater,left_trim,down_trim,right_trim,up_trim)"); sql.AppendFormat("values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", openProject.project_no, wldm, type, w, g, yl, yl, LoginAdminInfo.id); sql.AppendFormat(",'{0}','{1}','{2}','{3}');", left_trim, down_trim, right_trim, up_trim); } } } openProject.name = projectnameText.Text; OperationModel om = PatchProjectDB.SavePatchOptimizeResult(openProject, pack, line, sql.ToString()); if (om.state) { openProject.state = 20; containerMsg.Visible = false; Logger.Info($"{openProject.project_no}:保存成功"); string savedSuccess = Setting.language != 0 ? "Saved successfully." : "保存成功!"; globel.SHowNewFromOkMessage(savedSuccess, true); //globel.SHowNewFromOkMessage("保存成功!", true); //自动上传 //if (globel.AutoUploadOffcut) //{ // OffcutDB.SyncOffcutToDB(openProject.project_no); //} } else { Logger.Info($"保存失败!\r\n位置:{om.errCode }\r描述:{ om.info}"); globel.SHowNewFromOkMessage("保存失败!\r\n位置:" + om.errCode + "\r\n描述:" + om.info, false); } return; } switch (openProject.state) { case -2: globel.ShowFromWarningMessage(strStateError); break; case 1://第一次优化保存 firstOptimizaSave(openProject.project_no); break; case 10://钢化模拟计算后,优化排版的保存 heatAnalogOptimizeSave(openProject.project_no); break; case 20://优化保存 case 100://允许生产 case 200://生产已领取 globel.ShowFromWarningMessage(strSaved); break; default: globel.ShowFromWarningMessage(strStateError); break; } return; } catch (Exception ex) { globel.ShowErrorMessage(ex.Message); } } //第一次优化保存 void firstOptimizaSave(string p_no) { MyGlasFile myglassfile = new MyGlasFile(pack, simpleorder); string line = myglassfile.ToBtString(); string str_pjlyl = Math.Round(pack.getNetUsage() * 100, 2).ToString(); int stocks_num = pack.stocks.Count; if (ProjectDB.UpdateProjectFirstInfo(p_no, str_pjlyl, stocks_num)) { openProject.state = 2; globel.ShowFromOKMessage(strSaveSuccess); } } //钢化模拟计算后的优化排版保存 void heatAnalogOptimizeSave(string p_no) { try { if (pack != null) { containerMsg.Visible = true; lblSaveInfo.Text = "工程: " + openProject.project_no + " 保存中,请稍等。。。"; containerMsg.Update(); setSimpleOrder(); if (pack.stocks.Count > 0) pack.stocks[0].glassType = cmbGlassType.Text.Trim();//设置原片膜系与使用膜系一致 MyGlasFile myglassfile = new MyGlasFile(pack, simpleorder); //string line = myglassfile.ToBtString();//调整前的结果 string line = myglassfile.toResultString();//调整后的结果,24.11.12 添加 int sType = useOffcut ? 0 : 1;//原片类型,0余料1原料 #region 保存方式1 //bool isSuccess = ProjectDB.SaveProjectOptimizeResult(p_no, pack, line, dicOpenPrcessLayer_, sType); //dk.Abort(); //if (isSuccess) //{ // openProject.state = 20; // //globel.ShowFromOKMessage("工程保存成功!"); // globel.SHowNewFromOkMessage("工程保存成功!",true); // //自动上传 // if (globel.AutoUploadOffcut) // { // OffcutDB.SyncOffcutToDB(p_no); // } //} //else //{ // //globel.ShowFromOKMessage("工程保存失败!"); // globel.SHowNewFromOkMessage("工程保存失败!", false); //} #endregion #region 保存方式2 OperationModel om = new OperationModel(); if (OptimaConfig.optimaSwitch) { om = ProjectDB.SaveOPTOptimizeResult(p_no, pack, line, dicOpenPrcessLayer_, sType); } else { om = ProjectDB.SaveOptimizeResult(p_no, pack, line, dicOpenPrcessLayer_, sType); } //dk.Abort(); if (om.state) { openProject.state = 20; containerMsg.Visible = false; globel.SHowNewFromOkMessage("保存成功!", true); //自动上传 if (globel.AutoUploadOffcut) { OffcutDB.SyncOffcutToDB(p_no); } } else { globel.SHowNewFromOkMessage("保存失败!\r\n位置:" + om.errCode + "\r\n描述:" + om.info, false); } #endregion } else { globel.ShowFromWarningMessage("没有优化内容"); return; } } catch (Exception ex) { globel.ShowFromWarningMessage("工程保存失败:\r\n" + ex.Message); #region 操作记录 PorjectLogDB.InsertProjectOperationLog(new PorjectLogModel() { project_no = txtProjectNo.Text.Trim(), operate_no = 9, operate_detail = ex.Message }); #endregion return; //throw; } } #endregion #region cmbGlassThick_TextChanged private void cmbGlassThick_TextChanged(object sender, EventArgs e) { if (pack != null) { for (int i = 0; i < pack.stocks.Count; i++) pack.stocks[i].Thickness = Convert.ToInt16(cmbGlassThick.Text); for (int i = 0; i < pack.mergedstocks.Count; i++) pack.mergedstocks[i].Thickness = Convert.ToInt16(cmbGlassThick.Text); } Setting.settingchaged = true; } #endregion #region 提取数字 /// /// 从字符串中提取所有数字 /// Returns:所有数字 /// /// 需要提取的字符串 /// 所有数字 public static string GetNumbers(string p_str) { string strReturn = string.Empty; if (p_str == null || p_str.Trim() == "") { strReturn = ""; } foreach (char chrTemp in p_str) { if (Char.IsNumber(chrTemp)) { strReturn += chrTemp.ToString(); } } return strReturn; } #endregion #region 设置小片磨量 和 大片修边 private void uBtnSetEdg_Click(object sender, EventArgs e) { DGVGlassDetailsRigthClickOperation(3); } private void TSMISetPolyMoliang_Click(object sender, EventArgs e) { DGVGlassDetailsRigthClickOperation(3); } private void uBtnSetTrim_Click(object sender, EventArgs e) { DGVStockRightClickOperation(1); } private void TSMISetStockXiuBian_Click(object sender, EventArgs e) { DGVStockRightClickOperation(1); } void SetMoLiangOrXiuBian(int type) { if (type == 1) { 设置磨量 setEdg = new 设置磨量(currentProcessList); setEdg.ShowDialog(); if (setEdg.DialogResult == DialogResult.OK) { int rowCount = polyView.AllowUserToAddRows ? polyView.Rows.Count - 1 : polyView.Rows.Count; for (int i = 0; i < rowCount; i++) { if (polyView.Rows[i].Cells["宽度"].Value == null || string.IsNullOrEmpty(polyView.Rows[i].Cells["宽度"].Value.ToString())) { continue; } if (currentEdge.auto_fill_edge && currentEdge.min_auto_lenght != 0) { if (Convert.ToDouble(polyView.Rows[i].Cells["宽度"].Value.ToString()) < currentEdge.min_auto_lenght) { continue; } if (Convert.ToDouble(polyView.Rows[i].Cells["高度"].Value.ToString()) < currentEdge.min_auto_lenght) { continue; } } if (setEdg.setEdgeByProcess == "全部" || setEdg.setEdgeByProcess == "All") { polyView.Rows[i].Cells["长磨1"].Value = currentEdge.down_edge; polyView.Rows[i].Cells["长磨2"].Value = currentEdge.up_edge; polyView.Rows[i].Cells["短磨1"].Value = currentEdge.right_edge; polyView.Rows[i].Cells["短磨2"].Value = currentEdge.left_edge; } else { if (polyView.Rows[i].Cells["流程卡号"].Value.ToString().Contains(setEdg.setEdgeByProcess)) { polyView.Rows[i].Cells["长磨1"].Value = currentEdge.down_edge; polyView.Rows[i].Cells["长磨2"].Value = currentEdge.up_edge; polyView.Rows[i].Cells["短磨1"].Value = currentEdge.right_edge; polyView.Rows[i].Cells["短磨2"].Value = currentEdge.left_edge; } } } } } else { 设置磨量 setTrim = new 设置磨量(type); setTrim.ShowDialog(); if (setTrim.DialogResult == DialogResult.OK) { int sRow = stockView.AllowUserToAddRows ? stockView.Rows.Count - 1 : stockView.Rows.Count; for (int i = 0; i < sRow; i++) { stockView.Rows[i].Cells["X1修边"].Value = currentTrimming.left_trim; stockView.Rows[i].Cells["X2修边"].Value = currentTrimming.right_trim; stockView.Rows[i].Cells["Y1修边"].Value = currentTrimming.down_trim; stockView.Rows[i].Cells["Y2修边"].Value = currentTrimming.up_trim; } } } } #endregion #region 按钮圆角、进出 /// /// 按钮事件加载 /// private void ButtonEventLoading() { labelUtil.setLabelName(ref lblBtnSearchStock); labelUtil.setLabelName(ref lblBtnSetMoLiang); labelUtil.setLabelName(ref lblBtnSetXiuBian); labelUtil.setLabelName(ref lblBtnOptima); labelUtil.setLabelName(ref lblBtnSave); labelUtil.setLabelName(ref lblQueryYuliao); if (Setting.language != 2) { lblBtnSearchStock.Paint += new PaintEventHandler(labelUtil.label_Paint); lblBtnSetMoLiang.Paint += new PaintEventHandler(labelUtil.label_Paint); lblBtnSetXiuBian.Paint += new PaintEventHandler(labelUtil.label_Paint); lblBtnOptima.Paint += new PaintEventHandler(labelUtil.label_Paint); lblQueryYuliao.Paint += new PaintEventHandler(labelUtil.label_Paint); lblBtnSave.Paint += new PaintEventHandler(labelUtil.label_Paint); } this.lblBtnSearchStock.MouseEnter += new System.EventHandler(labelUtil.lblBtn_MouseEnter); this.lblBtnSetMoLiang.MouseEnter += new System.EventHandler(labelUtil.lblBtn_MouseEnter); this.lblBtnSetXiuBian.MouseEnter += new System.EventHandler(labelUtil.lblBtn_MouseEnter); this.lblBtnOptima.MouseEnter += new System.EventHandler(labelUtil.lblBtn_MouseEnter); this.lblQueryYuliao.MouseEnter += new System.EventHandler(labelUtil.lblBtn_MouseEnter); this.lblBtnSave.MouseEnter += new System.EventHandler(labelUtil.lblBtn_MouseEnter); this.lblBtnSearchStock.MouseLeave += new System.EventHandler(labelUtil.lblBtn_MouseLeave); this.lblBtnSetMoLiang.MouseLeave += new System.EventHandler(labelUtil.lblBtn_MouseLeave); this.lblBtnSetXiuBian.MouseLeave += new System.EventHandler(labelUtil.lblBtn_MouseLeave); this.lblBtnOptima.MouseLeave += new System.EventHandler(labelUtil.lblBtn_MouseLeave); this.lblQueryYuliao.MouseLeave += new System.EventHandler(labelUtil.lblBtn_MouseLeave); this.lblBtnSave.MouseLeave += new System.EventHandler(labelUtil.lblBtn_MouseLeave); } #endregion #region 流程卡显示\隐藏 private void TSMIShowProcess_Click(object sender, EventArgs e) { DGVGlassDetailsRigthClickOperation(1); } private void TSMIHideProcess_Click(object sender, EventArgs e) { DGVGlassDetailsRigthClickOperation(2); } public void processShowOrHide(int hs) { if (hs == 1) { this.tlpMainChengPin.SetColumnSpan(this.polyView, 1); s.Visible = true; } else { s.Visible = false; this.tlpMainChengPin.SetColumnSpan(this.polyView, 2); } } #endregion #region 查询库存 private void uBtnSearchKuCun_Click(object sender, EventArgs e) { if (openProject.state == 20 && pack != null) { globel.ShowFromWarningMessage("当前结果已经保存,请新建工程后再次查询!"); return; } string gThick = cmbGlassThick.Text.Trim(); if (string.IsNullOrWhiteSpace(gThick)) { globel.ShowFromWarningMessage("请输入玻璃厚度!"); cmbGlassThick.Focus(); return; }; string gType = cmbGlassType.Text.Trim(); if (string.IsNullOrWhiteSpace(gType)) { globel.ShowFromWarningMessage("请输入玻璃类型!"); cmbGlassType.Focus(); return; }; projectnameText.Text = ""; Logger.Info($"查询了:{gThick}mm厚度{gType} 现补小片"); if (globel.UserGroup == "补片") { string filer = txtFilter.Text.Trim(); bool filterState = false; if (string.IsNullOrWhiteSpace(filer) || filer == filtertext) { filterState = showPatchPolysData(gThick, gType); } else { filterState = showPatchPolysData(gThick, gType, filer); } if (filterState) { ShowMaterialData(); } projectnameText.Text += $" {gThick}mm {gType}"; } } #endregion private void lblQueryYuliao_Click(object sender, EventArgs e) { //ShowSurplusMaterials(); showOffcutStock(); } /// /// 原片库存筛选 /// /// 玻璃类型 /// 玻璃厚度 //void ShowMaterialData(string glassType, string glassThickness) void ShowMaterialData() { string gThick = cmbGlassThick.Text.Trim(); if (string.IsNullOrWhiteSpace(gThick)) { globel.ShowFromWarningMessage("请输入玻璃厚度!"); cmbGlassThick.Focus(); return; }; string gType = cmbGlassType.Text.Trim(); if (string.IsNullOrWhiteSpace(gType)) { globel.ShowFromWarningMessage("请输入玻璃类型!"); cmbGlassType.Focus(); return; }; this.stockView.Rows.Clear(); //DataTable dt = MaterialDB.GetMaterialByColor(glassThickness, glassType); DataTable dt = MaterialDB.GetMaterialByColor(gThick, gType); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { int index = this.stockView.Rows.Add(); bool isKuan = Convert.ToDouble(dt.Rows[i]["width"].ToString()) >= Convert.ToDouble(dt.Rows[i]["height"].ToString()); this.stockView.Rows[index].Cells["优先"].Value = "1"; this.stockView.Rows[index].Cells["大片宽"].Value = isKuan ? dt.Rows[i]["width"].ToString() : dt.Rows[i]["height"].ToString(); this.stockView.Rows[index].Cells["大片高"].Value = isKuan ? dt.Rows[i]["height"].ToString() : dt.Rows[i]["width"].ToString(); this.stockView.Rows[index].Cells["类型"].Value = dt.Rows[i]["glassType"].ToString(); this.stockView.Rows[index].Cells["状态"].Value = "原片"; this.stockView.Rows[index].Cells["厚度"].Value = dt.Rows[i]["thickness"].ToString(); this.stockView.Rows[index].Cells["名称"].Value = dt.Rows[i]["name"].ToString(); this.stockView.Rows[index].Cells["库存量"].Value = dt.Rows[i]["available_quantity"]; this.stockView.Rows[index].Cells["库位"].Value = dt.Rows[i]["inventory_area"]; this.stockView.Rows[index].Cells["供应商"].Value = dt.Rows[i]["producer"].ToString(); this.stockView.Rows[index].Cells["物料代码"].Value = dt.Rows[i]["id"].ToString(); if (currentTrimming.auto_fill_trim) { stockView.Rows[i].Cells["X1修边"].Value = currentTrimming.left_trim; stockView.Rows[i].Cells["X2修边"].Value = currentTrimming.right_trim; stockView.Rows[i].Cells["Y1修边"].Value = currentTrimming.down_trim; stockView.Rows[i].Cells["Y2修边"].Value = currentTrimming.up_trim; } else { this.stockView.Rows[index].Cells["X1修边"].Value = "0"; this.stockView.Rows[index].Cells["Y1修边"].Value = "0"; this.stockView.Rows[index].Cells["X2修边"].Value = "0"; this.stockView.Rows[index].Cells["Y2修边"].Value = "0"; } } } useOffcut = false; if (OptimaConfig.optimaSwitch) { stockView.Columns["优先"].Visible = true; } else { stockView.Columns["优先"].Visible = false; } } /// /// 显示余料 /// void ShowSurplusMaterials() { string gThick = cmbGlassThick.Text.Trim(); if (string.IsNullOrWhiteSpace(gThick)) { globel.ShowFromWarningMessage("请输入玻璃厚度!"); cmbGlassThick.Focus(); return; }; string gType = cmbGlassType.Text.Trim(); if (string.IsNullOrWhiteSpace(gType)) { globel.ShowFromWarningMessage("请输入玻璃类型!"); cmbGlassType.Focus(); return; }; this.stockView.Rows.Clear(); DataTable dt = OffcutDB.QuerySurplusMaterials(gType, gThick); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { int index = this.stockView.Rows.Add(); bool isKuan = Convert.ToDouble(dt.Rows[i]["width"].ToString()) >= Convert.ToDouble(dt.Rows[i]["height"].ToString()); this.stockView.Rows[index].Cells["优先"].Value = "1"; this.stockView.Rows[index].Cells["大片宽"].Value = isKuan ? dt.Rows[i]["width"].ToString() : dt.Rows[i]["height"].ToString(); this.stockView.Rows[index].Cells["大片高"].Value = isKuan ? dt.Rows[i]["height"].ToString() : dt.Rows[i]["width"].ToString(); this.stockView.Rows[index].Cells["类型"].Value = dt.Rows[i]["colour"].ToString(); this.stockView.Rows[index].Cells["厚度"].Value = dt.Rows[i]["thickness"].ToString(); this.stockView.Rows[index].Cells["库存量"].Value = dt.Rows[i]["quantity"]; this.stockView.Rows[index].Cells["库位"].Value = "余料"; this.stockView.Rows[index].Cells["供应商"].Value = "余料"; this.stockView.Rows[index].Cells["物料代码"].Value = dt.Rows[i]["id"].ToString(); this.stockView.Rows[index].Cells["X1修边"].Value = "0"; this.stockView.Rows[index].Cells["Y1修边"].Value = "0"; this.stockView.Rows[index].Cells["X2修边"].Value = "0"; this.stockView.Rows[index].Cells["Y2修边"].Value = "0"; } } useOffcut = true; } void showOffcutStock() { string gThick = cmbGlassThick.Text.Trim(); if (string.IsNullOrWhiteSpace(gThick)) { globel.ShowFromWarningMessage("请输入玻璃厚度!"); cmbGlassThick.Focus(); return; }; string gType = cmbGlassType.Text.Trim(); if (string.IsNullOrWhiteSpace(gType)) { globel.ShowFromWarningMessage("请输入玻璃类型!"); cmbGlassType.Focus(); return; }; this.stockView.Rows.Clear(); DataTable dt = OffcutDB.GetOffcuStock(gType, gThick); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { int index = this.stockView.Rows.Add(); bool isKuan = Convert.ToDouble(dt.Rows[i]["宽"].ToString()) >= Convert.ToDouble(dt.Rows[i]["高"].ToString()); this.stockView.Rows[index].Cells["优先"].Value = "1"; this.stockView.Rows[index].Cells["大片宽"].Value = isKuan ? dt.Rows[i]["宽"].ToString() : dt.Rows[i]["高"].ToString(); this.stockView.Rows[index].Cells["大片高"].Value = isKuan ? dt.Rows[i]["高"].ToString() : dt.Rows[i]["宽"].ToString(); this.stockView.Rows[index].Cells["类型"].Value = dt.Rows[i]["膜系"].ToString(); this.stockView.Rows[index].Cells["状态"].Value = "余料"; this.stockView.Rows[index].Cells["厚度"].Value = dt.Rows[i]["厚度"].ToString(); this.stockView.Rows[index].Cells["库存量"].Value = dt.Rows[i]["数量"]; this.stockView.Rows[index].Cells["库位"].Value = "余料"; this.stockView.Rows[index].Cells["供应商"].Value = "余料"; this.stockView.Rows[index].Cells["物料代码"].Value = dt.Rows[i]["id"].ToString(); this.stockView.Rows[index].Cells["X1修边"].Value = currentTrimming.left_trim; this.stockView.Rows[index].Cells["Y1修边"].Value = currentTrimming.down_trim; this.stockView.Rows[index].Cells["X2修边"].Value = currentTrimming.right_trim; this.stockView.Rows[index].Cells["Y2修边"].Value = currentTrimming.up_trim; } } useOffcut = true; } #region polyView 加行号 private void polyView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { GridViews.DGVAddRowIndex(polyView, e); } #endregion #region 退出程序 private void 任务_FormClosing_1(object sender, FormClosingEventArgs e) { directPacking.Setting.UpdateSetting(); // saveCommonSize(); string strClose = ""; switch (Setting.language) { case 1: strClose = "Are you sure to exit the program?"; break; case 2: strClose = "Уверены ли вы в выходе из реестра?"; break; default: strClose = "是否确认退出玻璃优化软件?"; break; } if (globel.ShowFromConfirmMessage(strClose)) { LoginAdminInfo.last_logout_time = DateTime.Now;//.ToString("yyyy-MM-dd HH:mm:ss"); AdminDB.UpdateAdminInfo(); Logger.Info("退出了程序\r\n\r\n\r\n"); System.Environment.Exit(0); } else { e.Cancel = true; } } #endregion #region #region 0引用 private void button2_Click(object sender, EventArgs e)//保存录入数据 { if (!Directory.Exists(directPacking.Setting.btdir + "\\data")) Directory.CreateDirectory(directPacking.Setting.btdir + "\\data"); DirectoryInfo dir = new DirectoryInfo(directPacking.Setting.btdir); string path = Setting.btdir + "\\data\\" + projectnameText.Text.Trim() + txtProjectNo.Text.Trim() + ".txt"; StreamWriter sw = new StreamWriter(path, false, Encoding.Unicode); for (int i = 0; i < polyView.Rows.Count; i++) { if (polyView.Rows[i].Cells["宽度"].Value != null) { string line = polyView.Rows[i].Cells["编号"].Value.ToString(); //0 line = line + " @ " + polyView.Rows[i].Cells["宽度"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["高度"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["数量"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["模板号"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["长磨1"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["短磨1"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["长磨2"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["短磨2"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["加工信息"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["客户名称"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["订单编号"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["产品名称"].Value.ToString();//12 line = line + " @ " + polyView.Rows[i].Cells["单价"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["备注"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["楼层编号"].Value.ToString(); line = line + " @ " + polyView.Rows[i].Cells["架号"].Value.ToString(); sw.WriteLine(line); } } sw.Close(); globel.ShowFromOKMessage("保存成功,保存位置" + path, false); } private void ordernameText_TextChanged(object sender, EventArgs e) { Setting.settingchaged = true; } private void companyinfo_MouseLeave(object sender, EventArgs e) { ((Control)sender).ForeColor = Color.Black; } private void companyinfo_MouseLeave2(object sender, EventArgs e) { ((Control)sender).ForeColor = Color.Brown; } private void companyinfo_MouseEnter(object sender, EventArgs e) { ((Control)sender).ForeColor = Color.White; } private void 手工优化_Click(object sender, EventArgs e) { 人工排版 rengong = new 人工排版(this); rengong.ShowDialog(); } private void mainTab_DrawItem(object sender, DrawItemEventArgs e) { List names = new List(); names.Add("录入成品"); names.Add("优化版面"); names.Add("手工排版"); names.Add("设备驱动"); names.Add("优化报告"); names.Add("打印标签"); names.Add("手工切割"); e.DrawBackground(); e.Graphics.DrawString(names[e.Index], new Font("宋体", 9), new SolidBrush(Color.CadetBlue), e.Bounds.X, 5); } public void addRowfromPingjing(string innfo) { polyView.Rows.Add(DisplayPack.PolyNewRowBittengCSV(polyView, "0`" + innfo.Replace(",", "`").Replace("enter", "\r\n"))); } private void glassTypeText_Enter(object sender, EventArgs e) { ((System.Windows.Forms.TextBox)sender).ForeColor = System.Drawing.Color.Black; } private void selectAllRemain(bool value) { for (int i = 0; i < stockView.Rows.Count - 1; i++) { if (stockView.Rows[i].Cells["余料"].Value != null || Boolean.Parse(stockView.Rows[i].Cells["余料"].Value.ToString()) == true) { stockView.Rows[i].Cells[0].Value = value; } } } private void 手工切割_Click(object sender, EventArgs e) { 手工排版.Form1 form = new 手工排版.Form1(); form.Show(); } #region 常用规格记忆 public void readCommonSize()//读取原片常用规格 { //try { stockView.Rows.Clear(); FileStream fs = new FileStream(System.Windows.Forms.Application.StartupPath + "\\data\\常用规格.txt", FileMode.OpenOrCreate); StreamReader reader = new StreamReader(fs); string s; while ((s = reader.ReadLine()) != null) { loadCommonSize(stockView, s); } fs.Close(); reader.Close(); } //catch { // return; } } public void readRemainSize() { try { if (Setting.danji) { FileStream fs = new FileStream(System.Windows.Forms.Application.StartupPath + "\\data\\余料.txt", FileMode.OpenOrCreate); StreamReader reader = new StreamReader(fs); string s; while ((s = reader.ReadLine()) != null) { loadRemainSize(stockView, s); } fs.Close(); reader.Close(); } //else //{ // DataTable table = saleclient.getTable("select * from 余料 where jiagongchang='" + Setting.companyname + "'", "myglasserpgetTable"); // string s; // foreach (DataRow row in table.Rows) // { // s = row["width"].ToString() + "*" + row["height"].ToString() + "*1*" + row["intodate"].ToString() + "*" + // row["glasstype"].ToString() + "*" + row["thick"].ToString() + "*" + row["position"].ToString(); // loadRemainSize(stockView, s); // } //} // 选中所有的余料 //for (int i = 0; i < stockView.Rows.Count - 1; i++) // if ((Boolean)stockView.Rows[i].Cells["余料"].Value == true) // { // stockView.Rows[i].Cells[0].Value = true; // } } catch { return; } } private void loadCommonSize(DataGridView view, string str) { DataGridViewRow row = (DataGridViewRow)view.Rows[0].Clone(); string[] strs = str.Split('*'); row.Cells[0].Value = false; try { row.Cells["大片宽"].Value = strs[0];//大片宽 row.Cells["大片高"].Value = strs[1];//大片高 row.Cells["类型"].Value = strs[2];//类型 row.Cells["厚度"].Value = strs[3];//厚度 row.Cells["X1修边"].Value = strs[4];//X1修边 row.Cells["Y1修边"].Value = strs[5];//Y1修边 row.Cells["X2修边"].Value = strs[6];//X2修边 row.Cells["Y2修边"].Value = strs[7];//Y2修边 row.Cells["库存量"].Value = strs[8];//数量 row.Cells["用量"].Value = strs[9];//数量 row.Cells["库位"].Value = strs[10];//数量 row.Cells["膜系"].Value = strs[11];//数量 row.Cells["供应商"].Value = strs[12];//数量 row.Cells["余料"].Value = strs[13];//数量 row.Cells["物料代码"].Value = strs[14];//数量 } catch (Exception ee) { } // row.Cells[8].Value = false; changeRowColor(row, System.Drawing.Color.WhiteSmoke); view.Rows.Add(row); } private void loadRemainSize(DataGridView view, string str) { DataGridViewRow row = (DataGridViewRow)view.Rows[0].Clone(); string[] strs = str.Split('*'); row.Cells[1].Value = strs[0]; row.Cells[2].Value = strs[1]; row.Cells[0].Value = false; row.Cells[5].Value = "0"; row.Cells[6].Value = "0"; row.Cells[7].Value = "0"; row.Cells[8].Value = "0"; row.Cells[9].Value = strs[2]; if (strs.Length == 4) { row.Cells[3].Value = Sentences.whiteglass; row.Cells[4].Value = 5; } else { //if (!((DataGridViewComboBoxColumn)(stockView.Columns["类型"])).Items.Contains(strs[4])) //{ // ((DataGridViewComboBoxColumn)(stockView.Columns["类型"])).Items.Add(strs[4]); // ((DataGridViewComboBoxCell)(row.Cells[3])).Items.Add(strs[4]); //} row.Cells[3].Value = strs[4]; row.Cells[4].Value = strs[5]; } row.Cells[10].Value = true; row.Cells[10].ReadOnly = true; row.Cells[12].Value = strs.Length > 6 ? strs[6] : ""; changeRowColor(row, System.Drawing.Color.LightGreen); view.Rows.Add(row); } public void changeRowColor(DataGridViewRow row, System.Drawing.Color color) { for (int i = 0; i < row.Cells.Count; i++) { row.Cells[i].Style.BackColor = color; } } private bool checkdata() { stockView.EndEdit(); bool result = true; foreach (DataGridViewRow row in stockView.Rows) { if (row.Index != stockView.Rows.Count - 1) { try { double.Parse(row.Cells["大片宽"].Value.ToString()); double.Parse(row.Cells["大片高"].Value.ToString()); } catch { globel.ShowFromWarningMessage(Sentences.cuowushujuzai + (row.Index + 1).ToString(), false, Sentences.tishi); return false; } try { Int32.Parse(row.Cells["库存量"].Value.ToString()); } catch { row.Cells["库存量"].Value = "100000"; } try { Int32.Parse(row.Cells["类型"].Value.ToString()); } catch { row.Cells["类型"].Value = "白玻"; } try { Int32.Parse(row.Cells["厚度"].Value.ToString()); } catch { row.Cells["厚度"].Value = "5"; } try { Int32.Parse(row.Cells["X1修边"].Value.ToString()); } catch { row.Cells["X1修边"].Value = "0"; } try { Int32.Parse(row.Cells["X2修边"].Value.ToString()); } catch { row.Cells["X2修边"].Value = "0"; } try { Int32.Parse(row.Cells["Y1修边"].Value.ToString()); } catch { row.Cells["Y1修边"].Value = "0"; } try { Int32.Parse(row.Cells["Y2修边"].Value.ToString()); } catch { row.Cells["Y2修边"].Value = "0"; } } } return result; } #endregion #endregion #region 清空信息 private void TSMIClearShowInfo_Click(object sender, EventArgs e) { Setting.settingchaged = true; Setting.justOpened = null; if (任务.pack == null) { if (polyView.Rows.Count > 1) { if (globel.ShowFromConfirmMessage(strClearInfoConfirm)) { ClearShowInfo(); } } } else { //当前工程未保存 if (pack != null && !hasSaved) { if (globel.ShowFromConfirmMessage(strClearInfoConfirm)) { pack = null; ClearShowInfo(); if (reportform != null) reportform.pack = null; if (banmian != null) { banmian.pack = null; banmian.pictureBox1.Image = null; } if (qudong != null) { qudong.pack = null; qudong.pictureBoxDXF.Image = null; } if (rengong != null) { rengong.bbox.Image = null; rengong.orderTree.Nodes.Clear(); } } } //当前工程已保存或者没有当前工程也没有录入成品 else if (pack != null && hasSaved || pack == null && polyView.Rows.Count == 1) { pack = null; ClearShowInfo(); } //没有工程但是已经录入成品 else if (pack == null && polyView.Rows.Count > 1) { if (globel.ShowFromConfirmMessage(strClearInfoConfirm)) { ClearShowInfo(); } } } } private void ClearShowInfo()//新建工程 { polyView.Rows.Clear(); polyView.ReadOnly = false; polyView.AllowUserToAddRows = true; mainTab.SelectedIndex = 0; this.Text = "北玻自动化玻璃优化系统"; norenwudan(); ids = null; Setting.renwudantable = null; Setting.glasstype = ""; Setting.thick = ""; txtProjectNo.Text = ""; cmbGlassThick.Text = ""; cmbGlassType.Text = ""; stockView.Rows.Clear(); YPMJ.Text = "0"; YPSL.Text = "0"; } #endregion private void TSMIUseYuanPian_Click(object sender, EventArgs e) { 原片用量 yu = new 原片用量(); yu.ShowDialog(); } #endregion #region 是否继续 public bool IsContinue(string msg = "当前工程因 原片不足 未全部优化,是否继续执行当前操作?") { if (pack.yuanpianbuzu) { if (globel.ShowFromConfirmMessage(msg)) { return true; } return false; } return true; } #endregion private void TSMIYPSelected_Click(object sender, EventArgs e) { DGVStockRightClickOperation(2);//选择原片 } //2023.10.31 新增 private void TSMIPolySetShape_Click(object sender, EventArgs e) { if (polyView.CurrentRow == null) { return; } if (polyView.Rows[currentPolyRow].Cells["模板号"].Value == null) { return; } float w = Convert.ToInt64(polyView.Rows[currentPolyRow].Cells["宽度"].Value); float h = Convert.ToInt64(polyView.Rows[currentPolyRow].Cells["高度"].Value); updateyixing_Click(polyView.CurrentRow.Index, w, h); return; } private void tsmiProjectMangage_Click(object sender, EventArgs e) { 工程管理 pm = new 工程管理(this); pm.ShowDialog(); } private void 工程创建ToolStripMenuItem_Click(object sender, EventArgs e) { 工程创建 pc = new 工程创建(this); pc.ShowDialog(); } /*钢化计算*/ private void TSMIHeatCount_Click(object sender, EventArgs e) { //模拟计算 hs = new 模拟计算(this); //hs.ShowDialog(); } #region 第一次优化显示小片 public bool ShowProjectGlassDetails(string pNo) { polyView.Rows.Clear(); OpenProjectInfo(pNo); bool autofill = currentEdge.auto_fill_edge; //DataTable dt = FlowCardDB.GetGlassDataByProject(pNo); DataTable dt = FlowCardDB.GetGlassDataByProject2(pNo); if (dt != null) { foreach (DataRow dr in dt.Rows) { //用于优化的小片数据展示 int index = this.polyView.Rows.Add(); object width = this.polyView.Rows[index].Cells["宽度"].Value = dr["width"]; object height = this.polyView.Rows[index].Cells["高度"].Value = dr["height"]; this.polyView.Rows[index].Cells["数量"].Value = dr["quantity"]; this.polyView.Rows[index].Cells["模板号"].Value = 100; //是否填充 bool filling = Math.Min(Convert.ToInt64(width), Convert.ToInt64(height)) < currentEdge.min_auto_lenght; this.polyView.Rows[index].Cells["长磨1"].Value = autofill ? filling ? "0" : currentEdge.down_edge.ToString() : "0"; this.polyView.Rows[index].Cells["短磨1"].Value = autofill ? filling ? "0" : currentEdge.left_edge.ToString() : "0"; this.polyView.Rows[index].Cells["长磨2"].Value = autofill ? filling ? "0" : currentEdge.up_edge.ToString() : "0"; this.polyView.Rows[index].Cells["短磨2"].Value = autofill ? filling ? "0" : currentEdge.right_edge.ToString() : "0"; this.polyView.Rows[index].Cells["流程卡号"].Value = dr["process_id"]; this.polyView.Rows[index].Cells["架号"].Value = "A01"; this.polyView.Rows[index].Cells["序号"].Value = dr["order_number"].ToString(); this.polyView.Rows[index].Cells["编号"].Value = dr["order_number"].ToString(); polyView.Rows[index].Cells["面积"].Value = dr["area"]; polyView.Rows[index].Cells["单价"].Value = dr["price"]; polyView.Rows[index].Cells["单片名称"].Value = dr["glass_child"]; polyView.Rows[index].Cells["产品名称"].Value = dr["product_name"]; polyView.Rows[index].Cells["楼层编号"].Value = dr["building_number"]; polyView.Rows[index].Cells["印标类型"].Value = dr["icon"]; polyView.Rows[index].Cells["备注"].Value = dr["remarks"]; polyView.Rows[index].Cells["玻璃层"].Value = dr["technology_number"]; //自动计算面积 double w, h; int c; if (polyView.Rows[index].Cells["宽度"].Value != null && double.TryParse(polyView.Rows[index].Cells["宽度"].Value.ToString(), out w) && polyView.Rows[index].Cells["高度"].Value != null && double.TryParse(polyView.Rows[index].Cells["高度"].Value.ToString(), out h) && polyView.Rows[index].Cells["数量"].Value != null && int.TryParse(polyView.Rows[index].Cells["数量"].Value.ToString(), out c)) { polyView.Rows[index].Cells["周长"].Value = Functions.decimalconvert((2 * w + 2 * h) * c * Math.Pow(10, -3)); } newRectRow(index, 100); } CountPolyNumberOrArea(); } ShowMaterialData(); return true; } #endregion #region 钢化计算后的工程,显示小片 /// /// 显示钢化计算后工程玻璃详情 /// /// 工程号 /// 是否筛选原片 /// public bool ShowHeatProjectGlassDetails(string pNo, bool isShowMaterial = true) { polyView.Rows.Clear(); OpenProjectInfo(pNo); bool autofill = currentEdge.auto_fill_edge;//是否自动填充 EdgeModel edgeModel = currentEdge; if (!string.IsNullOrEmpty(projectEdge)) { edgeModel = JsonConvert.DeserializeObject(projectEdge); } DataTable dt = FlowCardDB.GlassDataByProjectHeat(pNo); if (dt != null) { polyView.AllowUserToAddRows = true; string err_Msg = ""; try { //玻璃钢化数据 ProjectDB.GlassHeatSortDataByProject(pNo); //暂停布局更新: polyView.SuspendLayout(); foreach (DataRow dr in dt.Rows) { //用于优化的小片数据展示 int index = this.polyView.Rows.Add(); err_Msg = "小片宽高可能存在异常,宽" + dr["width"] + ";高:" + dr["height"]; object width = this.polyView.Rows[index].Cells["宽度"].Value = dr["width"]; object height = this.polyView.Rows[index].Cells["高度"].Value = dr["height"]; if (string.IsNullOrEmpty(width.ToString()) || string.IsNullOrEmpty(height.ToString())) { globel.ShowFromWarningMessage("成品尺寸异常,请检查!"); return false; } this.polyView.Rows[index].Cells["数量"].Value = dr["quantity"]; this.polyView.Rows[index].Cells["模板号"].Value = 100; err_Msg = "小片磨量设置可能存在异常"; //是否填充 bool filling = Math.Min(Convert.ToInt64(width), Convert.ToInt64(height)) < currentEdge.min_auto_lenght; if (string.IsNullOrEmpty(projectEdge)) { this.polyView.Rows[index].Cells["长磨1"].Value = autofill ? filling ? "0" : currentEdge.down_edge.ToString() : "0"; this.polyView.Rows[index].Cells["短磨1"].Value = autofill ? filling ? "0" : currentEdge.left_edge.ToString() : "0"; this.polyView.Rows[index].Cells["长磨2"].Value = autofill ? filling ? "0" : currentEdge.up_edge.ToString() : "0"; this.polyView.Rows[index].Cells["短磨2"].Value = autofill ? filling ? "0" : currentEdge.right_edge.ToString() : "0"; } else { this.polyView.Rows[index].Cells["长磨1"].Value = edgeModel.down_edge.ToString(); this.polyView.Rows[index].Cells["短磨1"].Value = edgeModel.left_edge.ToString(); this.polyView.Rows[index].Cells["长磨2"].Value = edgeModel.up_edge.ToString(); this.polyView.Rows[index].Cells["短磨2"].Value = edgeModel.right_edge.ToString(); } err_Msg = "小片流程卡信息可能存在异常"; this.polyView.Rows[index].Cells["流程卡号"].Value = dr["process_id"]; this.polyView.Rows[index].Cells["架号"].Value = dr["layout_id"]; this.polyView.Rows[index].Cells["序号"].Value = dr["order_number"].ToString(); this.polyView.Rows[index].Cells["编号"].Value = dr["order_number"].ToString(); err_Msg = "小片成品信息可能存在异常"; polyView.Rows[index].Cells["面积"].Value = dr["area"]; polyView.Rows[index].Cells["单价"].Value = dr["price"]; polyView.Rows[index].Cells["单片名称"].Value = dr["glass_child"]; polyView.Rows[index].Cells["产品名称"].Value = dr["product_name"]; polyView.Rows[index].Cells["楼层编号"].Value = dr["building_number"] != null ? dr["building_number"].ToString().Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ") : dr["building_number"]; polyView.Rows[index].Cells["印标类型"].Value = dr["icon"]; polyView.Rows[index].Cells["备注"].Value = dr["remarks"]; polyView.Rows[index].Cells["玻璃层"].Value = dr["layer"]; //自动计算面积 double w, h; int c; if (polyView.Rows[index].Cells["宽度"].Value != null && double.TryParse(polyView.Rows[index].Cells["宽度"].Value.ToString(), out w) && polyView.Rows[index].Cells["高度"].Value != null && double.TryParse(polyView.Rows[index].Cells["高度"].Value.ToString(), out h) && polyView.Rows[index].Cells["数量"].Value != null && int.TryParse(polyView.Rows[index].Cells["数量"].Value.ToString(), out c)) { polyView.Rows[index].Cells["周长"].Value = Functions.decimalconvert((2 * w + 2 * h) * c * Math.Pow(10, -3)); } newRectRow(index, 100); } //恢复布局更新: polyView.ResumeLayout(); } catch (Exception ex) { globel.ShowFromErrorMessage(err_Msg + "\r\n" + ex.Message); return false; } CountPolyNumberOrArea(); polyView.AllowUserToAddRows = false; } if (isShowMaterial) { ShowMaterialData(); } return true; } #endregion /// /// 当前工程的磨量信息 /// string projectEdge = ""; /// /// 打开的工程信息 /// /// void OpenProjectInfo(string pNo) { DataTable pInfo = ProjectDB.QueryProject(pNo); ManualMode = false; if (pInfo != null) { openProject = new ProjectModel { project_no = pNo, name = pInfo.Rows[0]["project_name"].ToString(), glass_thickness = pInfo.Rows[0]["glass_thickness"].ToString(), glass_type = pInfo.Rows[0]["glass_type"].ToString(), state = Convert.ToInt32(pInfo.Rows[0]["state"].ToString()), guidance = pInfo.Rows[0]["guidance"] == DBNull.Value ? 1 : Convert.ToInt32(pInfo.Rows[0]["guidance"].ToString()), }; projectEdge = pInfo.Rows[0]["edge_config"].ToString(); cmbGlassThick.Text = openProject.glass_thickness.Trim('m'); cmbGlassType.Text = openProject.glass_type; projectnameText.Text = openProject.name; txtProjectNo.Text = pNo; currentOperateProject = pNo; if (openProject.state >= 20) { cmbGlassThick.Enabled = false; cmbGlassType.Enabled = false; } else { cmbGlassThick.Enabled = true; cmbGlassType.Enabled = true; pack = null; } } stockViewStateSet(); OpenProjectProcessInfo(pNo); OpenProcessLayer(pNo); } /// /// 原片列表设置:第一次优化允许添加修改原片,模拟计算后优化不允许 /// void stockViewStateSet() { return; //现补版本不做当前限制 if (openProject.state < 10) { //tsmiAddStock.Visible = true; //stockView.ReadOnly = false; foreach (DataGridViewColumn dgvc in stockView.Columns) { dgvc.ReadOnly = false; } //for (int i = 1; i < stockView.Columns.Count; i++) //{ // if (i < 6) // { // stockView.Columns[i].ReadOnly = true; // } //} } else { //tsmiAddStock.Visible = false; for (int i = 1; i < stockView.Columns.Count; i++) { if (i < 6) { stockView.Columns[i].ReadOnly = true; } } } } /// /// 打开的工程流程卡信息 /// /// void OpenProjectProcessInfo(string pNo) { try { //TODO 流程卡的概括信息 DataTable pInfo = FlowCardDB.GetProcessOverviewDataByProject(pNo); if (pInfo == null || pInfo.Rows.Count <= 0) { return; } s.DataSource = null; s.DataSource = pInfo.DefaultView; s.Columns["标"].Visible = false; s.Columns["流程卡"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; s.Columns["项目名"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; s.Columns["尺寸"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dicOpentProcessMarkInfo_.Clear(); currentProcessList.Clear(); foreach (DataRow dr in pInfo.Rows) { //string processNo = dr["process_id"].ToString(); string processNo = dr["流程卡"].ToString(); if (!dicOpentProcessMarkInfo_.ContainsKey(processNo)) { //string mIcon = dr["icon"].ToString(); string mIcon = dr["标"].ToString(); MarkModel mm = JsonConvert.DeserializeObject(mIcon); dicOpentProcessMarkInfo_.Add(processNo, mm != null ? mm.trademark : ""); } if (!currentProcessList.Contains(processNo)) { currentProcessList.Add(processNo); } } countProcessInfo(); } catch (Exception ex) { globel.ShowErrorMessage("OpenProjectProcessInfo:\r\n" + ex.Message); //throw; } } /// /// 打开的流程卡层数 /// /// void OpenProcessLayer(string projectNo) { //GetProcessSimpleDataByProject DataTable pInfo = FlowCardDB.GetProcessSimpleDataByProject(projectNo); if (pInfo == null || pInfo.Rows.Count <= 0) { return; } dicOpenPrcessLayer_.Clear(); foreach (DataRow dr in pInfo.Rows) { string processNo = dr["process_id"].ToString(); //string processLayer = dr["layer"].ToString(); //string pLayer = processNo + "-" + processLayer; int pLayersNumber = (int)dr["layers_number"]; if (!dicOpenPrcessLayer_.ContainsKey(processNo)) { dicOpenPrcessLayer_.Add(processNo, pLayersNumber); } } } /// /// 记录当前打开工程的流程卡打标信息 /// public static Dictionary dicOpentProcessMarkInfo_ = new Dictionary(); /// /// 用于记录打开的流程卡有几层 /// public static Dictionary dicOpenPrcessLayer_ = new Dictionary(); /// /// 打开优化后的工程 /// /// /// public bool OpenOptimizeProject(string p_no) { string p_content = ProjectDB.QueryProjectOptimizeResult(p_no); if (string.IsNullOrEmpty(p_content)) { globel.ShowFromWarningMessage(strProjectNoResult); return false; } MyGlasFile myglassfile = new MyGlasFile(); myglassfile.ReadFileContent(p_content); if (myglassfile.MGFile.Count == 0) { globel.ShowFromWarningMessage(Setting.language == 0 ? "读取文件出错" : "File Error!", false); return false; } OpenProjectInfo(p_no); //显示钢化模拟计算数据 //ShowHeatProjectGlassDetails(p_no, false); //setSimpleOrder(); OnePacking openpack = ReadFile.LoadPackInfo(p_no, myglassfile); if (openpack != null) { //显示小片信息 Order simpleorder = new Order(); myglassfile.wangmeiLoadOriginalInfo(this, ref simpleorder, p_content); pack = openpack; pagenumber = 0; drawPack(); Setting.justOpened = openpack.getcopy(); ShowOptimizeProjectStock(p_no); #region 读取OPT文件内容,OPTIMA优化使用 //string projectOPTFile = ProjectDB.QueryProjectOPTFile(p_no); //if (projectOPTFile != null) //{ // System.IO.StringReader streamreader = new StringReader(projectOPTFile); // listChangeOPTContent.Clear(); // string line = ""; // while ((line = streamreader.ReadLine()) != null) // { // listChangeOPTContent.Add(line); // } // streamreader.Close(); //} #endregion return true; } return false; } /// /// 展示工程优化后使用的原片信息 /// /// /// public bool ShowOptimizeProjectStock(string p_no) { dicReportProjectUseStock.Clear(); DataTable dt = MaterialDB.QueryMaterialUseByProjectNo(p_no); if (dt != null) { this.stockView.Rows.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { int index = this.stockView.Rows.Add(); this.stockView.Rows[index].Cells["大片宽"].Value = dt.Rows[i]["width"].ToString(); this.stockView.Rows[index].Cells["大片高"].Value = dt.Rows[i]["height"].ToString(); this.stockView.Rows[index].Cells["状态"].Value = dt.Rows[i]["type"].ToString() == "1" ? "原片" : "余料"; this.stockView.Rows[index].Cells["类型"].Value = openProject.glass_type; this.stockView.Rows[index].Cells["厚度"].Value = openProject.glass_thickness; this.stockView.Rows[index].Cells["库存量"].Value = 0; this.stockView.Rows[index].Cells["用量"].Value = dt.Rows[i]["use_count"].ToString(); this.stockView.Rows[index].Cells["物料代码"].Value = dt.Rows[i]["raw_stock_code"].ToString(); stockView.Rows[i].Cells["X1修边"].Value = dt.Rows[i]["left_trim"].ToString(); stockView.Rows[i].Cells["X2修边"].Value = dt.Rows[i]["right_trim"].ToString(); stockView.Rows[i].Cells["Y1修边"].Value = dt.Rows[i]["down_trim"].ToString(); stockView.Rows[i].Cells["Y2修边"].Value = dt.Rows[i]["up_trim"].ToString(); string keys = Convert.ToSingle(dt.Rows[i]["width"].ToString()) + "x" + Convert.ToSingle(dt.Rows[i]["height"].ToString()); if (!dicReportProjectUseStock.ContainsKey(keys)) { dicReportProjectUseStock.Add(keys, dt.Rows[i]["raw_stock_code"].ToString()); } } return true; } return false; } /// /// 小片列表右键操作 /// /// 操作类型 private void DGVGlassDetailsRigthClickOperation(int oType) { switch (oType) { case 1://显示流程卡 this.tlpMainChengPin.SetColumnSpan(this.polyView, 1); s.Visible = true; break; case 2://不显示流程卡 s.Visible = false; this.tlpMainChengPin.SetColumnSpan(this.polyView, 2); break; case 3://设置磨边 SetMoLiangOrXiuBian(1); break; case 4://数据导出 string fileName = txtProjectNo.Text + "-成品列表"; string filePath = DataGrieViewReport.StreamReportByDGV(polyView, fileName); if (string.IsNullOrEmpty(filePath)) { return; } if (globel.ShowFromConfirmMessage("导出成功,路径:" + filePath + "\r\n是否打开?")) { fileUtil.SysOpenFile(filePath); } break; default: break; } } /// /// 原片列表右键操作 /// /// 操作类型 private void DGVStockRightClickOperation(int oType) { switch (oType) { case 1://设置统一修边 SetMoLiangOrXiuBian(2); break; case 2://选择 foreach (DataGridViewRow dr in stockView.Rows) { dr.Cells[0].Value = dr.Selected ? true : dr.Cells[0].Value; } foreach (DataGridViewCell cell in stockView.SelectedCells) { stockView.Rows[cell.RowIndex].Cells[0].Value = true; } break; case 3: string fileName = txtProjectNo.Text + "-原片用量"; string filePath = DataGrieViewReport.StreamReportByDGV(polyView, fileName); if (string.IsNullOrEmpty(filePath)) { return; } if (globel.ShowFromConfirmMessage("导出成功,路径:" + filePath + "\r\n是否打开?")) { fileUtil.SysOpenFile(filePath); } break; case 4://添加物料 Random rd = new Random(); int index = this.stockView.Rows.Add(); this.stockView.Rows[index].Cells["大片宽"].Value = null; this.stockView.Rows[index].Cells["大片高"].Value = null; this.stockView.Rows[index].Cells["大片宽"].ReadOnly = false; this.stockView.Rows[index].Cells["大片高"].ReadOnly = false; this.stockView.Rows[index].Cells["优先"].Value = "1"; this.stockView.Rows[index].Cells["类型"].Value = cmbGlassType.Text.Trim(); this.stockView.Rows[index].Cells["状态"].Value = "余料"; this.stockView.Rows[index].Cells["厚度"].Value = cmbGlassThick.Text.Trim(); this.stockView.Rows[index].Cells["库存量"].Value = 999; this.stockView.Rows[index].Cells["物料代码"].Value = rd.Next(100000, 200000); if (currentTrimming.auto_fill_trim) { stockView.Rows[index].Cells["X1修边"].Value = currentTrimming.left_trim; stockView.Rows[index].Cells["X2修边"].Value = currentTrimming.right_trim; stockView.Rows[index].Cells["Y1修边"].Value = currentTrimming.down_trim; stockView.Rows[index].Cells["Y2修边"].Value = currentTrimming.up_trim; } else { this.stockView.Rows[index].Cells["X1修边"].Value = "0"; this.stockView.Rows[index].Cells["Y1修边"].Value = "0"; this.stockView.Rows[index].Cells["X2修边"].Value = "0"; this.stockView.Rows[index].Cells["Y2修边"].Value = "0"; } //stockView.AllowUserToAddRows = true; break; default: break; } } #region 打印 /// /// 合并打印 /// void PrintMerge() { } /// /// 打印版图 /// void PrintLayout() { } /// /// 打印报告 /// void PrintReport() { } void TSMIPrint(int tsmiType) { switch (tsmiType) { case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: break; case 9: break; default: break; } } #endregion private void tsmiMaterialRequisitionForm_Click(object sender, EventArgs e) { reportform.打印领料单(); mainTab.SelectedIndex = 6; } private void tsmiExport_Click(object sender, EventArgs e) { DGVGlassDetailsRigthClickOperation(4);//成品数据导出 } private void tsmiExportStock_Click(object sender, EventArgs e) { DGVStockRightClickOperation(3);//原片用量数据导出 } private void 异形模式ToolStripMenuItem_Click(object sender, EventArgs e) { } private void tsmiLabelPrint_Click(object sender, EventArgs e) { reportform.pack = 任务.pack; if (reportform.pack == null) return; reportform.按照版图打印标签_Click(sender, e); mainTab.SelectedIndex = 6; } public Dictionary dicReportPorcess = new Dictionary();//流程卡小片信息 public List lisProjectReportMark = new List(); private void TSMIUserInfo_Click(object sender, EventArgs e) { } private void tsmiUserInfoManage_Click(object sender, EventArgs e) { 用户信息 ui = new 用户信息(); ui.ShowDialog(); } private void tsmiRole_Click(object sender, EventArgs e) { 权限管理 set = new 权限管理(); set.ShowDialog(); } /// /// 权限控制显示 /// void PermissionControlDisplay() { 手工切割ToolStripMenuItem.Visible = false; //TSMIAbout.Visible = false; } private void tsmiAddStock_Click(object sender, EventArgs e) { DGVStockRightClickOperation(4); } private void TSMIPolysToSaveDXF_Click(object sender, EventArgs e) { if (polyView.CurrentRow == null) { return; } if (polyView.CurrentRow.Cells[5].Value == null) { return; } dxfPolygon dxfpoly = new dxfPolygon(); dxfpoly.ABS_Deserialize(polyView.CurrentRow.Cells[5].Value.ToString()); float w = Convert.ToInt64(polyView.CurrentRow.Cells["宽度"].Value); float h = Convert.ToInt64(polyView.CurrentRow.Cells["高度"].Value); netDxf.DxfDocument dxf = netDxf.DxfDocument.Str2dxfDocument(polyView.CurrentRow.Cells[5].Value.ToString()); string path = string.Format(@"C:\Users\32238\Desktop\DXF导出测试"); dxf.Save(path + "\\" + w + "*" + h + ".dxf"); } private void 导入DXF图形_Click(object sender, EventArgs e) { } #region 用于统计当前打开工程中的流程卡信息 /// /// 统计流程卡信息 /// public void countProcessInfo() { DataTable dt = FlowCardDB.GetPorcessReportDataByProject(openProject.project_no); if (dt == null) { return; } dicReportPorcess.Clear(); lisProjectReportMark.Clear(); foreach (DataRow dr in dt.Rows) { string layer = dr["glass_layer"].ToString(); string process_id = dr["process_id"].ToString(); string key = process_id + "." + layer; double width = Convert.ToDouble(dr["width"].ToString()); double height = Convert.ToDouble(dr["height"].ToString()); int glass_num = Convert.ToInt32(dr["quantity"].ToString()); double glass_area = Convert.ToDouble(dr["total_area"].ToString()); bool widthIsMax = width > height; if (dicReportPorcess.ContainsKey(key)) { dicReportPorcess[key].max_edge = widthIsMax ? (width > dicReportPorcess[key].max_edge ? width : dicReportPorcess[key].max_edge) : (height > dicReportPorcess[key].max_edge ? height : dicReportPorcess[key].max_edge); dicReportPorcess[key].min_edge = widthIsMax ? (height > dicReportPorcess[key].min_edge ? dicReportPorcess[key].min_edge : height) : (width > dicReportPorcess[key].min_edge ? dicReportPorcess[key].min_edge : width); dicReportPorcess[key].spec_num += 1; dicReportPorcess[key].glass_num += glass_num; dicReportPorcess[key].glass_area += glass_area; } else { ReportProcessCardModel rpm = new ReportProcessCardModel { glass_num = glass_num, max_edge = widthIsMax ? width : height, min_edge = !widthIsMax ? width : height, spec_num = 1, card_code = key, glass_area = glass_area }; dicReportPorcess.Add(key, rpm); } string markLabel = dr["icon"] != null ? dr["icon"].ToString() : ""; if (!string.IsNullOrWhiteSpace(markLabel)) { MarkModel mm = JsonConvert.DeserializeObject(markLabel); if (!lisProjectReportMark.Contains(mm.trademark)) { lisProjectReportMark.Add(mm.trademark); } } } } #endregion /// /// 保存提示框显示位置 /// void containerShow() { int x = (this.Width - containerMsg.Width) / 2; int y = (this.Height - containerMsg.Height) / 2; containerMsg.Location = new Point(x, y); } #region OPTIMA 优化 bool optimaOver = false; /// /// 优先使用物料 /// /// /// private void tsmiPriority_Click(object sender, EventArgs e) { foreach (DataGridViewCell cell in stockView.SelectedCells) { stockView.Rows[cell.RowIndex].Cells["优先"].Value = Convert.ToInt32(stockView.Rows[cell.RowIndex].Cells["优先"].Value) + 1; } } bool commandStatus = false;//指令状态 string operationSteps = "导入"; string commandFilePath = string.Format(@"{1}\{0}", "EXTApp.TOAction.EXTAppReceiveFromEWA", OptimaConfig.outputPath);//指令输入路径 string[] listOPTResultContent;//初始信息 public static List listChangeOPTContent = new List();//带有打标信息 public static string BBStringResult = "";//转换的北玻长字符串 int operTime = 0; private delegate void OptimaProgressBarShow(int i); public static Dictionary dicReportProjectUseStock = new Dictionary(); //记录原片使用用量 Dictionary dicUseStock = new Dictionary(); private void tsmiNoPriority_Click(object sender, EventArgs e) { foreach (DataGridViewCell cell in stockView.SelectedCells) { stockView.Rows[cell.RowIndex].Cells["优先"].Value = 1; } } private void lblBtnCloseMsg_Click(object sender, EventArgs e) { containerMsg.Visible = false; } #endregion #region 现补 string patchStr = Setting.language == 1 ? "patch" : "现补"; void createPatchProject() { if (openProject != null && openProject.state < 20 && pack != null) { if (globel.ShowFromConfirmMessage("当前工程有结果未保存,是否确认重新创建补片工程?")) { return; } } //txtProjectNo.Text = PatchProjectDB.getPatchProjectNo(); txtProjectNo.Text = ProjectDB.CreateProject(0); projectnameText.Text = patchStr; openProject = new ProjectModel() { project_no = txtProjectNo.Text, state = 10, strRemark = "补片" //name = projectnameText.Text ="手动工程", }; pack = null; polyView.Rows.Clear(); polyView.ReadOnly = true; //polyView.AllowUserToAddRows = true; mainTab.SelectedIndex = 0; this.Text = "北玻自动化玻璃优化系统"; cmbGlassType.Enabled = true; cmbGlassThick.Enabled = true; Setting.renwudantable = null; Setting.glasstype = ""; Setting.thick = ""; cmbGlassThick.Text = ""; cmbGlassType.Text = ""; stockView.Rows.Clear(); //tsmiAddStock.Visible = true; countTxt.Text = areaTxt.Text = zhouchangTxt.Text = YPMJ.Text = YPSL.Text = "0"; showGlassType(); } //余料管理 private void tsmiOffcutMangage_Click(object sender, EventArgs e) { //余料管理 余料管理 yl = new 余料管理(); yl.ShowDialog(); } private void tsmiCratePatchProject_Click(object sender, EventArgs e) { createPatchProject(); } bool showPatchPolysData(string hd, string mx) { polyView.Rows.Clear(); DataTable dt = PatchProjectDB.getPatchGlass(mx, hd); if (dt == null) { globel.ShowFromWarningMessage("没有当前膜系的现补小片"); return false; } loadPatchPolys(dt); CountPolyNumberOrArea(); return true; } bool showPatchPolysData(string hd, string mx, string txt) { polyView.Rows.Clear(); DataTable dt = PatchProjectDB.getPatchGlass2(mx, hd, txt); if (dt == null) { globel.ShowFromWarningMessage("没有符合条件的现补小片"); return false; } loadPatchPolys(dt); CountPolyNumberOrArea(); return true; } string strPatch = Setting.language == 0 ? "补片" : "Patch"; void loadPatchPolys(DataTable dt) { bool autofill = currentEdge.auto_fill_edge; int glassNumber = 1; foreach (DataRow dr in dt.Rows) { //用于优化的小片数据展示 int index = this.polyView.Rows.Add(); object width = this.polyView.Rows[index].Cells["宽度"].Value = dr["width"]; object height = this.polyView.Rows[index].Cells["高度"].Value = dr["height"]; this.polyView.Rows[index].Cells["数量"].Value = 1; this.polyView.Rows[index].Cells["模板号"].Value = 100; //是否填充 bool filling = Math.Min(Convert.ToInt64(width), Convert.ToInt64(height)) < currentEdge.min_auto_lenght; this.polyView.Rows[index].Cells["长磨1"].Value = autofill ? filling ? "0" : currentEdge.down_edge.ToString() : "0"; this.polyView.Rows[index].Cells["短磨1"].Value = autofill ? filling ? "0" : currentEdge.left_edge.ToString() : "0"; this.polyView.Rows[index].Cells["长磨2"].Value = autofill ? filling ? "0" : currentEdge.up_edge.ToString() : "0"; this.polyView.Rows[index].Cells["短磨2"].Value = autofill ? filling ? "0" : currentEdge.right_edge.ToString() : "0"; this.polyView.Rows[index].Cells["流程卡号"].Value = dr["flow_card_id"]; this.polyView.Rows[index].Cells["架号"].Value = dr["tempering_layout_id"]; this.polyView.Rows[index].Cells["序号"].Value = dr["total_layer"]; this.polyView.Rows[index].Cells["编号"].Value = glassNumber; polyView.Rows[index].Cells["面积"].Value = Math.Round(Convert.ToInt64(width) * Convert.ToInt64(height) * Math.Pow(10, -6), 3); polyView.Rows[index].Cells["单价"].Value = "0"; polyView.Rows[index].Cells["单片名称"].Value = $"{strPatch}-" + dr["glass_id"]; polyView.Rows[index].Cells["产品名称"].Value = dr["remark"]; polyView.Rows[index].Cells["楼层编号"].Value = ""; polyView.Rows[index].Cells["印标类型"].Value = dr["mark_icon"]; polyView.Rows[index].Cells["备注"].Value = dr["glass_id"]; polyView.Rows[index].Cells["玻璃层"].Value = dr["layer"]; //自动计算面积 double w, h; int c; if (polyView.Rows[index].Cells["宽度"].Value != null && double.TryParse(polyView.Rows[index].Cells["宽度"].Value.ToString(), out w) && polyView.Rows[index].Cells["高度"].Value != null && double.TryParse(polyView.Rows[index].Cells["高度"].Value.ToString(), out h) && polyView.Rows[index].Cells["数量"].Value != null && int.TryParse(polyView.Rows[index].Cells["数量"].Value.ToString(), out c)) { polyView.Rows[index].Cells["周长"].Value = Functions.decimalconvert((2 * w + 2 * h) * c * Math.Pow(10, -3)); } newRectRow(index, 100); glassNumber++; } } private void tsmiClearStock_Click(object sender, EventArgs e) { stockView.Rows.Clear(); } private void txtFilter_Enter(object sender, EventArgs e) { if (txtFilter.Text.Trim() == filtertext) { txtFilter.Text = ""; txtFilter.ForeColor = Color.Black; } } private void txtFilter_Leave(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtFilter.Text.Trim())) { txtFilter.Text = filtertext; txtFilter.ForeColor = Color.Silver; } } void showGlassType() { DataTable dt = PatchProjectDB.GetAllPachtGlass(); if (dt != null) { cmbGlassThick.DataSource = null; cmbGlassType.DataSource = null; List lisGlassThick = new List(); List lisGlassType = new List(); foreach (DataRow dr in dt.Rows) { string gThick = dr["thickness"].ToString(); string gType = ""; if (globel.CustomerName == "义乌") { gType = dr["filmsid"].ToString(); } else { //films_id gType = dr["films_id"].ToString(); } if (!lisGlassThick.Contains(gThick)) { lisGlassThick.Add(gThick); } if (!lisGlassType.Contains(gType)) { lisGlassType.Add(gType); } } cmbGlassThick.DataSource = lisGlassThick; cmbGlassType.DataSource = lisGlassType; } } #endregion } }