public List<Maticsoft.Model.Shop.Products.ProductStationMode> DataTableToList(DataTable dt)
 {
     List<Maticsoft.Model.Shop.Products.ProductStationMode> list = new List<Maticsoft.Model.Shop.Products.ProductStationMode>();
     int count = dt.Rows.Count;
     if (count > 0)
     {
         for (int i = 0; i < count; i++)
         {
             Maticsoft.Model.Shop.Products.ProductStationMode item = new Maticsoft.Model.Shop.Products.ProductStationMode();
             if ((dt.Rows[i]["StationId"] != null) && (dt.Rows[i]["StationId"].ToString() != ""))
             {
                 item.StationId = int.Parse(dt.Rows[i]["StationId"].ToString());
             }
             if ((dt.Rows[i]["ProductId"] != null) && (dt.Rows[i]["ProductId"].ToString() != ""))
             {
                 item.ProductId = long.Parse(dt.Rows[i]["ProductId"].ToString());
             }
             if ((dt.Rows[i]["DisplaySequence"] != null) && (dt.Rows[i]["DisplaySequence"].ToString() != ""))
             {
                 item.DisplaySequence = int.Parse(dt.Rows[i]["DisplaySequence"].ToString());
             }
             if ((dt.Rows[i]["Type"] != null) && (dt.Rows[i]["Type"].ToString() != ""))
             {
                 item.Type = int.Parse(dt.Rows[i]["Type"].ToString());
             }
             list.Add(item);
         }
     }
     return list;
 }
Example #2
0
 private string InsertProductStationMode(HttpContext context)
 {
     JsonObject obj2 = new JsonObject();
     int productId = Convert.ToInt32(context.Request.Form["ProductId"]);
     int type = Convert.ToInt32(context.Request.Form["Type"]);
     if (this.productStationModeBLL.Exists(productId, type))
     {
         obj2.Put("STATUS", "Presence");
         return obj2.ToString();
     }
     Maticsoft.Model.Shop.Products.ProductStationMode model = new Maticsoft.Model.Shop.Products.ProductStationMode {
         ProductId = productId,
         DisplaySequence = (this.productStationModeBLL.GetRecordCount(string.Empty) == 0) ? 1 : (this.productStationModeBLL.GetRecordCount(string.Empty) + 1),
         Type = type
     };
     if (this.productStationModeBLL.Add(model) > 0)
     {
         obj2.Put("STATUS", "SUCCESS");
         obj2.Put("DATA", "Approve");
         return obj2.ToString();
     }
     obj2.Put("STATUS", "NODATA");
     return obj2.ToString();
 }
 public Maticsoft.Model.Shop.Products.ProductStationMode GetModel(int StationId)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("SELECT  TOP 1 StationId,ProductId,DisplaySequence,Type FROM Shop_ProductStationModes ");
     builder.Append(" WHERE StationId=@StationId");
     SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@StationId", SqlDbType.Int, 4) };
     cmdParms[0].Value = StationId;
     Maticsoft.Model.Shop.Products.ProductStationMode mode = new Maticsoft.Model.Shop.Products.ProductStationMode();
     DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
     if (set.Tables[0].Rows.Count <= 0)
     {
         return null;
     }
     if ((set.Tables[0].Rows[0]["StationId"] != null) && (set.Tables[0].Rows[0]["StationId"].ToString() != ""))
     {
         mode.StationId = int.Parse(set.Tables[0].Rows[0]["StationId"].ToString());
     }
     if ((set.Tables[0].Rows[0]["ProductId"] != null) && (set.Tables[0].Rows[0]["ProductId"].ToString() != ""))
     {
         mode.ProductId = long.Parse(set.Tables[0].Rows[0]["ProductId"].ToString());
     }
     if ((set.Tables[0].Rows[0]["DisplaySequence"] != null) && (set.Tables[0].Rows[0]["DisplaySequence"].ToString() != ""))
     {
         mode.DisplaySequence = int.Parse(set.Tables[0].Rows[0]["DisplaySequence"].ToString());
     }
     if ((set.Tables[0].Rows[0]["Type"] != null) && (set.Tables[0].Rows[0]["Type"].ToString() != ""))
     {
         mode.Type = int.Parse(set.Tables[0].Rows[0]["Type"].ToString());
     }
     return mode;
 }
 protected void ButUpload_Click(object sender, EventArgs e)
 {
     try
     {
         if ((this.FileUploadProducts.PostedFile != null) && (this.FileUploadProducts.PostedFile.ContentLength > 0))
         {
             string str = Path.GetExtension(this.FileUploadProducts.PostedFile.FileName).ToLower();
             ".csv".IndexOf(str);
             if ((!this.CheckBox1.Checked && !this.CheckBox2.Checked) && (!this.CheckBox3.Checked && !this.CheckBox4.Checked))
             {
                 MessageBox.ShowFailTip(this, "请至少选择一种商品推荐方式!");
             }
             else
             {
                 int num = Convert.ToInt32((this.ProductsBatchUploadDropList.SelectedValue == this.dropItem0Value) ? "-1" : this.ProductsBatchUploadDropList.SelectedValue);
                 int num2 = Convert.ToInt32((this.dropProductTypes.SelectedValue == this.dropItem0Value) ? "-1" : this.dropProductTypes.SelectedValue);
                 int num3 = Convert.ToInt32((this.dropBrands.SelectedValue == this.dropItem0Value) ? "-1" : this.dropBrands.SelectedValue);
                 int num4 = Convert.ToInt32((this.dropEnterprise.SelectedValue == this.dropItem0Value) ? "-1" : this.dropEnterprise.SelectedValue);
                 string str2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
                 OleDbConnection selectConnection = new OleDbConnection(str2 + this.FileUploadProducts.PostedFile.FileName.Replace(this.FileUploadProducts.FileName, string.Empty) + ";Extended Properties=\"text;HDR=Yes;FMT=Delimited\"");
                 DataSet dataSet = new DataSet();
                 new OleDbDataAdapter("select * from " + this.FileUploadProducts.FileName, selectConnection).Fill(dataSet);
                 selectConnection.Close();
                 int num5 = 0;
                 Maticsoft.Model.Shop.Products.ProductInfo model = new Maticsoft.Model.Shop.Products.ProductInfo();
                 Maticsoft.BLL.Shop.Products.ProductInfo info2 = new Maticsoft.BLL.Shop.Products.ProductInfo();
                 for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                 {
                     model.CategoryId = num;
                     model.TypeId = new int?(num2);
                     model.BrandId = num3;
                     model.SupplierId = num4;
                     model.SaleStatus = this.CheckBoxSaleStatus.Checked ? 1 : 0;
                     model.ProductName = dataSet.Tables[0].Rows[i]["商品名称"].ToString();
                     model.Description = dataSet.Tables[0].Rows[i]["简单介绍"].ToString();
                     model.AddedDate = Convert.ToDateTime(dataSet.Tables[0].Rows[i]["添加时间"]);
                     model.ImageUrl = dataSet.Tables[0].Rows[i]["清晰图"].ToString();
                     model.MarketPrice = new decimal?(Convert.ToDecimal(dataSet.Tables[0].Rows[i]["市场价"].ToString()));
                     model.LineId = 1;
                     int num7 = Convert.ToInt32(info2.Add(model));
                     if (num7 != 0)
                     {
                         Maticsoft.Model.Shop.Products.ProductStationMode mode = new Maticsoft.Model.Shop.Products.ProductStationMode();
                         Maticsoft.BLL.Shop.Products.ProductStationMode mode2 = new Maticsoft.BLL.Shop.Products.ProductStationMode();
                         int num8 = 0;
                         for (int j = 1; j <= 4; j++)
                         {
                             CheckBox box = (CheckBox) this.divCheckBox.FindControl("CheckBox" + j);
                             if (box.Checked)
                             {
                                 mode.ProductId = num7;
                                 mode.DisplaySequence = mode2.GetRecordCount(" ProductId = " + num7) + 1;
                                 mode.Type = Convert.ToInt32(box.SkinID);
                                 if (mode2.Add(mode) != 0)
                                 {
                                     num8 = 1;
                                 }
                             }
                         }
                         if (num8 == 1)
                         {
                             num8 = 0;
                             num5++;
                         }
                     }
                 }
                 if (num5 > 0)
                 {
                     MessageBox.ShowAndBack(this, "已成功导入 " + num5.ToString() + " 个商品!");
                 }
                 else
                 {
                     MessageBox.ShowFailTip(this, "导入失败!");
                 }
             }
         }
         else
         {
             MessageBox.ShowFailTip(this, "请选择上传文件!");
         }
     }
     catch (Exception exception)
     {
         MessageBox.ShowFailTip(this, exception.Message);
     }
 }