private void btnRemove_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("آیا از حذف شخص مطمئنید ؟", "اخطار", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.No)
            {
                return;
            }

            if (dgvPersons.SelectedRows.Count == 0)
            {
                return;
            }

            var id = Convert.ToInt32(dgvPersons.SelectedRows[0].Cells["clnId"].Value);

            var db = new shampazEntities();
            var p  = db.Persons.Where(x => x.Id == id).FirstOrDefault();

            try
            {
                db.Persons.Remove(p);
                db.SaveChanges();
                DesktopAlert.Show("شخص حذف شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);
                dgvPersonsRefresh();
            }
            catch
            {
                DesktopAlert.Show("امکان حذف شخص نیست", eDesktopAlertColor.Red, eAlertPosition.BottomRight);
            }
        }
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (dgvFactors.SelectedRows.Count == 0)
            {
                return;
            }

            var result = MessageBox.Show("آیا مطئن هستید?", "اخطار", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.No)
            {
                return;
            }

            var db = new shampazEntities();

            foreach (DataGridViewRow row in dgvFactors.SelectedRows)
            {
                var id     = Convert.ToInt32(row.Cells["clnId"].Value);
                var factor = db.BuyFactors.Where(x => x.Id == id).FirstOrDefault();
                var items  = db.BuyFactorItems.Where(x => x.BuyFactorId == factor.Id).ToList();
                db.BuyFactorItems.RemoveRange(items);
                db.BuyFactors.Remove(factor);
            }

            db.SaveChanges();
            DesktopAlert.Show("فاکتور حذف شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);

            btnFilter.PerformClick();
        }
Beispiel #3
0
        private void save()
        {
            var db = new shampazEntities();

            var factor = new SellFactor
            {
                Date        = (DateTime)pdpDate.GeorgianDate + dtpTime.Value.TimeOfDay,
                PersonId    = SelectedPerson.Id,
                TotalPrice  = Convert.ToDecimal(txtTotalPrice.Text),
                Description = txtDescription.Text,
            };

            db.SellFactors.Add(factor);

            foreach (DataGridViewRow r in dgvItems.Rows)
            {
                factor.SellFactorItems.Add(
                    new SellFactorItem
                {
                    Name       = r.Cells["clnProductName"].Value.ToString(),
                    Numbers    = Convert.ToInt32(r.Cells["clnNumber"].Value),
                    Price      = Convert.ToDecimal(r.Cells["clnProductPrice"].Value),
                    ProductId  = Convert.ToInt32(r.Cells["clnProductId"].Value),
                    TotalPrice = Convert.ToDecimal(r.Cells["clnTotalPrice"].Value),
                }
                    );
            }

            db.SaveChanges();
            DesktopAlert.Show("فاکتور ذخیره شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);
            EditedSellFactor = factor;
        }
        private void editPerson()
        {
            var db = new shampazEntities();
            var p  = db.Persons.Where(x => x.Id == PersonId).FirstOrDefault();

            p.Name    = txtName.Text.Trim();
            p.Mobile  = txtMobile.Text.Trim();
            p.Address = txtAddress.Text.Trim();

            DesktopAlert.Show("شخص ویرایش شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);
            db.SaveChanges();
        }
        private void addPerson()
        {
            var db = new shampazEntities();

            db.Persons.Add(new Person
            {
                Name    = txtName.Text.Trim(),
                Address = txtAddress.Text.Trim(),
                Mobile  = txtMobile.Text.Trim()
            });

            db.SaveChanges();

            DesktopAlert.Show("شخص افزوده شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);
        }
        private void update()
        {
            var db     = new shampazEntities();
            var factor = db.BuyFactors.Where(x => x.Id == EditedFactor.Id).FirstOrDefault();

            factor.Date        = (DateTime)pdpDate.GeorgianDate + dtpTime.Value.TimeOfDay;
            factor.PersonId    = SelectedPerson.Id;
            factor.TotalPrice  = Convert.ToDecimal(txtTotalPrice.Text);
            factor.Description = txtDescription.Text;

            try
            {
                factor.PaymentPrice = Convert.ToDecimal(txtPayment.Text);
            }
            catch
            {
                factor.PaymentPrice = 0;
            }

            //MessageBox.Show(factor.Id.ToString());
            db.BuyFactorItems.RemoveRange(factor.BuyFactorItems);

            //foreach( var item in factor.SellFactorItems )
            //{
            //    db.SellFactorItems.Remove(item);
            //    db.SaveChanges();
            //}

            foreach (DataGridViewRow r in dgvItems.Rows)
            {
                factor.BuyFactorItems.Add(
                    new BuyFactorItem
                {
                    Name       = r.Cells["clnProductName"].Value.ToString(),
                    Quantity   = Convert.ToDouble(r.Cells["clnNumber"].Value),
                    Price      = Convert.ToDecimal(r.Cells["clnProductPrice"].Value),
                    ProductId  = Convert.ToInt32(r.Cells["clnProductId"].Value),
                    TotalPrice = Convert.ToDecimal(r.Cells["clnTotalPrice"].Value)
                }
                    );
            }

            db.SaveChanges();
            DesktopAlert.Show("فاکتور بروزرسانی شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);
            EditedFactor = factor;
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim().Length == 0)
            {
                DesktopAlert.Show("نام نمی تواند خالی باشد", eDesktopAlertColor.Red, eAlertPosition.BottomRight);
                return;
            }

            decimal price;

            try
            {
                price = Convert.ToDecimal(txtPrice.Text);
            }
            catch
            {
                price = 0;
            }

            if (price == 0)
            {
                DesktopAlert.Show("قیمت کالا را وارد کنید", eDesktopAlertColor.Red, eAlertPosition.BottomRight);
                return;
            }

            // Profit
            decimal profit;

            try
            {
                profit = Convert.ToDecimal(txtProfit.Text);
            }
            catch
            {
                profit = 0;
            }

            // save data
            var db = new shampazEntities();

            Product p;

            if (EditMode)
            {
                p        = db.Products.Where(x => x.Id == ProductId).FirstOrDefault();
                p.Name   = txtName.Text.Trim();
                p.Price  = price;
                p.Profit = profit;

                DesktopAlert.Show("محصول بروزرسانی شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);
            }
            else
            {
                db.Products.Add(new Product
                {
                    Name   = txtName.Text.Trim(),
                    Price  = price,
                    Profit = profit
                });

                DesktopAlert.Show("محصول ثبت شد", eDesktopAlertColor.Green, eAlertPosition.BottomRight);
            }

            db.SaveChanges();
            DialogResult = DialogResult.OK;

            Close();
        }
Beispiel #8
0
        private void deleteFactor(SellFactor factor)
        {
            var db = new shampazEntities();

            db.SaveChanges();
        }