예제 #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                int numberOfBillRepresentive;
                RepresentitiveBill RpresentiveB = context.RepresentitiveBills.OrderByDescending(R => R.ID).FirstOrDefault();
                if (RpresentiveB == null)
                {
                    numberOfBillRepresentive = 1;
                    labelNumberBill.Text     = numberOfBillRepresentive.ToString();
                }
                else
                {
                    numberOfBillRepresentive = int.Parse(RpresentiveB.ID.ToString());
                    numberOfBillRepresentive++;
                    labelNumberBill.Text = numberOfBillRepresentive.ToString();
                }
                listView1.Clear();
                comboBox1.Enabled = true;

                numericUQouantity.Value = 0;
            }
            catch
            {
            }
        }
예제 #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
            {
            }
        }
예제 #3
0
        private void sader_Load(object sender, EventArgs e)
        {
            List <Representitive> rep = context.Representitives.ToList();

            comboBox1.DataSource    = rep;
            comboBox1.DisplayMember = "Name";
            //-----------------displayNumber Of bill--------------
            //--------number of bill representiv----------
            int numberOfBill2;
            RepresentitiveBill representivrB = context.RepresentitiveBills.OrderByDescending(r => r.ID).FirstOrDefault();

            if (representivrB == null)
            {
                SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-9HH57Q0\MSSQLSEVEREX;Initial Catalog=project;Integrated Security=True");

                SqlCommand command = new SqlCommand();
                connection.Open();
                command.Connection  = connection;
                command.CommandText = "DBCC CHECKIDENT ('RepresentitiveBills',RESEED,0)";
                command.ExecuteNonQuery();
                connection.Close();

                numberOfBill2        = 1;
                labelNumberBill.Text = numberOfBill2.ToString();
            }
            else
            {
                numberOfBill2 = int.Parse(representivrB.ID.ToString());
                numberOfBill2++;
                labelNumberBill.Text = numberOfBill2.ToString();
            }
            List <Product> ProductList = context.Products.ToList();

            productComboSypplyer.DataSource    = ProductList;
            productComboSypplyer.DisplayMember = "Name";
        }
예제 #4
0
        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);
        }