public bool AddProduct(string name, string unit, decimal price, bool isVisible, int count, decimal tax, decimal shipping, out BL.Product product) { bool addProduct = false; using (ShopDataContext db = new ShopDataContext()) { product = new BL.Product(); if (db.Products.Any(p => p.Name == name)) return false; BL.Modules.Products.ProductProperies ppbl = new ProductProperies(); product.ProductID = Guid.NewGuid(); product.Name = name; product.CreateDate = DateTime.Now; product.Unit = unit; product.Price = price; product.InStock = (count > 0); product.IsVisible = isVisible; product.ProductTypeID = (int)ProductType.Types.Real; product.Count = count; product.Tax = tax; product.Shipping = shipping; db.Products.InsertOnSubmit(product); db.SubmitChanges(); addProduct = ppbl.AddProductPhoto(BL.Site.DefaultPhotoPreview, BL.Site.DefaultPhotoOriginal, product.ProductID); addProduct = true; } return addProduct; }
public BL.Product GetProductById(int id) { var product = _context.Products.Where(p => p.ProductId == id).First(); BL.Product searched = new BL.Product(product.ProductId, product.ProductName, product.UnitPrice); return(searched); }
public void Add_Order(int order_id, DateTime order_date, int cust_id, string descrip, string sales_man, int Delivery_man, string total) { DAL.Data_Access_Layer dal = new DAL.Data_Access_Layer(); dal.open_Connection(); BL.Product prd = new BL.Product(); SqlParameter[] paramter = new SqlParameter[7]; paramter[0] = new SqlParameter("@ID_order", SqlDbType.Int); paramter[0].Value = order_id; paramter[1] = new SqlParameter("@order_date", SqlDbType.Date); paramter[1].Value = order_date; paramter[2] = new SqlParameter("@Customer_id", SqlDbType.Int); paramter[2].Value = cust_id; paramter[3] = new SqlParameter("@Description_order", SqlDbType.VarChar, 250); paramter[3].Value = descrip; paramter[4] = new SqlParameter("@sales_man", SqlDbType.VarChar, 50); paramter[4].Value = sales_man; paramter[5] = new SqlParameter("@Delivery_man", SqlDbType.Int); paramter[5].Value = Delivery_man; paramter[6] = new SqlParameter("@total", SqlDbType.VarChar, 50); paramter[6].Value = total; dal.ExecuteCommand("Add_product", paramter); dal.Close_Connection(); }
public void update_products(string prod_id, string name_prod, int quant, string price, int id_cat, byte[] img) { DAL.Data_Access_Layer dal = new DAL.Data_Access_Layer(); dal.open_Connection(); BL.Product prd = new BL.Product(); SqlParameter[] paramter = new SqlParameter[6]; paramter[0] = new SqlParameter("@ID", SqlDbType.NChar, 50); paramter[0].Value = prod_id; paramter[1] = new SqlParameter("@Name_prod", SqlDbType.NVarChar, 50); paramter[1].Value = name_prod; paramter[2] = new SqlParameter("@quantity", SqlDbType.NChar, 10); paramter[2].Value = quant; paramter[3] = new SqlParameter("@image", SqlDbType.Image); paramter[3].Value = img; paramter[4] = new SqlParameter("@ID_Cat", SqlDbType.Int); paramter[4].Value = id_cat;; paramter[5] = new SqlParameter("@price", SqlDbType.VarChar, 50); paramter[5].Value = price; dal.ExecuteCommand("update_product", paramter); dal.Close_Connection(); }
// update product data private void button1_Click(object sender, EventArgs e) { if (!(txtAvailableQuan.Text.Equals("") || txtCriticalQuan.Text.Equals("") || txtorigPric.Text.Equals("") || txtsellprice.Text.Equals("")|| comboBox1.Text.Equals(""))) { BL.Product pro=new BL.Product(); BL.Product product = new BL.Product(comboBox1.Text, Convert.ToInt32(txtAvailableQuan.Text), Convert.ToInt32(txtCriticalQuan.Text), float.Parse(txtorigPric.Text), float.Parse(txtsellprice.Text)); if (!product.check_udate_product(product, ref pro)) // check_udate_product return true { MessageBox.Show("البيانات لم تتغير لكى يتم تعديلها"); } else { if (manager.Update_Product(product)) { MessageBox.Show("تم تعديل البيانات "); } } } else { MessageBox.Show("املا جميع الفرغات"); } }
private void AddProduct_Click(object sender, EventArgs e) { BL.Product prd = new BL.Product(); if (state == "Add") { string prod_id, prod_name, price; int qunt, ID_cat; prod_id = textBox_PRD_ID.Text; prod_name = textBox_PRD_Name.Text; price = textBox_PRD_Price.Text; qunt = int.Parse(textBox_PRD_Qunt.Text); ID_cat = Convert.ToInt32(comboBox_Categories.SelectedValue); MemoryStream ms = new MemoryStream(); pictureBox_PRD_Img.Image.Save(ms, pictureBox_PRD_Img.Image.RawFormat); byte[] img = ms.ToArray(); prd.Add_products(prod_id, prod_name, qunt, price, ID_cat, img); textBox_PRD_ID.Clear(); textBox_PRD_Name.Clear(); textBox_PRD_Price.Clear(); textBox_PRD_Qunt.Clear(); MessageBox.Show("Product Added Successfully", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string prod_id, prod_name, price; int qunt, ID_cat; prod_id = textBox_PRD_ID.Text; prod_name = textBox_PRD_Name.Text; price = textBox_PRD_Price.Text; qunt = int.Parse(textBox_PRD_Qunt.Text); ID_cat = Convert.ToInt32(comboBox_Categories.SelectedValue); MemoryStream ms = new MemoryStream(); byte[] img = ms.ToArray(); prd.update_products(prod_id, prod_name, qunt, price, ID_cat, img); MessageBox.Show("Product up to date Successfully", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } Prdct_Mngmnt.main_frm.dataGridView1.DataSource = prd.Get_allprdcts(); }
public void Delete_User() { DAL.Data_Access_Layer dal = new DAL.Data_Access_Layer(); dal.open_Connection(); BL.Product prd = new BL.Product(); SqlParameter[] paramter = new SqlParameter[1]; paramter[0] = new SqlParameter("@user_id", SqlDbType.NVarChar, 50); paramter[0].Value = user; dal.ExecuteCommand("delete_User", paramter); dal.Close_Connection(); }
static void Main(string[] args) { //BL.MapperProfile.Initialize(); BL.Product product1 = new BL.Product(); //product1.ID = 1; product1.Name = "Car"; product1.Price = 20; BL.Provider provider1 = new BL.Provider(); //provider1.ID = 2; provider1.Name = "Geely"; product1.Provider = provider1; BL.Category cat1 = new BL.Category(); //cat1.ID = 3; cat1.Name = "Cars"; product1.Categories.Add(cat1); cat1.Products.Add(product1); BL.Category cat2 = new BL.Category(); //cat2.ID = 4; cat2.Name = "Vehicles"; product1.Categories.Add(cat2); cat2.Products.Add(product1); provider1.Products.Add(product1); BL.ProductService db = new BL.ProductService(); //var db = ProductDb.Products; //foreach (Product prod in db) //{ // //База создалась только на этом моменте // Console.WriteLine("{0} - {1}", prod.Name, prod.Price); //} db.AddProduct(product1); BL.Product pr = db.Get(1); db.Save(); Console.WriteLine("{0}({2}) - {1}", pr.Name, pr.Price, pr.Provider.Name); Console.ReadLine(); }
//retrieve All Product public List<BL.Product> retrieveProduct() { List<BL.Product> allProducts = new List<BL.Product>(); DataTable dt = new DataTable(); dt = SelectTable("selectAllProduct", null); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { BL.Product product = new BL.Product(dr["Product_Name"].ToString(), Convert.ToInt32(dr["Avalible_Quantity"]), Convert.ToInt32(dr["Critcal_Quantity"]), float.Parse(dr["Oraginal_Price"].ToString()), float.Parse(dr["Sales_Price"].ToString())); product.Id = Convert.ToInt32(dr["Product_Id"]); allProducts.Add(product); } } return allProducts; }
//========================================================== // member functions public void Add_User() { DAL.Data_Access_Layer dal = new DAL.Data_Access_Layer(); dal.open_Connection(); BL.Product prd = new BL.Product(); SqlParameter[] paramter = new SqlParameter[4]; paramter[0] = new SqlParameter("@user_id", SqlDbType.NVarChar, 50); paramter[0].Value = user; paramter[1] = new SqlParameter("@password", SqlDbType.NVarChar, 50); paramter[1].Value = password; paramter[2] = new SqlParameter("@state", SqlDbType.NChar, 10); paramter[2].Value = state; paramter[3] = new SqlParameter("@Fullname", SqlDbType.VarChar, 50); paramter[3].Value = fullname; dal.ExecuteCommand("ADD_USER", paramter); dal.Close_Connection(); }
private void button1_Click(object sender, EventArgs e) { BL.Worker worker = new BL.Worker(); if (!(txtname.Text.Equals("") || txtOriginalPrice.Text.Equals("") || txtsellPrice.Text.Equals("") || txtCriticalQuantity.Text.Equals("") || txtAvilableQuantiity.Text.Equals(""))) { BL.Product product=new BL.Product(txtname.Text,Convert.ToInt32(txtAvilableQuantiity.Text),Convert.ToInt32(txtCriticalQuantity.Text),float.Parse(txtOriginalPrice.Text),float.Parse(txtsellPrice.Text)); if(worker.AddProduct(product)){ // check product is added if added show user message box Done MessageBox.Show("تم اضافة المنج بنجاح"); txtAvilableQuantiity.Text = ""; txtCriticalQuantity.Text = ""; txtname.Text = ""; txtOriginalPrice.Text = ""; txtsellPrice.Text = ""; } else{ // if prduct do not adde show user message Wrong for adding product MessageBox.Show("خطا فى الاضافه"); } } else { MessageBox.Show("املا جميع الفرغات"); } //show message box to make user write all fields }
public void Add_products_order(string id_prod, int order_ID, string quantiy, string price, double discount, string amount) { DAL.Data_Access_Layer dal = new DAL.Data_Access_Layer(); dal.open_Connection(); BL.Product prd = new BL.Product(); SqlParameter[] paramter = new SqlParameter[6]; paramter[0] = new SqlParameter("@ID_PROD", SqlDbType.NChar, 10); paramter[0].Value = id_prod; paramter[1] = new SqlParameter("@ID_ORDER", SqlDbType.Int); paramter[1].Value = order_ID; paramter[2] = new SqlParameter("@quantity", SqlDbType.NChar, 10); paramter[2].Value = quantiy; paramter[3] = new SqlParameter("@Price", SqlDbType.VarChar, 50); paramter[3].Value = price; paramter[4] = new SqlParameter("@discount", SqlDbType.Float); paramter[4].Value = discount; paramter[5] = new SqlParameter("@Amount", SqlDbType.VarChar, 50); paramter[5].Value = amount; dal.ExecuteCommand("Add_Order_products", paramter); dal.Close_Connection(); }
public void DeleteProductCategories(Guid productID) { BL.Product poducts = new BL.Product(); BL.ShopDataContext ctx = new ShopDataContext(); var refs = ctx.ProductsRefCategories.Where(r => r.ProductID == productID); foreach (var item in refs) { var catRef = item.Category.ProductsRefCategories.Where(s => s.Sort > item.Sort); foreach (var refs1 in catRef) { refs1.Sort--; } } ctx.ProductsRefCategories.DeleteAllOnSubmit(refs); ctx.SubmitChanges(); }
private void reload_Product() { // this function run during laod form and manager update product BL.Product pro = new BL.Product(); allProducts = new List<BL.Product>(); allProducts = pro.selectAllProduct(); foreach (BL.Product product in allProducts) { comboBox1.Items.Add(product.Product_Name1); } }
private void button3_Click(object sender, EventArgs e) { BL.Manager manager = new BL.Manager(); if (MessageBox.Show("هل تريد حذف الصنف المحدد؟", "عملية الحذف", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { BL.Product pro = new BL.Product(comboBox1.Text, Convert.ToInt32(txtAvailableQuan.Text), Convert.ToInt32(txtCriticalQuan.Text), float.Parse(txtorigPric.Text), float.Parse(txtsellprice.Text)); if (manager.Delet_Product(pro)) { comboBox1.SelectedItem = null; comboBox1.Items.Clear(); reloadProduct(); txtAvailableQuan.Text = ""; txtCriticalQuan.Text = ""; txtorigPric.Text = ""; txtsellprice.Text = ""; } else { MessageBox.Show("المنتج غير موجود "); } } }
//this event fire when user don't focus on it private void txtname_Validated(object sender, EventArgs e) { BL.Product product = new BL.Product(); if (product.Check_Product_Name(txtname.Text)) { MessageBox.Show("هذا المنتج موجود بالفعل", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtname.Focus(); txtname.SelectionStart = 0; txtname.SelectionLength = txtname.TextLength; } }