Exemplo n.º 1
0
 private void AssignNewCategory(ProductCategory item)
 {
     if (item == null) return;
     if (!categories.ContainsKey(item.CategoryID)) return;
     ProductCategory oldItem = categories[item.CategoryID];
     oldItem.CategoryName = item.CategoryName;
     oldItem.Remark = item.Remark;
 }
Exemplo n.º 2
0
 private ProductCategory GetProductCategoryFrom(DataRow row)
 {
     if (row == null) return null;
     ProductCategory pc = new ProductCategory();
     pc.CategoryID = Formatter.GetStringValueFrom(row, "CategoryID");
     pc.CategoryName = Formatter.GetStringValueFrom(row, "CategoryName");
     pc.Remark = Formatter.GetStringValueFrom(row, "Remark");
     return pc;
 }
Exemplo n.º 3
0
 public ProductCategory UpdateCategory(ProductCategory category)
 {
     if (category == null) return null;
     try
     {
         DataSet ds = SqlHelper.ExecuteDataset(sqlConn, "UpdateProductCategory", new object[] { currentUser.UserID, category.CategoryID, category.CategoryName, category.Remark });
         if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
         {
             DataTable table = ds.Tables[0];
             ProductCategory pc = GetProductCategoryFrom(table.Rows[0]);
             if (pc != null)
             {
                 if (!categories.ContainsKey(pc.CategoryID))
                     categories[pc.CategoryID] = pc;
                 else AssignNewCategory(pc);
                 return pc;
             }
         }
     }
     catch (Exception ex)
     {
         LoggerBase.Instance.Error(ex.ToString());
     }
     return null;
 }
Exemplo n.º 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;
         }
     }
 }