private void ComponentOuterPackingSizeModify_Load(object sender, EventArgs e) { if (this.setItem == SUPPLY_OuterPackingSize) { if (this.mode == FormMode.ALTER && this.ID == -1) { throw new Exception("未设置源零件信息"); } Utilities.CreateEditPanel(this.tableLayoutPanelTextBoxes, SupplyViewMetaData.supplyOuterPackingSizekeyNames); if (this.mode == FormMode.ALTER || this.mode == FormMode.CHECK) { try { DataAccess.Supply supply = (from s in this.wmsEntities.Supply where s.ID == this.ID select s).FirstOrDefault(); Utilities.CopyPropertiesToTextBoxes(supply, this); } catch (Exception) { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } } if (this.setItem == COMPONENT_OuterPackingSize) { if (this.mode == FormMode.ALTER && this.ID == -1) { throw new Exception("未设置源零件信息"); } Utilities.CreateEditPanel(this.tableLayoutPanelTextBoxes, ComponenViewMetaData.ComponentOuterPackingSizekeyNames); if (this.mode == FormMode.ALTER || this.mode == FormMode.CHECK) { try { DataAccess.Component componen = (from s in this.wmsEntities.Component where s.ID == this.ID select s).FirstOrDefault(); Utilities.CopyPropertiesToTextBoxes(componen, this); } catch (Exception) { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } } if (this.mode == FormMode.CHECK) { this.buttonOK.Visible = false; } }
private void buttonOK_Click(object sender, EventArgs e) { if (this.setItem == SUPPLY_OuterPackingSize) { DialogResult MsgBoxResult = DialogResult.No;//设置对话框的返回值 //询问是否保留历史信息 if (this.mode == FormMode.ALTER) { MsgBoxResult = MessageBox.Show("是否要保留历史信息", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } DataAccess.Supply supply = null; if (this.mode == FormMode.ALTER) { try { supply = (from s in this.wmsEntities.Supply where s.ID == this.ID select s).FirstOrDefault(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (supply == null) { MessageBox.Show("历史零件信息不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MsgBoxResult == DialogResult.Yes)//如果对话框的返回值是YES(按"Y"按钮) { //新建零件保留历史信息 this.wmsEntities.Supply.Add(supply); try { supply.ID = -1; supply.IsHistory = 1; supply.NewestSupplyID = this.ID; supply.LastUpdateUserID = this.userID; supply.LastUpdateTime = DateTime.Now; wmsEntities.SaveChanges(); } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { supply = (from s in this.wmsEntities.Supply where s.ID == this.ID select s).FirstOrDefault(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (supply == null) { MessageBox.Show("零件信息不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } //开始数据库操作 if (Utilities.CopyTextBoxTextsToProperties(this, supply, SupplyViewMetaData.supplyOuterPackingSizekeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { Utilities.CopyComboBoxsToProperties(this, supply, SupplyViewMetaData.supplyOuterPackingSizekeyNames); } supply.LastUpdateUserID = this.userID; supply.LastUpdateTime = DateTime.Now; supply.IsHistory = 0; wmsEntities.SaveChanges(); //调用回调函数 if (this.mode == FormMode.ALTER && this.modifyFinishedCallback != null) { this.modifyFinishedCallback(supply.ID); MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } if (this.setItem == COMPONENT_OuterPackingSize) { DataAccess.Component componen = null; if (this.mode == FormMode.ALTER) { try { componen = (from s in this.wmsEntities.Component where s.ID == this.ID select s).FirstOrDefault(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (componen == null) { MessageBox.Show("历史零件信息不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } //开始数据库操作 if (Utilities.CopyTextBoxTextsToProperties(this, componen, ComponenViewMetaData.ComponentOuterPackingSizekeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { Utilities.CopyComboBoxsToProperties(this, componen, ComponenViewMetaData.ComponentOuterPackingSizekeyNames); } wmsEntities.SaveChanges(); //调用回调函数 if (this.mode == FormMode.ALTER && this.modifyFinishedCallback != null) { this.modifyFinishedCallback(componen.ID); MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } }
private void buttonOK_Click(object sender, EventArgs e) { DialogResult messageBoxResult = DialogResult.No;//设置对话框的返回值 var textBoxSupplierName = this.Controls.Find("textBoxSupplierName", true)[0]; var textBoxNo = this.Controls.Find("textBoxNo", true)[0]; var textBoxComponentName = this.Controls.Find("textBoxComponentName", true)[0]; //询问是否保留历史信息 if (this.mode == FormMode.ALTER && this.history_save == 0) { messageBoxResult = MessageBox.Show("是否要保留历史信息", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } if (textBoxNo.Text == string.Empty) { MessageBox.Show("零件代号不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (textBoxComponentName.Text == string.Empty) { MessageBox.Show("零件名称不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { string componentName = textBoxComponentName.Text; try { DataAccess.Component componenID1 = (from s in this.wmsEntities.Component where s.Name == componentName select s).FirstOrDefault(); this.componenID = componenID1.ID; } catch { } } if (textBoxSupplierName.Text == string.Empty) { MessageBox.Show("请选择供应商!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { string supplierName = textBoxSupplierName.Text; try { Supplier supplierID = (from s in this.wmsEntities.Supplier where s.Name == supplierName && s.IsHistory == 0 select s).FirstOrDefault(); this.supplierID = supplierID.ID; } catch { } } //if (this.supplierID == -1) //{ // MessageBox.Show("请输入正确的供应商名称!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} Supply supply = null; if (this.mode == FormMode.ALTER) { try { supply = (from s in this.wmsEntities.Supply where s.ID == this.supplyID select s).FirstOrDefault(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (supply == null) { MessageBox.Show("历史零件信息不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var sameNameUsers = (from u in wmsEntities.Supply where u.No == textBoxNo.Text && u.ID != supply.ID && u.IsHistory == 0 && u.ProjectID == this.projectID && u.WarehouseID == this.warehouseID select u).ToArray(); if (sameNameUsers.Length > 0) { MessageBox.Show("修改供应信息失败,已存在相同代号条目:" + textBoxNo.Text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //try //{ // var sameNameUsers = (from u in wmsEntities.Supply // where u.SupplierID == supplierID // && u.ComponentID == this.componenID // && u.No == textBoxNo.Text // && u.ID != supply.ID && u.IsHistory == 0 // && u.ProjectID == this.projectID && u.WarehouseID == this.warehouseID // select u).ToArray(); // if (sameNameUsers.Length > 0) // { // MessageBox.Show("修改供应信息失败,已存在同名供应商——零件供货条目:" + textBoxSupplierName.Text + "——" + textBoxComponentName.Text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } //} //catch //{ // MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} if (messageBoxResult == DialogResult.Yes)//如果对话框的返回值是YES(按"Y"按钮) { //新建零件保留历史信息 this.wmsEntities.Supply.Add(supply); try { supply.ID = -1; supply.IsHistory = 1; supply.NewestSupplyID = this.supplyID; supply.LastUpdateUserID = this.userID; supply.LastUpdateTime = DateTime.Now; wmsEntities.SaveChanges(); } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var supplystorge = (from u in wmsEntities.Supply where u.NewestSupplyID == this.supplyID select u).ToArray(); if (supplystorge.Length > 0) { MessageBox.Show("历史信息保留成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.history_save = 1; } try { supply = (from s in this.wmsEntities.Supply where s.ID == this.supplyID select s).FirstOrDefault(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (supply == null) { MessageBox.Show("零件信息不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } supply.ProjectID = this.projectID; supply.WarehouseID = this.warehouseID; supply.SupplierID = this.supplierID; supply.ComponentID = this.componenID; //开始数据库操作 if (Utilities.CopyTextBoxTextsToProperties(this, supply, SupplyViewMetaData.supplykeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { Utilities.CopyComboBoxsToProperties(this, supply, SupplyViewMetaData.KeyNames); } supply.LastUpdateUserID = this.userID; supply.LastUpdateTime = DateTime.Now; supply.IsHistory = 0; wmsEntities.SaveChanges(); } else if (mode == FormMode.ADD) { try { var sameNameUsers = (from u in wmsEntities.Supply where u.No == textBoxNo.Text && u.ProjectID == this.projectID && u.WarehouseID == this.warehouseID select u).ToArray(); if (sameNameUsers.Length > 0) { MessageBox.Show("修改供应信息失败,已存在相同代号条目:" + textBoxNo.Text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } supply = new DataAccess.Supply(); supply.CreateUserID = this.userID; //supply.CreateTime = DateTime.Now; supply.ProjectID = this.projectID; supply.WarehouseID = this.warehouseID; supply.SupplierID = this.supplierID; supply.ComponentID = this.componenID; //把选择零件的默认包装信息存进供应表 DataAccess.Component componenID = (from s in this.wmsEntities.Component where s.ID == this.componenID select s).FirstOrDefault(); PropertyInfo[] proAs = componenID.GetType().GetProperties(); PropertyInfo[] proBs = supply.GetType().GetProperties(); for (int i = 0; i < proAs.Length; i++) { for (int j = 0; j < proBs.Length; j++) { if (proAs[i].Name == "Default" + proBs[j].Name) { object a = proAs[i].GetValue(componenID, null); proBs[j].SetValue(supply, a, null); } } } //开始数据库操作 if (Utilities.CopyTextBoxTextsToProperties(this, supply, SupplyViewMetaData.supplykeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { Utilities.CopyComboBoxsToProperties(this, supply, SupplyViewMetaData.KeyNames); } supply.LastUpdateUserID = this.userID; supply.LastUpdateTime = DateTime.Now; supply.IsHistory = 0; this.wmsEntities.Supply.Add(supply); wmsEntities.SaveChanges(); } //supply.ProjectID = this.projectID; //supply.WarehouseID = this.warehouseID; //supply.SupplierID = this.supplierID; //supply.ComponentID = this.componenID; ////开始数据库操作 //if (Utilities.CopyTextBoxTextsToProperties(this, supply, SupplyViewMetaData.supplykeyNames, out string errorMessage) == false) //{ // MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} //else //{ // Utilities.CopyComboBoxsToProperties(this, supply, SupplyViewMetaData.KeyNames); //} //supply.LastUpdateUserID = this.userID; //supply.LastUpdateTime = DateTime.Now; //supply.IsHistory = 0; //wmsEntities.SaveChanges(); //调用回调函数 if (this.mode == FormMode.ALTER && this.modifyFinishedCallback != null) { this.modifyFinishedCallback(supply.ID); MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else if (this.mode == FormMode.ADD && this.addFinishedCallback != null) { this.addFinishedCallback(supply.ID); MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }