예제 #1
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     M_pro.productName      = this.TextBox1.Text;
     M_pro.productUnitPrice = Convert.ToSingle(this.TextBox2.Text);
     M_pro.productCount     = Convert.ToInt32(this.TextBox3.Text);
     M_pro.productClassID   = Convert.ToInt32(this.DropDownList1.SelectedValue);
     M_pro.productContent   = this.TextBox4.Text;
     M_pro.msg   = content1.Value.Replace("'", "''");
     M_pro.ex1ID = this.TextBox5.Text;
     if (this.File1.Value != null && this.File1.Value != "")
     {
         ui.SaveSmallImg(Server.MapPath("~/Images/SmallImages") + "\\" + ui.GetFileName(this.File1), 145, 184, "Eshine", 14, this.File1);
         M_pro.productImg = ui.GetFileName(this.File1);
         ui.SaveUpFile(Server.MapPath("~/Images/BigImages") + "\\" + ui.GetFileName(this.File1), this.File1);
         //M_pro.productImg = ui.GetFileName(this.File1);
         B_pro.AddPro(M_pro);
         Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('添加成功');location='product_admin.aspx'</script>");
     }
     else
     {
         Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('添加失败')</script>");
     }
 }
예제 #2
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (this.TextBox21.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('请选择图片!');</script>");
            return;
        }

        StringBuilder strpic = new StringBuilder();

        if (this.TextBox22.Text != "")
        {
            strpic.Append(this.TextBox22.Text + ";");
        }
        if (this.TextBox23.Text != "")
        {
            strpic.Append(this.TextBox23.Text + ";");
        }
        if (this.TextBox24.Text != "")
        {
            strpic.Append(this.TextBox24.Text + ";");
        }
        if (this.TextBox25.Text != "")
        {
            strpic.Append(this.TextBox25.Text + ";");
        }
        if (strpic.Length > 0)
        {
            strpic.Remove(strpic.Length - 1, 1);
        }

        if (this.Button2.Text == "新增")
        {
            if (Session["language"] != null && Session["language"] == "zh-cn")
            {
                M_pro.productName        = this.TextBox1.Text;
                M_pro.productClassID     = 71;
                M_pro.productUnitPrice   = double.Parse(this.TextBox2.Text);
                M_pro.productMarketPrice = double.Parse(this.TextBox6.Text);
                M_pro.productCount       = int.Parse(this.TextBox3.Text);
                M_pro.productContent     = this.TextBox4.Text;
                M_pro.msg         = content1.Value.Replace("'", "''");
                M_pro.ikangName   = content2.Value.Replace("'", "''");
                M_pro.meinianName = content3.Value.Replace("'", "''");
                M_pro.cimingNmae  = content4.Value.Replace("'", "''");


                M_pro.ex1ID       = this.TextBox5.Text;
                M_pro.unit        = this.CheckBox1.Checked ? "发布" : "隐藏";
                M_pro.productImg  = this.TextBox21.Text;
                M_pro.ex1Name     = strpic.ToString();
                M_pro.downlimit   = this.TextBox26.Text;
                M_pro.type        = "商城";
                M_pro.productDate = DateTime.Now;
                M_pro.uplimit     = this.RadioButton1.Checked ? "快递实物" : "电子码";
                M_pro.px          = int.Parse(this.Label2.Text) + 1;
            }
            else
            {
                M_pro.productName_eng    = this.TextBox1.Text;
                M_pro.productClassID     = 71;
                M_pro.productUnitPrice   = double.Parse(this.TextBox2.Text);
                M_pro.productMarketPrice = double.Parse(this.TextBox6.Text);
                M_pro.productCount       = int.Parse(this.TextBox3.Text);
                M_pro.productContent_eng = this.TextBox4.Text;
                M_pro.msg_eng            = content1.Value.Replace("'", "''");
                M_pro.ikangName_eng      = content2.Value.Replace("'", "''");
                M_pro.meinianName_eng    = content3.Value.Replace("'", "''");
                M_pro.cimingName_eng     = content4.Value.Replace("'", "''");


                M_pro.ex1ID_eng      = this.TextBox5.Text;
                M_pro.unit           = this.CheckBox1.Checked ? "发布" : "隐藏";
                M_pro.productImg_eng = this.TextBox21.Text;
                M_pro.ex1Name_eng    = strpic.ToString();
                M_pro.downlimit_eng  = this.TextBox26.Text;
                M_pro.type           = "商城";
                M_pro.productDate    = DateTime.Now;
                M_pro.uplimit        = this.RadioButton1.Checked ? "快递实物" : "电子码";
                M_pro.px             = int.Parse(this.Label2.Text) + 1;
            }
            B_pro.AddPro(M_pro);
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('新增成功');location='product_admin.aspx'</script>");
        }
        else
        {
            StringBuilder str = new StringBuilder();
            if (Session["language"] != null && Session["language"].ToString() == "zh-cn")
            {
                str.Append("update tab_products set ");
                str.AppendFormat("productName=N'{0}',", this.TextBox1.Text);
                str.AppendFormat("productClassID={0},", this.DropDownList1.SelectedValue);
                str.AppendFormat("productUnitPrice={0},", this.TextBox2.Text);
                str.AppendFormat("productMarketPrice={0},", this.TextBox6.Text);
                str.AppendFormat("productCount={0},", this.TextBox3.Text);
                str.AppendFormat("productContent='{0}',", this.TextBox4.Text);
                str.AppendFormat("msg=N'{0}',", content1.Value.Replace("'", "''"));
                str.AppendFormat("ikangName=N'{0}',", content2.Value.Replace("'", "''"));
                str.AppendFormat("meinianName=N'{0}',", content3.Value.Replace("'", "''"));
                str.AppendFormat("cimingNmae=N'{0}',", content4.Value.Replace("'", "''"));


                str.AppendFormat("ex1ID=N'{0}',", this.TextBox5.Text);
                str.AppendFormat("unit=N'{0}',", this.CheckBox1.Checked ? "发布" : "隐藏");
                str.AppendFormat("productImg='{0}',", this.TextBox21.Text);
                str.AppendFormat("ex1Name=N'{0}',", strpic.ToString());
                str.AppendFormat("downlimit=N'{0}',", this.TextBox26.Text);
                str.AppendFormat("uplimit=N'{0}',", this.RadioButton1.Checked ? "快递实物" : "电子码");


                if (false && this.File1.Value != "" || this.File1.Value != string.Empty)
                {
                    ui.SaveSmallImg(Server.MapPath("~/Images/SmallImages") + "\\" + ui.GetFileName(this.File1), 65, 65, "mediplus", 14, this.File1);
                    str.AppendFormat("productImg='{0}',", ui.GetFileName(File1));
                    ui.SaveUpFile(Server.MapPath("~/Images/BigImages") + "\\" + ui.GetFileName(this.File1), this.File1);
                    //str.AppendFormat("productImg='{0}',", ui.GetFileName(File1));
                }
                str.Remove(str.Length - 1, 1);
                str.Append(" where productID=" + Convert.ToInt32(ViewState["proID"]));
            }
            else
            {
                str.Append("update tab_products set ");
                str.AppendFormat("productName_eng=N'{0}',", this.TextBox1.Text);
                str.AppendFormat("productClassID={0},", this.DropDownList1.SelectedValue);
                str.AppendFormat("productUnitPrice={0},", this.TextBox2.Text);
                str.AppendFormat("productMarketPrice={0},", this.TextBox6.Text);
                str.AppendFormat("productCount={0},", this.TextBox3.Text);
                str.AppendFormat("productContent_eng='{0}',", this.TextBox4.Text);
                str.AppendFormat("msg_eng=N'{0}',", content1.Value.Replace("'", "''"));
                str.AppendFormat("ikangName_eng=N'{0}',", content2.Value.Replace("'", "''"));
                str.AppendFormat("meinianName_eng=N'{0}',", content3.Value.Replace("'", "''"));
                str.AppendFormat("cimingName_eng=N'{0}',", content4.Value.Replace("'", "''"));


                str.AppendFormat("ex1ID_eng=N'{0}',", this.TextBox5.Text);
                str.AppendFormat("unit=N'{0}',", this.CheckBox1.Checked ? "发布" : "隐藏");
                str.AppendFormat("productImg_eng='{0}',", this.TextBox21.Text);
                str.AppendFormat("ex1Name_eng=N'{0}',", strpic.ToString());
                str.AppendFormat("downlimit_eng=N'{0}',", this.TextBox26.Text);
                str.AppendFormat("uplimit=N'{0}',", this.RadioButton1.Checked ? "快递实物" : "电子码");


                if (false && this.File1.Value != "" || this.File1.Value != string.Empty)
                {
                    ui.SaveSmallImg(Server.MapPath("~/Images/SmallImages") + "\\" + ui.GetFileName(this.File1), 65, 65, "mediplus", 14, this.File1);
                    str.AppendFormat("productImg='{0}',", ui.GetFileName(File1));
                    ui.SaveUpFile(Server.MapPath("~/Images/BigImages") + "\\" + ui.GetFileName(this.File1), this.File1);
                    //str.AppendFormat("productImg='{0}',", ui.GetFileName(File1));
                }
                str.Remove(str.Length - 1, 1);
                str.Append(" where productID=" + Convert.ToInt32(ViewState["proID"]));
            }
            //Response.Write(str.ToString());
            B_pro.UpdatePro(str.ToString());
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('更新成功');location='product_admin.aspx'</script>");
        }
    }
    protected void Button5_Click1(object sender, EventArgs e)
    {
        int successfulcount = 0, errorcount = 0;

        try
        {
            if (this.FileUpload1.HasFile)
            {
                if (!ue.SaveUpFile("~/Admin/temp/", this.FileUpload1))//上传文件
                {
                    throw new Exception("上传文件失败!");
                }

                DataTable inputdt = ue.InputExcel("Sheet1");
                if (inputdt == null)
                {
                    throw new Exception("Excel文件读取失败!");
                }

                int j;

                for (int i = 0; i < inputdt.Rows.Count; i++)
                {
                    j                           = 0;
                    products                    = new Model.tab_products();
                    products.productName        = inputdt.Rows[i][j++].ToString().Trim();
                    products.productClassID     = int.Parse(inputdt.Rows[i][j++].ToString());
                    products.ikangName          = inputdt.Rows[i][j++].ToString().Trim();
                    products.ikangID            = inputdt.Rows[i][j++].ToString().Trim();
                    products.meinianName        = inputdt.Rows[i][j++].ToString().Trim();
                    products.meinianID          = inputdt.Rows[i][j++].ToString().Trim();
                    products.cimingNmae         = inputdt.Rows[i][j++].ToString().Trim();
                    products.cimingID           = inputdt.Rows[i][j++].ToString().Trim();
                    products.ex1Name            = inputdt.Rows[i][j++].ToString().Trim();
                    products.ex1ID              = inputdt.Rows[i][j++].ToString().Trim();
                    products.type               = inputdt.Rows[i][j++].ToString().Trim();
                    products.unit               = inputdt.Rows[i][j++].ToString().Trim();
                    products.uplimit            = inputdt.Rows[i][j++].ToString().Trim();
                    products.downlimit          = inputdt.Rows[i][j++].ToString().Trim();
                    products.productUnitPrice   = inputdt.Rows[i][j++].ToString() == ""?0:double.Parse(inputdt.Rows[i][j++].ToString());
                    products.productMarketPrice = inputdt.Rows[i][j++].ToString() == ""?0: double.Parse(inputdt.Rows[i][j++].ToString());


                    try
                    {
                        if (bp.AddPro(products) < 1)
                        {
                            errorcount++;
                        }
                        else
                        {
                            successfulcount++;
                        }
                    }
                    catch
                    {
                        errorcount++;
                    }
                }
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('操作已完成!其中成功导入数据" + successfulcount + "条,失败" + errorcount + "条'); </script>");
                GridView1.DataBind();
            }
            else
            {
                throw new Exception("请选择Excel文件!");
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('" + ex.Message + "'); </script>");
        }
    }