/// <summary>
 /// 添加到商品库的方法,供给添加商品还有更新商品用的
 /// </summary>
 public void insertcommdity()// 添加到商品库的方法
 {
     #region  层架构插入商品数据
     commodity c = new commodity();
     c.Comid        = int.Parse(txt_comid.Text);
     c.Username     = love.denglu_username == string.Empty ? "a" : love.denglu_username;//如果这个是空的话说明这个是在软件的测试阶段,不是空的话说明它是通过了登陆键来赋值的
     c.Name         = txt_name.Text;
     c.Shoujia      = int.Parse(txt_shoujia.Text);
     c.Kuadi        = cmb_wuliugongsi.Text;
     c.Kucun        = int.Parse(txt_kucun.Text);
     c.Isbaoyou     = ckb_isbaoyou.Checked ? "是" : "否";
     c.Yuexiaoliang = int.Parse(num_yuexiaoliang.Value.ToString());
     //c.Adddatetime    自动使用日期时间
     c.Scd = txt_scd.Text;
     #region c.Isorcolor赋值  判断是否选择了有颜色pannel,并且有颜色chekbox被选中了,然后才赋值
     int colorcount = 0;
     foreach (Control item in pan_iscolor.Controls)
     {
         if (item is CheckBox)
         {
             CheckBox ck = (CheckBox)item;
             if (ck.Checked)
             {
                 colorcount++;
             }
         }
     }
     if (ckb_isorcolor.Checked && colorcount != 0)
     {
         c.Isorcolor = "有";
     }
     else
     {
         c.Isorcolor = "无";
     }
     #endregion
     #region c.Isororther赋值   判断是否选择了有其它pannel,并且有其它色chekbox被选中了,然后才赋值
     int orthercount = 0;
     foreach (var item in list_orther.Items)
     {
         if (item.ToString().Trim() != string.Empty)
         {
             orthercount++;
         }
     }
     if (ckb_isororther.Checked && orthercount != 0)
     {
         c.Isororther = "有";
     }
     else
     {
         c.Isororther = "无";
     }
     #endregion
     c.Xiangxi = txt_xiangxi.Text == "这里键入你的产品介绍,或者你想对买家说的话。" ? "" : txt_xiangxi.Text;
     c.Picda   = sqlHelper.tiqupic(pic_daico, Application.StartupPath + @"\image\a.jpg");
     c.Pic1    = sqlHelper.tiqupic(pic_xiao1, Application.StartupPath + @"\image\a.jpg");
     c.Pic2    = sqlHelper.tiqupic(pic_xiao2, Application.StartupPath + @"\image\a.jpg");
     c.Pic3    = sqlHelper.tiqupic(pic_xiao3, Application.StartupPath + @"\image\a.jpg");
     c.addcommodity();//执行业务层插入的方法
     #region 循环添加颜色
     if (c.Isorcolor == "有")
     {
         commditycolor.Clear();//首先清除颜色的集合
         foreach (Control item in pan_iscolor.Controls)
         {
             if (item is CheckBox)
             {
                 CheckBox ck = (CheckBox)item;
                 if (ck.Checked)
                 {
                     commditycolor.Add(ck.Text);
                 }
             }
         }
         foreach (var item in commditycolor)
         {
             comcolor co = new comcolor();
             co.Comid = int.Parse(txt_comid.Text);
             co.Color = item.ToString();
             co.insertcolor();//执行插入
         }
     }
     #endregion
     #region 循环添加其它
     if (c.Isororther == "有")
     {
         commdityorther.Clear();
         foreach (var item in list_orther.Items)
         {
             if (item.ToString().Trim() != string.Empty)
             {
                 commdityorther.Add(item.ToString().Trim());
             }
         }
         foreach (var item in commdityorther)
         {
             comorther ct = new comorther();
             ct.Comid  = int.Parse(txt_comid.Text);
             ct.Orther = item;
             ct.insertorther();
         }
     }
     #endregion
     #endregion
 }
Beispiel #2
0
        public void updatecommodity()// 修改商品的方法
        {
            commodity c = new commodity();

            c.Kucun       = int.Parse(txt_kucun.Text);
            c.Name        = txt_name.Text;
            c.Shoujia     = decimal.Parse(txt_shoujia.Text);
            c.Scd         = txt_scd.Text;
            c.Kuadi       = cmb_wuliugongsi.Text;
            c.Adddatetime = dtp_adddatetime.Value;
            c.Isbaoyou    = ckb_isbaoyou.Checked ? "是" : "否";
            c.Picda       = sqlHelper.tiqupic(pic_daico, Application.StartupPath + "\\asdf.jpg");
            c.Pic1        = sqlHelper.tiqupic(pic_xiao1, Application.StartupPath + "\\asdf.jpg");
            c.Pic2        = sqlHelper.tiqupic(pic_xiao2, Application.StartupPath + "\\asdf.jpg");
            c.Pic3        = sqlHelper.tiqupic(pic_xiao3, Application.StartupPath + "\\asdf.jpg");
            c.Comid       = int.Parse(dangqianid);
            c.Xiangxi     = txt_xiangxi.Text == "这里键入你的产品介绍,或者你想对买家说的话。" ? "" : txt_xiangxi.Text;

            #region c.Isorcolor赋值  判断是否选择了有颜色pannel,并且有颜色chekbox被选中了,然后才赋值
            int colorcount = 0;
            foreach (Control item in pan_iscolor.Controls)
            {
                if (item is CheckBox)
                {
                    CheckBox ck = (CheckBox)item;
                    if (ck.Checked)
                    {
                        colorcount++;
                    }
                }
            }
            if (ckb_isorcolor.Checked && colorcount != 0)
            {
                c.Isorcolor = "有";
            }
            else
            {
                c.Isorcolor = "无";
            }
            #endregion

            #region c.Isororther赋值   判断是否选择了有其它pannel,并且有其它色chekbox被选中了,然后才赋值
            int orthercount = 0;
            foreach (var item in list_orther.Items)
            {
                if (item.ToString().Trim() != string.Empty)
                {
                    orthercount++;
                }
            }
            //判断是否写的是没有任何属性
            string ss = string.Empty;//循环判断是否是没有添加任何属性如果是的话就要赋值无
            foreach (var item in list_orther.Items)
            {
                if (item.ToString().Trim() != string.Empty)
                {
                    ss += item.ToString().Trim();
                }
            }
            //必须要选择了有其它并且在数量不等于1的情况下值不为 没有任何属性
            if ((ckb_isororther.Checked && orthercount != 0) && ss != "没有任何属性")
            {
                c.Isororther = "有";
            }
            else
            {
                c.Isororther = "无";
            }

            c.IsXiangXiupdate();
            #endregion

            #region 循环添加颜色
            if (c.Isorcolor == "有")
            {
                //首先删除所有颜色,然后再插入
                string sqldecolor = "delete comcolor where comid = " + dangqianid;//先删除颜色
                sqlHelper.ExecuteCommand(sqldecolor, CommandType.Text, null);

                commditycolor.Clear();//首先清除颜色的集合
                foreach (Control item in pan_iscolor.Controls)
                {
                    if (item is CheckBox)
                    {
                        CheckBox ck = (CheckBox)item;
                        if (ck.Checked)
                        {
                            commditycolor.Add(ck.Text);
                        }
                    }
                }
                foreach (var item in commditycolor)
                {
                    comcolor co = new comcolor();
                    co.Comid = int.Parse(dangqianid);
                    co.Color = item.ToString();
                    co.insertcolor();//执行插入
                }
            }
            else
            {
                //既然没有颜色那么就要删除掉数据库中的所有颜色
                string sqldecolor = "delete comcolor where comid = " + dangqianid;//先删除颜色
                sqlHelper.ExecuteCommand(sqldecolor, CommandType.Text, null);
            }

            #endregion
            #region 循环添加其它
            if (c.Isororther == "有")
            {
                //首先删除所有其它,然后再插入
                string sqldeorhter = "delete comorther where comid = " + dangqianid;//再删除其它
                sqlHelper.ExecuteCommand(sqldeorhter, CommandType.Text, null);

                commdityorther.Clear();
                foreach (var item in list_orther.Items)
                {
                    if (item.ToString().Trim() != string.Empty)
                    {
                        commdityorther.Add(item.ToString().Trim());
                    }
                }
                foreach (var item in commdityorther)
                {
                    comorther ct = new comorther();
                    ct.Comid  = int.Parse(dangqianid);
                    ct.Orther = item;
                    ct.insertorther();
                }
            }
            else
            {
                //既然没有其它那么就要把其它从数据库中清空
                string sqldeorhter = "delete comorther where comid = " + dangqianid;//再删除其它
                sqlHelper.ExecuteCommand(sqldeorhter, CommandType.Text, null);
            }
            #endregion
        }