コード例 #1
0
        public static List <ProductMoving> LoadProductMovingFromSql()
        {
            List <ProductMoving> listProductsMoving = new List <ProductMoving>();

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                string     sql = @"select * from ProductsMoving";
                SqlCommand com = new SqlCommand(sql, conn);
                using (SqlDataReader rdr = com.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        ProductMoving pr = new ProductMoving();
                        pr.ID         = Int32.Parse(rdr[0].ToString());
                        pr.IDproduct  = Int32.Parse(rdr[1].ToString());
                        pr.CountStore = double.Parse(rdr[2].ToString());
                        pr.CountShop  = double.Parse(rdr[3].ToString());
                        pr.Sold       = double.Parse(rdr[4].ToString());
                        listProductsMoving.Add(pr);
                    }
                }
            }
            return(listProductsMoving);
        }
コード例 #2
0
 public static void SaveProductMovingToXML(ProductMoving product)
 {
     LoadProductMovingFromXML();
     if (ProductsMoving.Any(it => it.ID == product.ID))
     {
         ProductsMoving.First(it => it.ID == product.ID).IDproduct  = product.IDproduct;
         ProductsMoving.First(it => it.ID == product.ID).CountStore = product.CountStore;
         ProductsMoving.First(it => it.ID == product.ID).CountShop  = product.CountShop;
         ProductsMoving.First(it => it.ID == product.ID).Sold       = product.Sold;
     }
     else
     {
         product.ID = ProductsMoving.Last().ID + 1;
         ProductsMoving.Add(product);
     }
     try
     {
         var xmlReader = new XmlSerializer(typeof(List <ProductMoving>));
         using (var stream = File.Create(PathFileProductsMoving))
         {
             xmlReader.Serialize(stream, ProductsMoving);
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Ошибка записи списка пользователей", "ошибка", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
コード例 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.Text == "" || comboBox2.Text == "")
     {
         MessageBox.Show("Вы не заполнили некоторые поля", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return;
     }
     // it need to check name
     Products       = BridgeToBD.LoadProductShopFromDB(TypeBD.SQL);
     ProductsMoving = BridgeToBD.LoadProductMovingFromDB(TypeBD.SQL);
     if (!Products.Any(it => it.Name == textBox3.Text))
     {
         ProductShop pr = new ProductShop();
         pr.ID        = Products.Last().ID + 1;
         pr.Name      = textBox3.Text;
         pr.PriceSell = (float)Convert.ToDouble(textBox5.Text);
         pr.PriceBuy  = (float)Convert.ToDouble(textBox4.Text);
         pr.UoM       = (UoM)Enum.Parse(typeof(UoM), comboBox1.Text);
         ProductMoving prmove = new ProductMoving();
         prmove.IDproduct = pr.ID;
         prmove.Sold      = 0;
         if (comboBox2.Text == "Warehouse")
         {
             prmove.CountStore = Convert.ToDouble(textBox6.Text);
         }
         else if (comboBox2.Text == "Shop")
         {
             prmove.CountShop = Convert.ToDouble(textBox6.Text);
         }
         else
         {
             MessageBox.Show("Некорректно выбран склад");
         }
         Products.Add(pr);
         ProductsMoving.Add(prmove);
         //HelperProduct.SaveUsersFromFile(Products);
         // this.Update(); // it doesn't work
         //HelperProduct.InsertToSql(pr);
         BridgeToBD.SaveProductShopToBD(Products, TypeBD.SQL);
         BridgeToBD.SaveProductMovingToSQL(ProductsMoving);
         dataGridView1ReLoad();
     }
     else
     {
         MessageBox.Show("Товар с таким именем уже есть на складе");
     }
 }
コード例 #4
0
 public static void SaveProductMovingToSQL(ProductMoving prodmoving)
 {
     using (var conn = new SqlConnection(ConnectionString))
     {
         LoadProductMovingFromSql();
         conn.Open();
         SqlCommand comm = conn.CreateCommand();
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.Add("@id", SqlDbType.Int).Value              = prodmoving.ID;
         comm.Parameters.Add("@id_product", SqlDbType.Int).Value      = prodmoving.IDproduct;
         comm.Parameters.Add("@count_store", SqlDbType.Decimal).Value = prodmoving.CountStore;
         comm.Parameters.Add("@count_shop", SqlDbType.Decimal).Value  = prodmoving.CountShop;
         comm.Parameters.Add("@sold", SqlDbType.Decimal).Value        = prodmoving.Sold;
         comm.CommandText = (ProductsMoving.Any(it => it.ID == prodmoving.ID)) ? "ai_update_products_moving" : "ai_insert_products_moving";
         comm.ExecuteNonQuery();
     }
 }
コード例 #5
0
 public static void SaveProductMovingToEntity(ProductMoving prMove)
 {
     LoadProductMovingFromEntity();
     EntityLibrary.ProductsMoving prodMove = new EntityLibrary.ProductsMoving();
     prodMove.id         = prMove.ID;
     prodMove.idProduct  = prMove.IDproduct;
     prodMove.CountStore = (decimal)prMove.CountStore;
     prodMove.CountShop  = (decimal)prMove.CountShop;
     prodMove.Sold       = (decimal)prMove.Sold;
     if (ProductsMoving.Any(it => it.ID == prMove.ID))
     {
         UpdateProductsMovingToEntity(prodMove);
     }
     else
     {
         InsertProductsMovingToEntity(prodMove);
     }
 }
コード例 #6
0
        public static void SaveProductMovingToBD(ProductMoving prMove, TypeBD typeBD)
        {
            switch (typeBD)
            {
            case TypeBD.XML:
                SaveProductMovingToXML(prMove);
                break;

            case TypeBD.SQL:
                SaveProductMovingToSQL(prMove);
                break;

            case TypeBD.Entity:
                SaveProductMovingToEntity(prMove);
                break;

            default:
                MessageBox.Show("ERROR typeBD");
                break;
            }
        }
コード例 #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == string.Empty)
            {
                MessageBox.Show("Вы не заполнили поле 'Название товара'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (comboBox1.Text == string.Empty)
            {
                MessageBox.Show("Вы не заполнили поле 'Единицы измерения'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (textBox4.Text == "")
            {
                MessageBox.Show("Вы не заполнили поле 'Цена закупки'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (textBox5.Text == "")
            {
                MessageBox.Show("Вы не заполнили поле 'Цена продажи'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (textBox6.Text == "")
            {
                MessageBox.Show("Вы не заполнили поле 'Количество товара'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (comboBox2.Text == "")
            {
                MessageBox.Show("Вы не заполнили поле 'Склад'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            BridgeToBD.LoadProductShopFromDB(BridgeToBD.ChoiceBD);
            if (!BridgeToBD.Products.Any(it => it.Name == textBox3.Text))
            {
                ProductShop pr = new ProductShop();
                pr.Name      = textBox3.Text;
                pr.PriceSell = (float)Convert.ToDouble(textBox5.Text);
                pr.PriceBuy  = (float)Convert.ToDouble(textBox4.Text);
                pr.UoM       = (UoM)Enum.Parse(typeof(UoM), comboBox1.Text);

                ProductMoving prmove = new ProductMoving();
                prmove.Sold = 0;
                if (comboBox2.Text == "Warehouse")
                {
                    prmove.CountStore = Convert.ToDouble(textBox6.Text);
                    prmove.CountShop  = 0;
                }
                else if (comboBox2.Text == "Shop")
                {
                    prmove.CountShop  = Convert.ToDouble(textBox6.Text);
                    prmove.CountStore = 0;
                }
                else
                {
                    MessageBox.Show("Некорректно выбран склад");
                }
                BridgeToBD.SaveProductShopToBD(pr, BridgeToBD.ChoiceBD);
                BridgeToBD.LoadProductShopFromDB(BridgeToBD.ChoiceBD);
                prmove.IDproduct = BridgeToBD.Products.Last().ID;
                BridgeToBD.SaveProductMovingToBD(prmove, BridgeToBD.ChoiceBD);
                dataGridView1ReLoad();
            }
            else
            {
                MessageBox.Show("Товар с таким именем уже есть на складе");
            }
        }