Beispiel #1
0
 public StockForm(ProductInfo pi, bool increase)
 {
     InitializeComponent();
     currentProduct = pi;
     tbx_Stock.Text = "1";
     this.increase = increase;
     if (increase)
         lbl_Warning.Text = ResourceHelper.Instance.GetString("Main.Stock.Add.Warning");
     else
     {
         lbl_Warning.Text = ResourceHelper.Instance.GetString("Main.Stock.Minus.Warning");
         lbl_Stock.Text = ResourceHelper.Instance.GetString("Stock.ReduceStock");
     }
     lbl_ProductInfo.Text = pi.Representation;
 }
Beispiel #2
0
        public void InitialData(ProductInfo pi)
        {
            ToggleBtnState();
            currentProduct = pi;
            newMode = (pi == null);
            cbx_Category.Items.AddRange(DataService.Instance.Categories.ToArray());
            cbx_Origin.Items.AddRange(DataService.Instance.Origins.ToArray());
            cbx_Status.Items.AddRange(DataService.Instance.StatusList.ToArray());
            cbx_Style.Items.AddRange(DataService.Instance.StyleList.ToArray());
            cbx_Color.Items.AddRange(DataService.Instance.Colors.ToArray());
            cbx_Crafts.Items.AddRange(DataService.Instance.Crafts.ToArray());
            cbx_Material.Items.AddRange(DataService.Instance.Materials.ToArray());

            if (cbx_Category.Items.Count > 0) cbx_Category.SelectedIndex = 0;
            if (cbx_Style.Items.Count > 0) cbx_Style.SelectedIndex = 0;
            if (cbx_Origin.Items.Count > 0) cbx_Origin.SelectedIndex = 0;
            if (cbx_Status.Items.Count > 0) cbx_Status.SelectedIndex = 0;
            if (cbx_Color.Items.Count > 0) cbx_Color.SelectedIndex = 0;
            if (cbx_Crafts.Items.Count > 0) cbx_Crafts.SelectedIndex = 0;
            if (cbx_Material.Items.Count > 0) cbx_Material.SelectedIndex = 0;

            dtp_ProductionDate.Value = DateTime.Now;
            PaintProduct(pi);
        }
Beispiel #3
0
 public ProductInfo UpdateProduct(ProductInfo pi)
 {
     if (pi == null) return null;
     try
     {
         DataSet ds = SqlHelper.ExecuteDataset(sqlConn, "UpdateProductDetail", pi.GetUpdateParams().ToArray());
         if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
         {
             DataTable table = ds.Tables[0];
             ProductInfo product = GetProductInfoFrom(table.Rows[0]);
             if (product != null)
             {
                 if (!products.ContainsKey(product.ProductID))
                     products[product.ProductID] = product;
                 else
                     AssignNewProduct(product);
                 if (OnProductUpdated != null)
                 {
                     OnProductUpdated(this, new ProductUpdateEventArgs(product));
                 }
                 return product;
             }
         }
     }
     catch (Exception ex)
     {
         LoggerBase.Instance.Error(ex.ToString());
     }
     return null;
 }
Beispiel #4
0
 public bool DeleteProduct(ProductInfo pi)
 {
     if (pi == null) return false;
     try
     {
         int count = SqlHelper.ExecuteNonQuery(sqlConn, "DeleteProductDetails", new object[] { pi.ProductID, currentUser.UserID });
         if (count > 0)
         {
             if (products.ContainsKey(pi.ProductID))
                 products.Remove(pi.ProductID);
             return true;
         }
     }
     catch (Exception ex)
     {
         LoggerBase.Instance.Error(ex.ToString());
     }
     return false;
 }
Beispiel #5
0
 public ProductUpdateEventArgs(ProductInfo pi)
 {
     this.pi = pi;
 }
Beispiel #6
0
 private ProductInfo GetProductInfoFrom(DataRow row)
 {
     if (row == null) return null;
     ProductInfo pi = new ProductInfo();
     pi.ProductID = Formatter.GetStringValueFrom(row, "ProductID");
     pi.ProductName = Formatter.GetStringValueFrom(row, "ProductName");
     pi.CategoryName = Formatter.GetStringValueFrom(row, "CategoryName");
     pi.Color = Formatter.GetStringValueFrom(row, "ColorName");
     pi.Crafts = Formatter.GetStringValueFrom(row, "CraftsName");
     pi.CreateDate = Formatter.GetDateTimeValueFrom(row, "CreateDate");
     pi.Image = Formatter.GetImageFrom(row, "Image");
     pi.Material = Formatter.GetStringValueFrom(row, "MaterialName");
     pi.ModifiedDate = Formatter.GetDateTimeValueFrom(row, "ModifiedDate");
     pi.OriginName = Formatter.GetStringValueFrom(row, "OriginName");
     pi.ProductionDate = Formatter.GetDateTimeValueFrom(row, "ProductionDate");
     pi.Quantity = Formatter.GetStringValueFrom(row, "Quantity");
     pi.Specification = Formatter.GetStringValueFrom(row, "Spec");
     pi.StatusName = Formatter.GetStringValueFrom(row, "StatusName");
     pi.StyleName = Formatter.GetStringValueFrom(row, "StyleName");
     pi.SubCategoryName = Formatter.GetStringValueFrom(row, "SubCategoryName");
     pi.Weight = Formatter.GetStringValueFrom(row, "Weight");
     pi.Remark = Formatter.GetStringValueFrom(row, "Remark");
     pi.CategoryID = Formatter.GetStringValueFrom(row, "CategoryID");
     pi.ColorID = Formatter.GetStringValueFrom(row, "ColorID");
     pi.CraftsID = Formatter.GetStringValueFrom(row, "CraftsID");
     pi.MaterialID = Formatter.GetStringValueFrom(row, "MaterialID");
     pi.OriginID = Formatter.GetStringValueFrom(row, "OriginID");
     pi.StatusID = Formatter.GetStringValueFrom(row, "StatusID");
     pi.StyleID = Formatter.GetStringValueFrom(row, "StyleID");
     pi.SubCategoryID = Formatter.GetStringValueFrom(row, "SubCategoryID");
     pi.Stock = Formatter.GetIntValueFrom(row, "Stock");
     return pi;
 }
Beispiel #7
0
 private void AssignNewProduct(ProductInfo pi)
 {
     if (pi == null) return;
     if (products == null) return;
     if (!products.ContainsKey(pi.ProductID)) return;
     ProductInfo oldProduct = products[pi.ProductID];
     oldProduct.ProductName = pi.ProductName;
     oldProduct.CategoryName = pi.CategoryName;
     oldProduct.Color = pi.Color;
     oldProduct.Crafts = pi.Crafts;
     oldProduct.CreateDate = pi.CreateDate;
     oldProduct.Image = pi.Image;
     oldProduct.Material = pi.Material;
     oldProduct.ModifiedDate = pi.ModifiedDate;
     oldProduct.OriginName = pi.OriginName;
     oldProduct.ProductionDate = pi.ProductionDate;
     oldProduct.Quantity = pi.Quantity;
     oldProduct.Specification = pi.Specification;
     oldProduct.StatusName = pi.StatusName;
     oldProduct.StyleName = pi.StyleName;
     oldProduct.SubCategoryName = pi.SubCategoryName;
     oldProduct.Weight = pi.Weight;
     oldProduct.Remark = pi.Remark;
     oldProduct.CategoryID = pi.CategoryID;
     oldProduct.ColorID = pi.ColorID;
     oldProduct.CraftsID = pi.CraftsID;
     oldProduct.MaterialID = pi.MaterialID;
     oldProduct.OriginID = pi.OriginID;
     oldProduct.StatusID = pi.StatusID;
     oldProduct.StyleID = pi.StyleID;
     oldProduct.SubCategoryID = pi.SubCategoryID;
     oldProduct.Stock = pi.Stock;
 }
Beispiel #8
0
 private void PaintProduct(ProductInfo pi)
 {
     if (pi == null) return;
     wtbx_ProductName.Text = pi.ProductName;
     dtp_ProductionDate.Value = pi.ProductionDate;
     wtbx_Qty.Text = pi.Quantity;
     wtbx_Weight.Text = pi.Weight;
     rtbx_Remark.Text = pi.Remark;
     rtbx_Spec.Text = pi.Specification;
     pictureBox1.Image = pi.Image;
     tbx_Stock.Text = pi.Stock.ToString("N0");
     cbx_Category.SelectedItem = DataService.Instance.CategoryOf(pi.CategoryID);
     cbx_Color.SelectedItem = DataService.Instance.ColorOf(pi.ColorID);
     cbx_Crafts.SelectedItem = DataService.Instance.CraftsOf(pi.CraftsID);
     cbx_Material.SelectedItem = DataService.Instance.MaterialOf(pi.MaterialID);
     cbx_Origin.SelectedItem = DataService.Instance.OriginOf(pi.OriginID);
     cbx_Status.SelectedItem = DataService.Instance.StatusOf(pi.StatusID);
     cbx_Style.SelectedItem = DataService.Instance.StyleOf(pi.StyleID);
     cbx_SubCategory.SelectedItem = DataService.Instance.SubCategoryOf(pi.SubCategoryID);
 }
Beispiel #9
0
        private ProductInfo GetProductInfo()
        {
            ProductInfo pi = new ProductInfo();
            if (!newMode)
            {
                if (currentProduct == null) return null;
                pi.ProductID = currentProduct.ProductID;
            }

            ProductCategory category = cbx_Category.SelectedItem as ProductCategory;
            if (category == null) return null;
            pi.CategoryID = category.CategoryID;
            ProductColor color = cbx_Color.SelectedItem as ProductColor;
            if (color == null) return null;
            pi.ColorID = color.ColorID;
            ProductCrafts crafts = cbx_Crafts.SelectedItem as ProductCrafts;
            if (crafts == null) return null;
            pi.CraftsID = crafts.CraftsID;
            ProductMaterial material = cbx_Material.SelectedItem as ProductMaterial;
            if (material == null) return null;
            pi.MaterialID = material.MaterialID;
            ProductOrigin origin = cbx_Origin.SelectedItem as ProductOrigin;
            if (origin == null) return null;
            pi.OriginID = origin.OriginID;
            pi.ProductionDate = dtp_ProductionDate.Value;
            pi.ProductName = wtbx_ProductName.Text;
            pi.Quantity = wtbx_Qty.Text;
            pi.Remark = rtbx_Remark.Text;
            pi.Specification = rtbx_Spec.Text;
            ProductStatus status = cbx_Status.SelectedItem as ProductStatus;
            if (status == null) return null;
            pi.StatusID = status.StatusID;
            ProductStyle style = cbx_Style.SelectedItem as ProductStyle;
            if (style == null) return null;
            pi.StyleID = style.StyleID;
            ProductSubCategory subcategory = cbx_SubCategory.SelectedItem as ProductSubCategory;
            if (subcategory == null) return null;
            pi.SubCategoryID = subcategory.SubCategoryID;
            pi.Weight = wtbx_Weight.Text;
            pi.Image = pictureBox1.Image as Bitmap;
            return pi;
        }