private void button1_Click(object sender, EventArgs e) { Person p = new Person(); if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "") { p.Name = textBox1.Text; p.Address = textBox3.Text; int id = (comboBox1.SelectedIndex) + 1; //var query = (from c in app.PersonTypes // where c.ID==id // select c.ID).FirstOrDefault(); p.PersonType_ID = id; int number; if (int.TryParse(textBox2.Text, out number)) { p.Phone = textBox2.Text; app.person.Add(p); app.SaveChanges(); MessageBox.Show("تم حفظ"); getall(); } else { MessageBox.Show("مينفعش ندخل حروف فى رقم التليفون "); } } else { MessageBox.Show("اتاكد انك دخلت كل حاجه "); } }
private void buttonAdd_Click(object sender, EventArgs e) { var query = (from cat in context.categories where cat.Name.Equals(textNameOfCat.Text) select cat.Name).Count(); if (textNameOfCat.Text.Length >= 1 && textNameOfCat.Text != " ") { Categories cat = new Categories(); if (query == 0) { cat.Name = textNameOfCat.Text; context.categories.Add(cat); context.SaveChanges(); textNameOfCat.Text = ""; ShowCategories(); } else { MessageBox.Show("تم ادخل هذا الصنف من قبل"); textNameOfCat.Text = ""; } } else { MessageBox.Show("من فضلك ادخل اسم الصنف"); } }
private void button3_Click(object sender, EventArgs e) { try { if (checnk_form()) { Invoice invoice = new Invoice(); invoice.Pesron_ID = int.Parse(comboBox1.SelectedValue.ToString()); invoice.InvoiceType_ID = 6; invoice.PaymentType_ID = int.Parse(comboBox2.SelectedValue.ToString()); invoice.TotalBill = numericUpDown4.Value; invoice.TotalCash = numericUpDown2.Value; invoice.TotalReset = numericUpDown3.Value; invoice.BillDate = DateTime.Now.Date; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { int id = int.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString()); int quantity = int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()); InvoiceProduct ips = new InvoiceProduct(); ips.Product_ID = id; ips.Quantity = quantity; ips.SerialNumber = generate_code() + i; invoice.InvoiceProduct.Add(ips); } Person p = context.person.FirstOrDefault(ps => ps.ID == invoice.Pesron_ID); p.AccountMoney -= numericUpDown2.Value; context.invoices.Add(invoice); context.SaveChanges(); dataGridView1.Rows.Clear(); counter = 0; numericUpDown4.Value = 0; numericUpDown2.Value = 0; numericUpDown3.Value = 0; MessageBox.Show("تم حفظ الفاتورة"); dataGridView2.Rows.Clear(); showallbillin(); //numericUpDown2.Enabled = false; //listBox2.Items.Clear(); listBox3.Items.Clear(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); MessageBox.Show("لقد حدث خطأ اثناء عملية حفظ البيانات يرجي المحاولة في وقت لاحق"); } }
private void DeleteProduct_Click(object sender, EventArgs e) { try { if (Datagridviewshow.SelectedRows[0].Cells[1].Value != null) { int ID = int.Parse(Datagridviewshow.SelectedRows[0].Cells[5].Value.ToString()); var query = (from p in context.Products where p.ID == ID select p).FirstOrDefault(); var invpord = context.invoice_products.Where(ds => ds.Products == query).ToList(); context.invoice_products.RemoveRange(invpord); context.Products.Remove(query); context.SaveChanges(); ShowAllProduct(); } else { MessageBox.Show("يرجي اختيار المنتج الصحيح"); } } catch (Exception es) { MessageBox.Show("من فضلك اختار المنتج الذى تريد مسحه "); } }
private void SaveUpdate_Click(object sender, EventArgs e) { try { countclick = 1; categoryName = updatetextbox.Text; if (categoryName.Length >= 1 && categoryName != "" && categoryName != null) { var query2 = (from cat in context.categories where cat.Name.Equals(categoryName) select cat).Count(); if (query2 == 0) { var query = (from cat in context.categories where cat.ID == ID select cat).FirstOrDefault(); query.Name = categoryName; context.SaveChanges(); this.Close(); } else { MessageBox.Show("هذا الصنف موجود مسبقا"); } } else { MessageBox.Show("من فضلك ادخل اسم الصنف صحيحا"); } } catch (Exception ex) { MessageBox.Show(ex.Message); //MessageBox.Show("من فضلك ادخل اسم الصنف صحيحا"); } }
private void button3_Click(object sender, EventArgs e) { Invoice invoice = new Invoice(); invoice.invoiceTypePriceID = 1; invoice.BillDate = (DateTime.Now).Date; invoice.TotalCash = 0; //change Invoice Type to 3 invoice.InvoiceType_ID = 3; invoice.PaymentType_ID = 1; invoice.Pesron_ID = int.Parse(comboBox2.SelectedValue.ToString()); invoice.TotalBill = 0; invoice.TotalReset = 0; foreach (DataGridViewRow row in dataGridView2.Rows) { int i = row.Index; if (i < dataGridView2.RowCount - 1) { string value1 = row.Cells[0].Value.ToString(); var quantdata = (from n in context.Products where n.Name == value1 select n).FirstOrDefault(); int value2 = int.Parse(row.Cells[1].Value.ToString()); string ser = row.Cells[2].Value.ToString(); invoice.InvoiceProduct.Add(new InvoiceProduct { Quantity = value2, SerialNumber = ser, Product_ID = quantdata.ID }); } } if (dataGridView2.Rows.Count != 1) { context.invoices.Add(invoice); context.SaveChanges(); context = new ERBContext(); MessageBox.Show("تم الحفظ", "تأكيد"); dataGridView2.Rows.Clear(); } else { MessageBox.Show("لا توجد بيانات", "خطأ"); } }
private void button1_Click(object sender, EventArgs e) { int ID = (from cat in context.categories where cat.Name == NameOfCat.SelectedValue.ToString() select cat.ID).FirstOrDefault(); string ProductName = NameOfProduct.Text; decimal Pricein = priceIn.Value; decimal PriceOutAll = priceOutAll.Value; decimal PriceOutOne = priceOutOne.Value; int Qoutity = (int)countity.Value; var query = (from pro in context.Products where pro.Name == ProductName select pro).Count(); if (query == 0 && ProductName != " " && ProductName != null && ProductName.Length >= 1 && Pricein > 0 && PriceOutAll > 0 && PriceOutOne > 0 && Qoutity > 0) { context.Products.Add(new Products() { PriceIn = Pricein, PriceOutOne = PriceOutOne, PriceOutAll = PriceOutAll, Quantity = Qoutity, Categories_ID = ID, Name = ProductName }); context.SaveChanges(); NameOfProduct.Text = ""; priceIn.Value = 0; priceOutAll.Value = 0; priceOutOne.Value = 0; countity.Value = 0; MessageBox.Show("تم اضافة المنتج"); //this.Close(); } else { if (query != 0) { MessageBox.Show("هذا المنتج موجود مسبقا "); } else if (ProductName == " " && ProductName == null && ProductName.Length < 1) { MessageBox.Show("من فضلك ادخل اسم المنتج"); } else { MessageBox.Show("من فضلك ادخل قيمة"); } } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "") { login_check lg = new login_check(); sslDalc sl = new sslDalc(); lg.logincheck_name = textBox1.Text; lg.logincheck_username = textBox2.Text; lg.logincheck_password = sl.Encrypt(textBox3.Text); lg.logincheck_type = 1; context.login_checks.Add(lg); context.SaveChanges(); MessageBox.Show("تم التسجيل"); textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; getall(); } else { MessageBox.Show("يرجي ملئ جميع البيانات"); } }
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { if (dataGridView1.SelectedRows[0].Cells[1].Value != null) { int ivid = int.Parse(dataGridView1.SelectedRows[0].Cells[1].Value.ToString()); int staus = context.invoices.FirstOrDefault(i => i.ID == ivid).invoicestatus; products = context.invoice_products.Where(ip => ip.Invoice_ID == ivid).ToList(); dataGridView2.Rows.Clear(); int co = 1; if (staus == 0) { foreach (var item in products) { add_drg(co.ToString(), item.Products.Name, item.Quantity.ToString(), item.SerialNumber, item.Product_ID.ToString()); co++; } } else if (staus == 1) { var i = context.InvoiceSellPermisions.Where(isv => isv.InvoicePermisionID == ivid); foreach (var item in products) { int quantity = 0; foreach (var items in i) { quantity += (from inpr in context.invoice_products where inpr.Invoice_ID == items.InvoiceSellID && inpr.Product_ID == item.Product_ID select inpr.Quantity).FirstOrDefault(); } if (item.Quantity - quantity != 0) { add_drg(co.ToString(), item.Products.Name, (item.Quantity - quantity).ToString(), item.SerialNumber, item.Product_ID.ToString()); co++; } } if (dataGridView2.Rows.Count <= 1) { context.invoices.FirstOrDefault(isa => isa.ID == ivid).invoicestatus = 2; context.SaveChanges(); comboBox1.SelectedIndex = 0; } } } else { MessageBox.Show("لا يوجد فاتورة"); } } else { MessageBox.Show("يرجي اختيار الفاتورة"); } }
private void DeleteProduct_Click(object sender, EventArgs e) { try { int ID = int.Parse(Datagridviewshow.SelectedRows[0].Cells[5].Value.ToString()); var query = (from p in context.Products where p.ID == ID select p).FirstOrDefault(); context.Products.Remove(query); context.SaveChanges(); ShowAllProduct(); } catch (Exception es) { MessageBox.Show("من فضلك اختار المنتج الذى تريد مسحه "); } }
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "" && textBox2.Text != "0" && dataGridView1.SelectedRows.Count > 0) { int quantity; int.TryParse(textBox2.Text, out quantity); var queryProductFatora = (from productFatora in Our.invoice_products where productFatora.Products.Name == label3.Text select productFatora).FirstOrDefault(); int?prodID = queryProductFatora.Product_ID; var prodin = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 1).Sum(vs => (int?)vs.Quantity) ?? 0; var prodout1 = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 5).Sum(vs => (int?)vs.Quantity) ?? 0; var prodout2 = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 3).Sum(vs => (int?)vs.Quantity) ?? 0; var prodin2 = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 4).Sum(vs => (int?)vs.Quantity) ?? 0; var totalfound = ((prodin + prodin2) - (prodout2 + prodout1)); if (totalfound >= quantity || totalfound >= quantity) { int index = dataGridView1.CurrentCell.RowIndex; //queryProductFatora.Quantity -= quantity; //queryProductFatora.Products.Quantity -= quantity; InvoiceProduct add = new InvoiceProduct(); //string a = ; //string a = DateTime.Now.ToShortDateString(); add.Quantity = quantity; add.SerialNumber = textBox1.Text; string name = dataGridView1.Rows[index].Cells["personName"].Value.ToString(); Products productDetails = (from Product in Our.Products where Product.Name == label3.Text select Product).FirstOrDefault(); Person personDetails = (from person in Our.person where person.Name == name && person.PersonType_ID == 1 select person).FirstOrDefault(); add.Product_ID = productDetails.ID; Invoice x = new Invoice(); x.BillDate = DateTime.Now.Date;//Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-dd")); x.Pesron_ID = personDetails.ID; x.InvoiceType_ID = 5; x.PaymentType_ID = 1; x.invoicestatus = 0; x.invoiceTypePrice = productDetails.InvoiceProduct.Select(ip => ip.Invoice.invoiceTypePrice).FirstOrDefault(); x.TotalBill = (quantity * productDetails.PriceIn); x.TotalCash = (quantity * productDetails.PriceIn); add.Invoice = x; x.Person.AccountMoney -= x.TotalCash; //delete from orginal fatora //int id; //int.TryParse(dataGridView1.Rows[index].Cells["invoiceNumber"].Value.ToString(), out id); //var queryFatora = (from fatora in Our.invoices // where fatora.ID == id // select fatora).FirstOrDefault(); //queryFatora.TotalBill -= x.TotalBill; //if (queryFatora.TotalCash > queryFatora.TotalReset) //{ // queryFatora.TotalCash -= x.TotalCash; //} //else //{ // queryFatora.TotalReset -= x.TotalCash; //} Our.invoice_products.Add(add); Our.SaveChanges(); MessageBox.Show("تمام "); getall(); textBox1.Text = ""; label3.Text = ""; dataGridView1.DataSource = null; textBox2.Text = "0"; } else { MessageBox.Show("الكميه المرتجعه مش موجوده ف المخزن " + totalfound); } } else { MessageBox.Show("يرجي اختيار و ملئ البيانات صحيحة"); } }
private void SaveProduct_Click(object sender, EventArgs e) { var query = (from p in context.Products where p.ID == IDPro select p).FirstOrDefault(); int ID = (from cat in context.categories where cat.Name == NameOfCat.SelectedValue.ToString() select cat.ID).FirstOrDefault(); query.Name = NameOfProduct.Text; query.PriceIn = priceIn.Value; query.PriceOutAll = priceOutAll.Value; query.PriceOutOne = priceOutOne.Value; query.Quantity = (int)countity.Value; query.Categories_ID = ID; var query2 = (from pro in context.Products where pro.Name == NameOfProduct.Text select pro).FirstOrDefault(); var query3 = (from p in context.Products where p.ID == IDPro select p).FirstOrDefault(); //if (query2 == 1 && NameOfProduct.Text== query3.Name && NameOfProduct.Text != " " // && NameOfProduct.Text != null && NameOfProduct.Text.Length >= 1 // && priceIn.Value > 0 && priceOutOne.Value > 0 // && priceOutAll.Value > 0 && countity.Value > 0) //{ // context.SaveChanges(); //} if (query2 == null && NameOfProduct.Text != " " && NameOfProduct.Text != null && NameOfProduct.Text.Length >= 1 && priceIn.Value >= 0 && priceOutOne.Value >= 0 && priceOutAll.Value >= 0 && countity.Value >= 0) { context.SaveChanges(); this.Close(); } else { if (query2 != null) { if (query2.ID == query.ID && NameOfProduct.Text != " " && NameOfProduct.Text != null && NameOfProduct.Text.Length >= 1 && priceIn.Value >= 0 && priceOutOne.Value >= 0 && priceOutAll.Value >= 0 && countity.Value >= 0) { context.SaveChanges(); this.Close(); } else if (query2.ID != query.ID) { MessageBox.Show("من فضلك ادخل اسم المنتج صيحيح بدون تكرار مع اسم منتج اخر"); } else if (NameOfProduct.Text == " " && NameOfProduct.Text == null && NameOfProduct.Text.Length < 1) { MessageBox.Show("من فضلك ادخل اسم المنتج"); } else { MessageBox.Show("من فضلك ادخل قيمة"); } } else if (NameOfProduct.Text == " " && NameOfProduct.Text == null && NameOfProduct.Text.Length < 1) { MessageBox.Show("من فضلك ادخل اسم المنتج"); } else { MessageBox.Show("من فضلك ادخل قيمة"); } } }