Exemple #1
0
        private DataTable Search(string name, string 厂家, ProductType type)
        {
            string nm = "";

            if (!string.IsNullOrEmpty(name))
            {
                nm = " and 品名 like '%" + name + "%'";
            }

            string cj = "";

            if (!string.IsNullOrEmpty(厂家))
            {
                cj = " and 厂家 like '%" + 厂家 + "%'";
            }

            string ty = "";

            if (type != null)
            {
                cj = " and 种类='" + type.类型 + "'";
            }

            string where = "(1=1)" + nm + cj + ty;
            return(ProductLogic.GetInstance().GetProducts(where));
        }
Exemple #2
0
 private void LoadProducts()
 {
     List<Product> ps = ProductLogic.GetInstance().GetAllProducts();
     comboBox1.Items.Clear();
     foreach (Product p in ps)
     {
         comboBox1.Items.Add(p);
     }
 }
Exemple #3
0
        public static ProductLogic GetInstance()
        {
            if (instance == null)
            {
                instance = new ProductLogic();
            }

            return(instance);
        }
Exemple #4
0
        private void LoadProducts()
        {
            List <Product> elements = ProductLogic.GetInstance().GetAllProducts();

            comboBox1.Items.Clear();
            foreach (Product element in elements)
            {
                comboBox1.Items.Add(element);
            }
        }
Exemple #5
0
        private void LoadProducts()
        {
            List <Product> elements = ProductLogic.GetInstance().GetAllProducts();

            comboBox1.Items.Clear();
            foreach (Product element in elements)
            {
                comboBox1.Items.Add(element);
            }
            dataGridView1.DataSource = ProductLogic.GetInstance().GetProducts(string.Empty);
        }
Exemple #6
0
 private DataTable Search(string name, string 厂家 = null)
 {
     if (!string.IsNullOrEmpty(name))
     {
         string cj = "";
         if (!string.IsNullOrEmpty(厂家))
         {
             cj = " and 厂家 like '%" + 厂家 + "%'";
         }
         string where = "品名 like '%" + name + "%'" + cj + " order by ID desc";
         return(ProductLogic.GetInstance().GetProducts(where));
     }
     return(null);
 }
Exemple #7
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         if (MessageBox.Show("确定要删除该产品?", "删除提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         {
             Product product = (Product)comboBox1.SelectedItem;
             if (ProductLogic.GetInstance().DeleteProduct(product))
             {
                 LoadProducts();
             }
         }
     }
     else
     {
         MessageBox.Show("先选定要删除的产品!");
     }
 }
Exemple #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            string  jj = textBox3.Text.Trim();
            string  sj = textBox4.Text.Trim();
            decimal JJ = 0;
            decimal SJ = 0;
            decimal d  = 0;

            if (string.IsNullOrEmpty(jj) || !decimal.TryParse(jj, out d))
            {
                MessageBox.Show("进价必须为数字!");
                textBox3.Focus();
                textBox3.SelectAll();
            }
            JJ = d;
            if (string.IsNullOrEmpty(sj) || !decimal.TryParse(sj, out d))
            {
                MessageBox.Show("售价必须为数字!");
                textBox4.Focus();
                textBox4.SelectAll();
            }
            SJ = d;
            Product product = new Product();

            product.品名 = textBox1.Text.Trim();
            product.单位 = textBox2.Text.Trim();
            product.进价 = JJ;
            product.售价 = SJ;
            product.厂家 = textBox5.Text.Trim();
            product.姓名 = textBox6.Text.Trim();
            product.电话 = textBox7.Text.Trim();
            product.地址 = textBox10.Text.Trim();
            product.备注 = textBox11.Text.Trim();
            ProductLogic pl = ProductLogic.GetInstance();

            if (pl.ExistsName(product.品名))
            {
                if (MessageBox.Show("系统中已经存在该品名,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    int id = pl.AddProduct(product);
                    if (id > 0)
                    {
                        product.ID = id;
                        LoadProducts();
                        MessageBox.Show("添加成功!");
                    }
                }
                else
                {
                    textBox1.Focus();
                    textBox1.SelectAll();
                }
            }
            else
            {
                int id = pl.AddProduct(product);
                if (id > 0)
                {
                    product.ID = id;
                    LoadProducts();
                    MessageBox.Show("添加成功!");
                }
            }
        }
Exemple #9
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         if (comboBox2.SelectedIndex == -1)
         {
             MessageBox.Show("请选择产品的种类!如若没有种类可选,请先维护好产品种类!");
             comboBox2.Focus();
             return;
         }
         string  jj = textBox3.Text.Trim();
         string  sj = textBox4.Text.Trim();
         decimal JJ = 0;
         decimal SJ = 0;
         decimal d  = 0;
         if (string.IsNullOrEmpty(jj) || !decimal.TryParse(jj, out d))
         {
             MessageBox.Show("进价必须为数字!");
             textBox3.Focus();
             textBox3.SelectAll();
             return;
         }
         JJ = d;
         if (string.IsNullOrEmpty(sj) || !decimal.TryParse(sj, out d))
         {
             MessageBox.Show("售价必须为数字!");
             textBox4.Focus();
             textBox4.SelectAll();
             return;
         }
         SJ = d;
         Product product = (Product)comboBox1.SelectedItem;
         product.品名 = textBox1.Text.Trim();
         product.种类 = comboBox2.SelectedItem as ProductType;
         product.单位 = textBox2.Text.Trim();
         product.进价 = JJ;
         product.售价 = SJ;
         product.厂家 = textBox5.Text.Trim();
         product.姓名 = textBox6.Text.Trim();
         product.电话 = textBox7.Text.Trim();
         product.地址 = textBox10.Text.Trim();
         product.备注 = textBox11.Text.Trim();
         ProductLogic pl = ProductLogic.GetInstance();
         if (pl.ExistsNameOther(product.品名, product.ID))
         {
             if (MessageBox.Show("系统中已经存在该品名,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
             {
                 if (pl.UpdateProduct(product))
                 {
                     LoadProducts();
                     MessageBox.Show("修改成功!");
                 }
             }
             else
             {
                 textBox1.Focus();
                 textBox1.SelectAll();
             }
         }
         else
         {
             if (pl.UpdateProduct(product))
             {
                 LoadProducts();
                 MessageBox.Show("修改成功!");
             }
         }
     }
     else
     {
         MessageBox.Show("先选定要修改的产品!");
     }
 }