Example #1
0
 //InsertProduct
 private void button12_Click(object sender, EventArgs e)
 {
     textBox1.Text = "Product";
     Product product = new Product();
     product.Id = 2;
     product.ProductSn = "Product test" + System.DateTime.Now.ToString();
     product.ProductName = "������";
     product.Remark = "ûʲô��д��";
     MessageBox.Show(dba.InsertProductFull(product));
 }
 public ProductInventoryEntry(Product product, int quantity)
 {
     try
     {
         Name = product.Name;
         Price = product.Price;
         Cost = product.Cost;
         Quantity = quantity;
     }
     catch (ArgumentNullException)
     {
         Debug.WriteLine("ERROR: Invalid arguments to construct ProductInventoryEntry");
     }
 }
 //У���Ƿ��в�Ʒ����һ���ģ� true-ͨ�����ԣ�û�����Ƶ�,false-û��ͨ�����ԣ������Ƶ�
 public bool CheckProduct(Product product)
 {
     command.CommandText = "SELECT * FROM Product where ProductSn = '" + product.ProductSn + "'";
     SQLiteDataAdapter da = new SQLiteDataAdapter(command);
     DataTable dt = new DataTable("Product");
     da.Fill(dt);
     if (dt.Rows.Count > 0)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
Example #4
0
 //SelectProduct
 private void button13_Click_1(object sender, EventArgs e)
 {
     textBox1.Text = "Product";
     Product product = new Product();
     product.Id = 2;
     product.ProductSn = "Product test" + System.DateTime.Now.ToString();
     product.ProductName = "������";
     product.Remark = "ûʲô��д��";
     //MessageBox.Show(product.ToString());
     MessageBox.Show(dba.SelectProduct(product).Rows[0][0].ToString());
     MessageBox.Show(dba.SelectProductToClass(product).ToString());
     List<Product> listProduct = new List<Product>();
     listProduct = dba.SelectProductAllToList();
     for (int i = 0; i < listProduct.Count; i++)
     {
         MessageBox.Show(listProduct[i].ToString());
     }
 }
 //���²�Ʒ
 public string UpdateProduct(Product product)
 {
     DataTable dt = new DataTable();
     dt = SelectProduct(product);
     if (dt.Rows.Count == 1)
     {
         dt.Rows[0][0] = product.Id;
         dt.Rows[0][1] = product.ProductSn;
         dt.Rows[0][2] = product.ProductName;
         dt.Rows[0][3] = product.Remark;
         dt.Rows[0][4] = product.UnitPerBox;
     }
     return UpdateTable(dt, "Product");
 }
        //��ѯij����Ʒ��Ϣ
        public Product SelectProductToClass(Product product)
        {
            command.CommandText = "SELECT * FROM Product where Id = '" + product.Id + "'";
            SQLiteDataAdapter da = new SQLiteDataAdapter(command);
            DataTable dt = new DataTable("Product");
            da.Fill(dt);

            Product returnvalue = new Product();
            if (dt.Rows.Count > 0)
            {
                returnvalue.Id = Convert.ToInt16(dt.Rows[0][0].ToString());
                returnvalue.ProductSn = dt.Rows[0][1].ToString();
                returnvalue.ProductName = dt.Rows[0][2].ToString();
                returnvalue.Remark = dt.Rows[0][3].ToString();
                returnvalue.UnitPerBox = Convert.ToInt16(dt.Rows[0][4].ToString());
            }
            return returnvalue;
        }
 //��ѯ�����в�Ʒ
 public List<Product> SelectProductAllToList()
 {
     List<Product> listproduct = new List<Product>();
     DataTable dt = new DataTable();
     dt = ReadTableOrderByXXId("Product", "ProductSn");
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         Product returnvalue = new Product();
         returnvalue.Id = Convert.ToInt16(dt.Rows[i][0].ToString());
         returnvalue.ProductSn = dt.Rows[i][1].ToString();
         returnvalue.ProductName = dt.Rows[i][2].ToString();
         returnvalue.Remark = dt.Rows[i][3].ToString();
         returnvalue.UnitPerBox = Convert.ToInt16(dt.Rows[i][4].ToString());
         listproduct.Add(returnvalue);
     }
     return listproduct;
 }
 //��ѯij����Ʒ��Ϣ
 public DataTable SelectProduct(Product product)
 {
     command.CommandText = "SELECT * FROM Product where Id = '" + product.Id + "'";
     SQLiteDataAdapter da = new SQLiteDataAdapter(command);
     DataTable dt = new DataTable("Product");
     da.Fill(dt);
     return dt;
 }
        //�������
        public string InsertStocks()
        {
            command.CommandText = "SELECT max(Id) FROM Product";
            SQLiteDataAdapter da = new SQLiteDataAdapter(command);
            DataTable dtMaxId = new DataTable();
            da.Fill(dtMaxId);
            int productid;
            Product productmax = new Product();

            if(dtMaxId.Rows.Count>0)
            {
                productid = Convert.ToInt16(dtMaxId.Rows[0][0].ToString());
                productmax.Id = productid;
                productmax = SelectProductToClass(productmax);
            }
            else
            {
                productid = 1;
            }

            DataTable dt = new DataTable();
            dt = CreateDataTable("Stocks");
            DataRow datarow;
            datarow = dt.NewRow();
            datarow[0] = productmax.Id;
            datarow[1] = 0;
            datarow[2] = 0;
            datarow[3] = DateTime.Now;
            datarow[4] = productmax.ProductSn;
            datarow[5] = productmax.ProductName;
            dt.Rows.Add(datarow);
            return UpdateTable(dt, "Stocks");
        }
 //������Ʒ�����ڿ�����Ҳ����һ��
 public string InsertProductFull(Product product)
 {
     string returnflag = InsertProduct(product);
     if (returnflag == "success")
     {
         return InsertStocks();
     }
     else
     {
         return returnflag;
     }
 }
 //������Ʒ
 public string InsertProduct(Product product)
 {
     DataTable dt = new DataTable();
     dt = CreateDataTable("Product");
     DataRow datarow;
     datarow = dt.NewRow();
     datarow[0] = product.Id;
     datarow[1] = product.ProductSn;
     datarow[2] = product.ProductName;
     datarow[3] = product.Remark;
     datarow[4] = product.UnitPerBox;
     dt.Rows.Add(datarow);
     return UpdateTable(dt, "Product");
 }