Beispiel #1
0
 private void AssignNewMaterial(ProductMaterial item)
 {
     if (item == null) return;
     if (!materials.ContainsKey(item.MaterialID)) return;
     ProductMaterial oldItem = materials[item.MaterialID];
     oldItem.MaterialName = item.MaterialName;
     oldItem.Remark = item.Remark;
 }
Beispiel #2
0
 private ProductMaterial GetProductMaterialFrom(DataRow row)
 {
     if (row == null) return null;
     ProductMaterial pc = new ProductMaterial();
     pc.MaterialID = Formatter.GetStringValueFrom(row, "MaterialID");
     pc.MaterialName = Formatter.GetStringValueFrom(row, "MaterialName");
     pc.Remark = Formatter.GetStringValueFrom(row, "Remark");
     return pc;
 }
Beispiel #3
0
 public ProductMaterial UpdateMaterial(ProductMaterial material)
 {
     if (material == null) return null;
     try
     {
         DataSet ds = SqlHelper.ExecuteDataset(sqlConn, "UpdateProductMaterial", new object[] { currentUser.UserID, material.MaterialID, material.MaterialName, material.Remark });
         if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
         {
             DataTable table = ds.Tables[0];
             ProductMaterial pm = GetProductMaterialFrom(table.Rows[0]);
             if (pm != null)
             {
                 if (!materials.ContainsKey(pm.MaterialID))
                     materials[pm.MaterialID] = pm;
                 else AssignNewMaterial(pm);
                 return pm;
             }
         }
     }
     catch (Exception ex)
     {
         LoggerBase.Instance.Error(ex.ToString());
     }
     return null;
 }
Beispiel #4
0
 private void btn_New_Click(object sender, EventArgs e)
 {
     NewParameter form = new NewParameter();
     if (form.ShowDialog(this) == DialogResult.OK)
     {
         bool ok = false;
         int i = cbx_ParamName.SelectedIndex;
         string paramName = form.ParameterName;
         string paramRemark = form.ParameterRemark;
         switch (cbx_ParamType.SelectedIndex)
         {
             case 0:
                 //Category
                 ProductCategory category = new ProductCategory();
                 category.CategoryName = paramName;
                 category.Remark = paramRemark;
                 ok = (DataService.Instance.CreateCategory(category) != null);
                 if (ok)
                 {
                     cbx_ParamName.Items.Clear();
                     cbx_ParamName.Items.AddRange(DataService.Instance.Categories.ToArray());
                 }
                 break;
             case 1:
                 //Sub Category
                 ProductSubCategory subCategory = cbx_ParamName.SelectedItem as ProductSubCategory;
                 if (subCategory != null)
                 {
                     ProductSubCategory newSubCate = new ProductSubCategory();
                     newSubCate.CategoryID = subCategory.CategoryID;
                     newSubCate.Remark = paramRemark;
                     newSubCate.SubCategoryName = paramName;
                     ok = (DataService.Instance.CreateSubCategory(newSubCate) != null);
                     if (ok)
                     {
                         cbx_ParamName.Items.Clear();
                         cbx_ParamName.Items.AddRange(DataService.Instance.SubCategories.ToArray());
                     }
                 }
                 break;
             case 2:
                 //Color
                 ProductColor color = new ProductColor();
                 color.ColorName = paramName;
                 color.Remark = paramRemark;
                 ok = (DataService.Instance.CreateColor(color) != null);
                 if (ok)
                 {
                     cbx_ParamName.Items.Clear();
                     cbx_ParamName.Items.AddRange(DataService.Instance.Colors.ToArray());
                 }
                 break;
             case 3:
                 //Crafts
                 ProductCrafts crafts = new ProductCrafts();
                 crafts.CraftsName = paramName;
                 crafts.Remark = paramRemark;
                 ok = (DataService.Instance.CreateCrafts(crafts) != null);
                 if (ok)
                 {
                     cbx_ParamName.Items.Clear();
                     cbx_ParamName.Items.AddRange(DataService.Instance.Crafts.ToArray());
                 }
                 break;
             case 4:
                 //Material
                 ProductMaterial material = new ProductMaterial();
                 material.MaterialName = paramName;
                 material.Remark = paramRemark;
                 ok = (DataService.Instance.CreateMaterial(material) != null);
                 if (ok)
                 {
                     cbx_ParamName.Items.Clear();
                     cbx_ParamName.Items.AddRange(DataService.Instance.Materials.ToArray());
                 }
                 break;
             default:
                 break;
         }
         if (!ok)
         {
             MessageBox.Show(ResourceHelper.Instance.GetString("NewParameter.New.Failed"), Text);
         }
         else
         {
             if (cbx_ParamName.Items.Count > i)
                 cbx_ParamName.SelectedIndex = i;
         }
     }
 }