Beispiel #1
0
        void UpdBtn_DoWork(object sender, DoWorkEventArgs e)
        {
            MsgToolsLabel.Text = "正在更新批量产品数据,请稍候...";
            ImpBtn.Enabled = false;
            UpdBtn.Enabled = false;
            SubmitBtn.Enabled = false;
            productDic.Clear();
            List<CategoryModel> CategoryList = new List<CategoryModel>();
            foreach (DataRowView dataRow in CategoriesList.CheckedItems)
            {
                Int32 value = Convert.ToInt32(dataRow["id"]);
                CategoryModel cateModel = new CategoryModel();
                cateModel.CategoryId = value;
                CategoryList.Add(cateModel);
            }

            List<TagModel> TagList = new List<TagModel>();
            foreach (string  tag in Tags)
            {
                TagModel tModel = new TagModel();
                tModel.Tag = tag;
                TagList.Add(tModel);
            }

            Int32 ManufacturerId = Convert.ToInt32(MaComboBox.SelectedValue);
            Int32 StockStatusId = Convert.ToInt32(StockComboBox.SelectedValue);
            Int32 WeightClassId = Convert.ToInt32(WeightComboBox.SelectedValue);
            Int32 LengthClassId = Convert.ToInt32(LengthComboBox.SelectedValue);
            Int32 Qty = Convert.ToInt32(QtyTextBox.Text.Trim());
            Int32 Moq = Convert.ToInt32(MOQTextBox.Text.Trim());
            string Unit = UnitTextBox.Text.Trim();
            string HsCode = HsCodeTextBox.Text.Trim();
            DateTime AvailableDate = AvailableBox.Value;
            ProductModel productModel = null;
            int orderNum = dao.getMaxSortOrder(CategoryList);
            foreach (string path in pictureList)
            {
                if (path.IndexOf("data") == -1) continue;

                string model = Path.GetFileNameWithoutExtension(path);
                string image = path.Substring(path.IndexOf("data")).Replace("\\", "/");
                ImageModel imageModel = new ImageModel();
                imageModel.Image = image;

                bool IsSameModel = false;
                foreach (string key in productDic.Keys)
                {
                    if (key.StartsWith(model))
                    {
                        productModel = productDic[key];
                        productModel.Images.Add(imageModel);
                        productModel.Image = image;
                        productModel.Model = model;
                        productDic.Remove(key);
                        productDic.Add(model, productModel);
                        IsSameModel = true;
                        break;
                    }
                    if (model.StartsWith(key))
                    {
                        productModel = productDic[key];
                        productModel.Images.Add(imageModel);
                        IsSameModel = true;
                        break;
                    }
                }
                if (IsSameModel)
                {
                    continue;
                }
                productModel = new ProductModel();
                productModel.Images.Add(imageModel);
                productModel.Image = image;
                productModel.Model = model;
                productModel.LanguageId = Convert.ToInt32(SelectLang);
                productModel.Statust = 1;
                productModel.SortOrder = ++orderNum;
                productModel.ManufacturerId = ManufacturerId;
                productModel.StockStatusId = StockStatusId;
                productModel.WeightClassId = WeightClassId;
                productModel.LengthClassId = LengthClassId;
                productModel.Quantity = Qty;
                productModel.Minimum = Moq;
                productModel.Sku = Unit;
                productModel.Upc = HsCode;
                productModel.AvailableDate = AvailableDate;
                productModel.Name = GetNextProNameValue();
                productModel.MetaKeyword = GetNextKeywordValue();
                productModel.MetaDescription = productModel.Name + ", "
                    + productModel.Model + ", " + productModel.MetaKeyword;
                productModel.Description = productDesc;
                productModel.Description2 = productDesc2;
                productModel.Categories.AddRange(CategoryList);
                productModel.Tags.AddRange(TagList);
                productDic.Add(model, productModel);

                //dao.InsertProducts(productDic.Values.ToList());
            }
            MsgToolsLabel.Text = "";
            ImpBtn.Enabled = true;
            UpdBtn.Enabled = true;
            SubmitBtn.Enabled = true;
        }
Beispiel #2
0
 private void AddProductStore(ProductModel model, MySqlTransaction trans)
 {
     string sql = "insert into product_to_store(product_id, store_id)VALUES(@product_id, 0);";
         MySqlParameter[] parameter = new MySqlParameter[]
         {
             new MySqlParameter("@product_id",model.ProductId)
         };
         MySqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql, parameter);
 }
Beispiel #3
0
 private void AddProductTags(ProductModel model, MySqlTransaction trans)
 {
     string sql = "INSERT INTO `product_tag` (`product_id`, `language_id`, `tag`)VALUES(@product_id, @language_id, @tag);";
      List<TagModel> tagList = model.Tags;
      if (tagList != null)
      {
          foreach (TagModel tmodel in tagList)
          {
              MySqlParameter[] parameter = new MySqlParameter[]
             {
                 new MySqlParameter("@product_id",model.ProductId),
                 new MySqlParameter("@language_id",model.LanguageId),
                 new MySqlParameter("@tag",tmodel.Tag)
             };
             MySqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql, parameter);
          }
      }
 }
Beispiel #4
0
 private void AddProductRelateds(ProductModel model, MySqlTransaction trans)
 {
     string sql = "INSERT INTO `product_related` (`product_id`, `related_id`)VALUES(@product_id, @related_id);";
      List<RelatedModel> rList = model.Relateds;
      if (rList != null)
      {
          foreach (RelatedModel rmodel in rList)
          {
              MySqlParameter[] parameter = new MySqlParameter[]
             {
                 new MySqlParameter("@product_id",model.ProductId),
                 new MySqlParameter("@related_id",rmodel.RelatedId)
             };
              MySqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql, parameter);
          }
      }
 }
Beispiel #5
0
 private void AddProductImages(ProductModel model, MySqlTransaction trans)
 {
     string sql = "INSERT INTO `product_image` (`product_id`, `image`)VALUES( @product_id, @image);";
      List<ImageModel> imageList = model.Images;
      if (imageList != null)
      {
          foreach (ImageModel imodel in imageList)
          {
              MySqlParameter[] parameter = new MySqlParameter[]
             {
                 new MySqlParameter("@product_id",model.ProductId),
                 new MySqlParameter("@image",imodel.Image)
             };
             MySqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql, parameter);
          }
      }
 }
Beispiel #6
0
 private void AddProductDesc(ProductModel model, MySqlTransaction trans)
 {
     string sql = "INSERT INTO `product_description` (`product_id`, `language_id`, "
         +" `name`, `description`, `description2`, `meta_description`, `meta_keyword`)"
         +" VALUES(@product_id, @language_id, @name, "
         +" @description, @description2, @meta_description,@meta_keyword);";
     MySqlParameter[] parameter = new MySqlParameter[]
     {
         new MySqlParameter("@product_id",model.ProductId),
         new MySqlParameter("@language_id",model.LanguageId),
         new MySqlParameter("@name",model.Name),
         new MySqlParameter("@description",model.Description),
         new MySqlParameter("@description2",model.Description2),
         new MySqlParameter("@meta_description",model.MetaDescription),
         new MySqlParameter("@meta_keyword",model.MetaKeyword)
     };
     MySqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql, parameter);
 }
Beispiel #7
0
 private void AddProductCategories(ProductModel model, MySqlTransaction trans)
 {
     string sql = "INSERT INTO `product_to_category` (`product_id`, `category_id`)VALUES(@product_id, @category_id);";
     List<CategoryModel> CategoryList = model.Categories;
     if (CategoryList != null)
     {
         foreach (CategoryModel cmodel in CategoryList)
         {
             MySqlParameter[] parameter = new MySqlParameter[]
             {
                 new MySqlParameter("@product_id",model.ProductId),
                 new MySqlParameter("@category_id",cmodel.CategoryId)
             };
             MySqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql, parameter);
         }
     }
 }
Beispiel #8
0
 private ProductModel AddProduct(ProductModel model, MySqlTransaction trans)
 {
     string sql = "INSERT INTO `product` (`model`,`sku`,`upc`,`location`,`quantity`,`stock_status_id`,"
        +" `image`,`manufacturer_id`,`shipping`,`price`,`points`,`tax_class_id`,`date_available`,"
        +" `weight`,`weight_class_id`,`length`,`width`,`height`,`length_class_id`,`minimum`,`sort_order`,"
        +" `status`,`date_added`,`date_modified`)VALUES (@model,@sku,@upc,'',@quantity,"
        +" @stock_status_id,@image,@manufacturer_id,@shipping,@price,0, @tax_class_id,"
        +" @date_available,@weight,@weight_class_id,@length,@width,@height,@length_class_id,"
        +" @minimum,@sort_order,1,SYSDATE(),SYSDATE());";
     MySqlParameter[] parameter = new MySqlParameter[]
     {
         new MySqlParameter("@model",model.Model),
         new MySqlParameter("@sku",model.Sku),
         new MySqlParameter("@upc",model.Upc),
         new MySqlParameter("@quantity",model.Quantity),
         new MySqlParameter("@stock_status_id",model.StockStatusId),
         new MySqlParameter("@image",model.Image),
         new MySqlParameter("@manufacturer_id",model.ManufacturerId),
         new MySqlParameter("@shipping",model.shipping),
         new MySqlParameter("@price",model.Price),
         new MySqlParameter("@tax_class_id",model.TaxClassId),
         new MySqlParameter("@date_available",model.AvailableDate),
         new MySqlParameter("@weight",model.Weight),
         new MySqlParameter("@weight_class_id",model.WeightClassId),
         new MySqlParameter("@length",model.Length),
         new MySqlParameter("@width",model.Width),
         new MySqlParameter("@height",model.Height),
         new MySqlParameter("@length_class_id",model.LengthClassId),
         new MySqlParameter("@minimum",model.Minimum),
         new MySqlParameter("@sort_order",model.SortOrder)
     };
     MySqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql, parameter);
     model.ProductId = Convert.ToInt32(MySqlHelper.ExecuteScalar(@"select max(Product_id) from product", null));
     return model;
 }