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 buttonEnter_Click(object sender, EventArgs e) { if (WarehouseID.Text == string.Empty) { MessageBox.Show("仓库ID不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (SupplierID.Text == string.Empty) { MessageBox.Show("供应商ID不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //添加 DataAccess.Component objcomponen = new DataAccess.Component(); { objcomponen.WarehouseID = Convert.ToInt32(WarehouseID.Text); objcomponen.SupplierID = Convert.ToInt32(SupplierID.Text); objcomponen.ContainerNo = ContainerNo.Text; objcomponen.Factroy = Factroy.Text; objcomponen.WorkPosition = WorkPosition.Text; objcomponen.No = No.Text; objcomponen.Name = Name1.Text; objcomponen.SupplierType = SupplierType.Text; objcomponen.Type = Type.Text; objcomponen.Size = Size.Text; objcomponen.Category = Category.Text; objcomponen.GroupPrincipal = GroupPrincipal.Text; objcomponen.SingleCarUsageAmount = Convert.ToDecimal(SingleCarUsageAmount.Text); objcomponen.Charge1 = Convert.ToDecimal(ChargeBelow50000.Text); objcomponen.Charge1 = Convert.ToDecimal(ChargeAbove50000.Text); objcomponen.InventoryRequirement1Day = Convert.ToDecimal(InventoryRequirement1Day.Text); objcomponen.InventoryRequirement3Day = Convert.ToDecimal(InventoryRequirement3Day.Text); objcomponen.InventoryRequirement5Day = Convert.ToDecimal(InventoryRequirement5Day.Text); objcomponen.InventoryRequirement10Day = Convert.ToDecimal(InventoryRequirement10Day.Text); } WMSEntities wms = new WMSEntities(); wms.Component.Add(objcomponen); wms.SaveChanges(); MessageBox.Show("添加零件成功"); this.Close(); }
private void buttonEnter_Click(object sender, EventArgs e) { if (SupplierID.Text == string.Empty) { MessageBox.Show("供应商ID不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //修改 WMSEntities wms = new WMSEntities(); DataAccess.Component objuser = (from s in wms.Component where s.Name == Name1.Text select s).First(); objuser.SupplierID = Convert.ToInt32(SupplierID.Text); objuser.ContainerNo = ContainerNo.Text; objuser.Factroy = Factroy.Text; objuser.WorkPosition = WorkPosition.Text; objuser.No = No.Text; objuser.SupplierType = SupplierType.Text; objuser.Type = Type.Text; objuser.Size = Size.Text; objuser.Category = Category.Text; objuser.GroupPrincipal = GroupPrincipal.Text; objuser.SingleCarUsageAmount = Convert.ToDecimal(SingleCarUsageAmount.Text); objuser.Charge1 = Convert.ToDecimal(ChargeBelow50000.Text); objuser.Charge2 = Convert.ToDecimal(ChargeAbove50000.Text); objuser.InventoryRequirement1Day = Convert.ToDecimal(InventoryRequirement1Day.Text); objuser.InventoryRequirement3Day = Convert.ToDecimal(InventoryRequirement3Day.Text); objuser.InventoryRequirement5Day = Convert.ToDecimal(InventoryRequirement5Day.Text); objuser.InventoryRequirement10Day = Convert.ToDecimal(InventoryRequirement10Day.Text); wms.SaveChanges(); MessageBox.Show("修改零件成功"); this.Close(); }
public static bool GetSupplyOrComponentAmbiguous(string supplyNoOrComponentName, out DataAccess.Component component, out Supply supply, out string errorMessage, int supplierID = -1, WMSEntities wmsEntities = null) { if (wmsEntities == null) { wmsEntities = new WMSEntities(); } //如果输入的名字是空的,直接抛出异常。这儿不允许传入空的 if (string.IsNullOrWhiteSpace(supplyNoOrComponentName)) { throw new Exception("GetSupplyOrComponent()函数不允许传入空的零件名字(代号)!空格也不行!请使用string.IsNullOrWhiteSpace()自行判空"); } //首先精确查询,如果没有,再模糊查询 component = (from c in wmsEntities.Component where c.Name == supplyNoOrComponentName && (from s in wmsEntities.Supply where s.ComponentID == c.ID && s.ProjectID == GlobalData.ProjectID && s.WarehouseID == GlobalData.WarehouseID && s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID) select s).Count() > 0 select c).FirstOrDefault(); supply = (from s in wmsEntities.Supply where s.No == supplyNoOrComponentName && s.ProjectID == GlobalData.ProjectID && s.WarehouseID == GlobalData.WarehouseID && s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID) && s.IsHistory == 0 select s).FirstOrDefault(); if (component == null && supply == null) { //模糊查询供货 Supply[] supplies = (from s in wmsEntities.Supply where s.No.Contains(supplyNoOrComponentName) && s.ProjectID == GlobalData.ProjectID && s.WarehouseID == GlobalData.WarehouseID && s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID) && s.IsHistory == 0 select s).ToArray(); //模糊查询零件 DataAccess.Component[] components = (from c in wmsEntities.Component where c.Name.Contains(supplyNoOrComponentName) && (from s in wmsEntities.Supply where s.ComponentID == c.ID && s.ProjectID == GlobalData.ProjectID && s.WarehouseID == GlobalData.WarehouseID && s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID) select s).Count() > 0 select c).ToArray(); if (supplies.Length + components.Length == 0) { component = null; supply = null; errorMessage = "未找到零件:" + supplyNoOrComponentName; return(false); } //Supply或Component不唯一的情况 if (supplies.Length + components.Length != 1) { object selectedObj = FormChooseAmbiguousSupplyOrComponent.ChooseAmbiguousSupplyOrComponent( components, supplies, supplyNoOrComponentName); if (selectedObj == null) { errorMessage = "用户取消了导入"; return(false); } else if (selectedObj is DataAccess.Component) { component = selectedObj as DataAccess.Component; } else if (selectedObj is Supply) { supply = selectedObj as Supply; } else { throw new Exception("FormChooseAmbiguousSupplyOrComponent返回值类型错误"); } errorMessage = null; return(true); } //如果搜索到唯一的零件/供货,则确定就是它。 if (supplies.Length > 0) { supply = supplies[0]; } else { component = components[0]; } errorMessage = null; return(true); } errorMessage = null; return(true); }
private void buttonOK_Click(object sender, EventArgs e) { var textBoxName = this.Controls.Find("textBoxName", true)[0]; if (textBoxName.Text == string.Empty) { MessageBox.Show("零件名称不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DataAccess.Component componen = null; if (this.mode == FormMode.ALTER) { try { componen = (from s in this.wmsEntities.Component where s.ID == this.componenID select s).FirstOrDefault(); } catch { MessageBox.Show("修改失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (componen == null) { MessageBox.Show("零件信息不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var sameNameComponent = (from u in wmsEntities.Component where u.Name == textBoxName.Text && u.ID != componen.ID select u).ToArray(); if (sameNameComponent.Length > 0) { MessageBox.Show("修改零件名失败,已存在同名零件:" + textBoxName.Text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (mode == FormMode.ADD) { try { var sameNameComponent = (from u in wmsEntities.Component where u.Name == textBoxName.Text select u).ToArray(); if (sameNameComponent.Length > 0) { MessageBox.Show("修改零件名失败,已存在同名零件:" + textBoxName.Text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { MessageBox.Show("操作失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } componen = new DataAccess.Component(); this.wmsEntities.Component.Add(componen); } //开始数据库操作 if (Utilities.CopyTextBoxTextsToProperties(this, componen, ComponenViewMetaData.componenkeyNames, out string errorMessage) == false) { MessageBox.Show(errorMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { Utilities.CopyComboBoxsToProperties(this, componen, ComponenViewMetaData.KeyNames); } //componen.IsHistory = 0; wmsEntities.SaveChanges(); //调用回调函数 if (this.mode == FormMode.ALTER && this.modifyFinishedCallback != null) { this.modifyFinishedCallback(componen.ID); MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else if (this.mode == FormMode.ADD && this.addFinishedCallback != null) { this.addFinishedCallback(componen.ID); MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
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(); } }