private void rpresentiveCombo_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            x = (Representitive)rpresentiveCombo.SelectedItem;
            string repName = rpresentiveCombo.SelectedItem.ToString();
            var    y       = context.RepresentitiveBillDetails
                             .Where(p => p.RepresentitiveBill.Representitive_NationalID == x.NationalID);
            List <Product> ProductList = new List <Product>();

            foreach (var item in y)
            {
                Product ProdcutOfRep = context.Products.FirstOrDefault(p => p.ID == item.ProductObj_ID);
                ProductList.Add(ProdcutOfRep);
            }
            // productComboFromRepresentive.DataSource= ProductList;//بتوع المندوب
            // productComboFromRepresentive.DisplayMember = "Name";
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                comboBox1.Enabled = false;

                RepresentitiveBillDetail newRepresentiveBd = new RepresentitiveBillDetail();
                Representitive           NameRep           = (Representitive)comboBox1.SelectedItem;
                Representitive           rep = context.Representitives.FirstOrDefault(r => r.Name == NameRep.Name);
                RepresentitiveBill       newRepresentitveBill = new RepresentitiveBill()
                {
                    Representitive_NationalID = rep.NationalID
                };
                context.RepresentitiveBills.Add(newRepresentitveBill);
                context.SaveChanges();
                RepresentitiveBill RepresentitveBillJustAdded = context.RepresentitiveBills.OrderByDescending(r => r.ID).FirstOrDefault();

                foreach (var item in supproductlocalList)
                {
                    newRepresentiveBd.GivenAmount              = item.GivenAmount;
                    newRepresentiveBd.Date                     = item.Date;
                    newRepresentiveBd.ProductObj_ID            = item.ProductObj_ID;
                    newRepresentiveBd.GivenAmountPrice         = item.GivenAmountPrice;
                    newRepresentiveBd.RepresentitiveBillObj_ID = RepresentitveBillJustAdded.ID;
                    context.RepresentitiveBillDetails.Add(newRepresentiveBd);
                    context.SaveChanges();
                    Product pro = context.Products.FirstOrDefault(p => p.ID == item.ProductObj_ID);
                    if (pro.AmountInStock > item.GivenAmount)
                    {
                        pro.AmountInStock = pro.AmountInStock - item.GivenAmount;
                        context.SaveChanges();
                    }
                    else
                    {
                        MessageBox.Show("الكمية المطلوبة أكبر من الكمية الموجوده فى المخزن");
                    }
                }
                supproductlocalList.Clear();
            }
            catch
            {
            }
        }
Exemple #3
0
        private void btn_save_reps_Click(object sender, EventArgs e)
        {
            try
            {
                Representitive newRepres = new Representitive();
                foreach (var item in supproductlocalList)
                {
                    newRepres.Name       = item.Name;
                    newRepres.NationalID = item.NationalId;
                    newRepres.Phone      = item.Phone;
                    newRepres.Salary     = item.salary;
                    newRepres.TargetSale = item.TargetSale;

                    storeContext.Representitives.Add(newRepres);
                    storeContext.SaveChanges();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("هناك مندوب موجود بالفعل ");
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //compoOfClients.Enabled = false;

            //RepresentitiveBillDetail newRepresentiveBd = new RepresentitiveBillDetail();



            //ClientBill CLientBillJustAdded = context.ClientBills.OrderByDescending(r => r.ID).FirstOrDefault();
            //ClientBillDetail clientBDetails = new ClientBillDetail();
            //double totalPrice = 0;
            //string trypeClientBill = null;
            //foreach (var item in supperList)
            //{
            //    clientBDetails.Amount = item.Amount;
            //    clientBDetails.Date = item.Date;
            //    clientBDetails.Type = item.Type;
            //    trypeClientBill = item.Type;
            //    clientBDetails.AmountPrice = item.AmountPrice;
            //    clientBDetails.Paid = 0;
            //    clientBDetails.Debt = 0;
            //    clientBDetails.ClientBillObj_ID = CLientBillJustAdded.ID;
            //    clientBDetails.ProductOpj_ID = item.ProductOpj_ID;
            //    clientBDetails.AdeyMortagaType = item.AdeyMortagaType;

            //    context.ClientBillDetails.Add(clientBDetails);

            //    totalPrice = totalPrice + clientBDetails.AmountPrice;
            //    ClientBillDetail ClientBillJustAdded = context.ClientBillDetails.OrderByDescending(cB => cB.ID).FirstOrDefault();

            //    x = (Representitive)rpresentiveCombo.SelectedItem;
            //    var prdN = productComboFromRepresentive.Text.ToString();
            //    var prd = context.Products.Where(n => n.Name == prdN).FirstOrDefault();
            //    //amount of representitveBillDetails
            //    var y = context.RepresentitiveBillDetails
            //          .Where(p => p.RepresentitiveBill.Representitive_NationalID == x.NationalID && p.ProductObj_ID == prd.ID).FirstOrDefault();
            //    clientBDetails.RepresentitiveBillDetailsObj_ID = y.ID;

            //    ClientBillDetail cUpdated = context.ClientBillDetails.OrderByDescending(c => c.ID).FirstOrDefault();

            //    //  cUpdated.RepresentitiveBillDetail.GivenAmount = cUpdated.RepresentitiveBillDetail.GivenAmount - item.Amount;
            //    //context.SaveChanges();


            //    RepresentitiveBillDetail rebDeta = context.RepresentitiveBillDetails.FirstOrDefault(r => r.ID == cUpdated.RepresentitiveBillDetailsObj_ID);

            //    if (rebDeta.GivenAmount > 0 && MortagaAdeyCombo.SelectedItem.ToString() == "عادى")
            //    {
            //        rebDeta.GivenAmount = rebDeta.GivenAmount + item.Amount;


            //    }
            //    else
            //    {
            //        prd.AmountInStock = prd.AmountInStock + item.Amount;

            //    }
            //    context.SaveChanges();
            //}
            //Client ClientObj = (Client)compoOfClients.SelectedItem;
            ////Representitive rep = context.Clients.FirstOrDefault(r => r.Name == NameRep.Name);
            //double paid = int.Parse(PaidNumericUpdown.Value.ToString());
            //double deptPrice = totalPrice - paid;
            //ClientBill NewClientBill = new ClientBill()
            //{
            //    ClientObj_NationalID = ClientObj.NationalID,
            //    TotalPrice = totalPrice,
            //    type = trypeClientBill,
            //    PaidPrice = paid,
            //    DeptPrice = deptPrice
            //};

            ////lapelTotalPrice.Text = totalPrice.ToString();
            ////lapelTotalPrice.Visible = true;
            //if (flag == true)
            //{
            //    context.ClientBills.Add(NewClientBill);
            //    context.SaveChanges();
            //    flag = false;
            //}
            compoOfClients.Enabled = false;

            RepresentitiveBillDetail newRepresentiveBd = new RepresentitiveBillDetail();

            Client     ClientSelected = context.Clients.FirstOrDefault(c => c.Name == compoOfClients.Text);
            ClientBill clientBilld    = new ClientBill()
            {
                ClientObj_NationalID = ClientSelected.NationalID,
                type = TypeBillCombo.Text,
            };

            context.ClientBills.Add(clientBilld);
            context.SaveChanges();


            ClientBill       CLientBillJustAdded = context.ClientBills.OrderByDescending(r => r.ID).FirstOrDefault();
            ClientBillDetail clientBDetails      = new ClientBillDetail();
            double           totalPrice          = 0;
            string           trypeClientBill     = null;

            foreach (var item in supperList)
            {
                clientBDetails.Amount           = item.Amount;
                clientBDetails.Date             = item.Date;
                clientBDetails.Type             = item.Type;
                trypeClientBill                 = item.Type;
                clientBDetails.AmountPrice      = item.AmountPrice;
                clientBDetails.Paid             = 0;
                clientBDetails.Debt             = 0;
                clientBDetails.ClientBillObj_ID = CLientBillJustAdded.ID;
                clientBDetails.ProductOpj_ID    = item.ProductOpj_ID;
                clientBDetails.AdeyMortagaType  = item.AdeyMortagaType;

                context.ClientBillDetails.Add(clientBDetails);

                totalPrice = totalPrice + clientBDetails.AmountPrice;
                ClientBillDetail ClientBillJustAdded = context.ClientBillDetails.OrderByDescending(cB => cB.ID).FirstOrDefault();

                x = (Representitive)rpresentiveCombo.SelectedItem;
                var prdN = productComboFromRepresentive.Text.ToString();
                var prd  = context.Products.Where(n => n.Name == prdN).FirstOrDefault();
                //amount of representitveBillDetails
                var y = context.RepresentitiveBillDetails
                        .Where(p => p.RepresentitiveBill.Representitive_NationalID == x.NationalID && p.ProductObj_ID == prd.ID).FirstOrDefault();
                clientBDetails.RepresentitiveBillDetailsObj_ID = y.ID;

                ClientBillDetail cUpdated = context.ClientBillDetails.OrderByDescending(c => c.ID).FirstOrDefault();

                //  cUpdated.RepresentitiveBillDetail.GivenAmount = cUpdated.RepresentitiveBillDetail.GivenAmount - item.Amount;
                //context.SaveChanges();


                RepresentitiveBillDetail rebDeta = context.RepresentitiveBillDetails.FirstOrDefault(r => r.ID == cUpdated.RepresentitiveBillDetailsObj_ID);

                if (rebDeta.GivenAmount > 0 && MortagaAdeyCombo.SelectedItem.ToString() == "عادى")
                {
                    rebDeta.GivenAmount = rebDeta.GivenAmount - item.Amount;
                }
                else
                {
                    prd.AmountInStock = prd.AmountInStock + item.Amount;
                }
                context.SaveChanges();
            }
            Client ClientObj = (Client)compoOfClients.SelectedItem;
            //Representitive rep = context.Clients.FirstOrDefault(r => r.Name == NameRep.Name);
            double     paid          = int.Parse(PaidNumericUpdown.Value.ToString());
            double     deptPrice     = totalPrice - paid;
            ClientBill NewClientBill = new ClientBill()
            {
                ClientObj_NationalID = ClientObj.NationalID,
                TotalPrice           = totalPrice,
                type      = trypeClientBill,
                PaidPrice = paid,
                DeptPrice = deptPrice
            };

            //lapelTotalPrice.Text = totalPrice.ToString();
            //lapelTotalPrice.Visible = true;
            if (flag == true)
            {
                context.ClientBills.Add(NewClientBill);
                context.SaveChanges();
                flag = false;
            }
        }
        private void button3_Click_2(object sender, EventArgs e)
        {
            Product ChechProduct = null;

            if (TypeBillCombo.Text == "جملة")
            {
                ChechProduct = ChechProduct = context.Products.FirstOrDefault(p => p.Name == productComboFromRepresentive.Text);
                priceType    = ChechProduct.WholesalePrice;
            }
            if (TypeBillCombo.Text == "قطاعى")
            {
                ChechProduct = ChechProduct = context.Products.FirstOrDefault(p => p.Name == productComboFromRepresentive.Text);
                priceType    = ChechProduct.RetailPrice;
            }
            if (MortagaAdeyCombo.Text == "عادى")
            {
                double price = int.Parse(numericUQouantity.Value.ToString()) * priceType;
                totalPrice += price;

                lapelTotalPrice.Text    = totalPrice.ToString();
                lapelTotalPrice.Visible = true;
            }
            superItem = new supproductlocal();
            // string RepresentiveName = null;
            if (TypeBillCombo.SelectedIndex == -1)
            {
                MessageBox.Show("لابد من ادخال نوع الفاتوره اولا"); return;
            }
            // if (labelRepresentitve.Text == "")
            //{
            LabelTypeOfBill.Visible = true;
            LabelTypeOfBill.Text    = TypeBillCombo.Text;
            TypeBillCombo.Visible   = false;
            // }

            if (rpresentiveCombo.SelectedIndex == -1)
            {
                MessageBox.Show("لابد من أدخال أسم المندوب اولا"); return;
            }
            // if (.Text == "")
            // {
            //RepresentiveName= rpresentiveCombo.Text;
            labelRepresentitve.Visible = true;
            labelRepresentitve.Text    = rpresentiveCombo.Text;
            rpresentiveCombo.Visible   = false;
            // }
            x = (Representitive)rpresentiveCombo.SelectedItem;
            var prdN = productComboFromRepresentive.Text.ToString();
            var prd  = context.Products.Where(n => n.Name == prdN).FirstOrDefault();
            //amount of representitveBillDetails
            var y = context.RepresentitiveBillDetails
                    .Where(p => p.RepresentitiveBill.Representitive_NationalID == x.NationalID && p.ProductObj_ID == prd.ID).FirstOrDefault();

            if (y != null)
            {
                if (MortagaAdeyCombo.Text == "عادى")
                {
                    if (int.Parse(numericUQouantity.Value.ToString()) > int.Parse(y.GivenAmount.ToString()))
                    {
                        MessageBox.Show("الكميه غير متاحه عند المندوب"); return;
                    }
                }
            }

            //------------------add to list View---------------------------
            Product productAdd = context.Products.FirstOrDefault(p => p.Name == productComboFromRepresentive.Text);
            int     GAmount    = int.Parse(numericUQouantity.Text);
            //check if قطاعى else جملة from combo
            double amountPrice = 0;

            if (TypeBillCombo.Text == "قطاعى")
            {
                amountPrice = productAdd.RetailPrice * GAmount;
            }
            else if (TypeBillCombo.Text == "جملة")
            {
                amountPrice = productAdd.WholesalePrice * GAmount;
                totalPrice  = amountPrice;
            }

            ListViewItem items = new ListViewItem(numericUQouantity.Value.ToString(), 0);

            items.SubItems.Add(DateTime.Now.ToString());
            items.SubItems.Add(amountPrice.ToString());
            items.SubItems.Add(productComboFromRepresentive.Text);
            items.SubItems.Add(MortagaAdeyCombo.Text);
            listView1.Items.AddRange(new ListViewItem[] { items });

            var product = context.Products.FirstOrDefault(p => p.Name == productComboFromRepresentive.Text);

            //----------------------mapping---------------
            var representitve           = context.Representitives.FirstOrDefault(r => r.Name == rpresentiveCombo.Text);
            RepresentitiveBill repAdded = context.RepresentitiveBills.FirstOrDefault(r => r.Representitive_NationalID == representitve.NationalID);

            superItem.Amount                   = double.Parse(numericUQouantity.Value.ToString());
            superItem.Date                     = DateTime.Now;
            superItem.AmountPrice              = amountPrice;
            superItem.ProductOpj_ID            = product.ID;
            superItem.Type                     = TypeBillCombo.Text;
            superItem.AdeyMortagaType          = MortagaAdeyCombo.Text;
            superItem.RepresentitiveBillObj_ID = repAdded.ID;

            supperList.Add(superItem);
        }