private void dgvFactorsRefresh()
        {
            dgvFactors.Rows.Clear();

            var db    = new shampazEntities();
            var items = from item in db.BuyFactorItems
                        join f in db.BuyFactors on item.BuyFactorId equals f.Id
                        where f.Date >= pDateFrom.GeorgianDate && f.Date <= pDateTo.GeorgianDate
                        group item by item.ProductId into g
                        select new
            {
                ProductId   = g.Key,
                ProductName = g.Select(n => n.Product).FirstOrDefault().Name,
                TotalPrice  = g.Select(t => t.TotalPrice).Sum(),
                Quantity    = g.Select(q => q.Quantity).Sum()
            };

            double  itemsCount = 0;
            decimal totalPrice = 0;

            foreach (var item in items)
            {
                dgvFactors.Rows.Add(item.ProductId, item.ProductName, item.Quantity, item.TotalPrice.ToString("#,#"));
                itemsCount += item.Quantity;
                totalPrice += item.TotalPrice;
            }

            txtSumNumbers.Text = itemsCount.ToString("#,#");
            txtSumPrice.Text   = totalPrice.ToString("#,#");
        }
Пример #2
0
        private void dgvFactorsRefresh()
        {
            dgvFactors.Rows.Clear();

            var db = new shampazEntities();

            var to = pDateTo.GeorgianDate + new TimeSpan(23, 59, 59);

            var items = from item in db.SellFactorItems
                        join f in db.SellFactors on item.SellFactorId equals f.Id
                        where f.Date >= pDateFrom.GeorgianDate && f.Date <= to
                        group item by item.ProductId into g
                        select new
            {
                ProductId     = g.Key,
                ProductName   = g.Select(n => n.Product).FirstOrDefault().Name,
                ProductProfit = g.Select(t => t.Product).FirstOrDefault().Profit,
                Quantity      = g.Select(q => q.Numbers).Sum()
            };

            int     itemsCount  = 0;
            decimal totalProfit = 0;

            foreach (var item in items)
            {
                dgvFactors.Rows.Add(item.ProductId, item.ProductName, item.Quantity, item.ProductProfit, item.Quantity * item.ProductProfit);
                itemsCount  += item.Quantity;
                totalProfit += item.Quantity * item.ProductProfit;
            }

            txtSumNumbers.Text = itemsCount.ToString("#,#");
            txtSumProfit.Text  = totalProfit.ToString("#,#");
        }
Пример #3
0
        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);
            }
        }
Пример #4
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;
        }
Пример #5
0
        private void SellFactorForm_Load(object sender, EventArgs e)
        {
            var db = new shampazEntities();

            if (EditedFactor == null)
            {
                pdpDate.GeorgianDate = DateTime.Now;
                SelectedPerson       = db.Persons.FirstOrDefault();
                calculateAndSetTotalPrice();
            }
            else
            {
                SelectedPerson       = EditedFactor.Person;
                pdpDate.GeorgianDate = EditedFactor.Date;
                lblFactorId.Text     = EditedFactor.Id.ToString();
                txtDescription.Text  = EditedFactor.Description;
                txtTotalPrice.Text   = EditedFactor.TotalPrice.ToString("#,#");
                txtPayment.Text      = EditedFactor.PaymentPrice.ToString("#,#");

                foreach (var item in EditedFactor.BuyFactorItems)
                {
                    dgvItems.Rows.Add(item.Product.Id, item.Product.Name, item.Price, item.Quantity, item.TotalPrice);
                }
            }

            btnPerson.Text = SelectedPerson.Name;
        }
Пример #6
0
        private int getTurn()
        {
            var      db = new shampazEntities();
            DateTime to = pdpDate.GeorgianDate.Value + new TimeSpan(23, 59, 59);

            return(db.SellFactors.Where(x => x.Date >= pdpDate.GeorgianDate && x.Date <= to && x.Id <= EditedSellFactor.Id).Count());
        }
Пример #7
0
        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();
        }
Пример #8
0
        private void dgvFactorsRefresh()
        {
            dgvFactors.Rows.Clear();

            var db      = new shampazEntities();
            var to      = pDateTo.GeorgianDate + new TimeSpan(23, 59, 59);
            var factors = db.SellFactors.Where(x => x.Date >= pDateFrom.GeorgianDate && x.Date <= to).ToList();

            txtFactorsCount.Text = factors.Count.ToString("#,#");

            var     itemsCount = 0;
            decimal totalPrice = 0;

            foreach (var factor in factors)
            {
                PersianCalendar pc    = new PersianCalendar();
                string          pDate = string.Format("{0}/{1}/{2}", pc.GetYear(factor.Date), pc.GetMonth(factor.Date), pc.GetDayOfMonth(factor.Date));
                string          pTime = string.Format("{0}:{1}", pc.GetHour(factor.Date), pc.GetMinute(factor.Date));

                var numbers = factor.SellFactorItems.Sum(x => x.Numbers);
                dgvFactors.Rows.Add(factor.Id, pDate, pTime, factor.Person.Name, numbers, factor.TotalPrice.ToString("#,#"));

                itemsCount += numbers;
                totalPrice += factor.TotalPrice;
            }

            txtFactorItemsCount.Text  = itemsCount.ToString("#,#");
            txtFactorsTotalPrice.Text = totalPrice.ToString("#,#");
        }
Пример #9
0
        private void SellFactorForm_Load(object sender, EventArgs e)
        {
            var db = new shampazEntities();

            if (EditedSellFactor == null)
            {
                pdpDate.GeorgianDate = DateTime.Now;
                SelectedPerson       = db.Persons.FirstOrDefault();
                calculateAndSetTotalPrice();
            }
            else
            {
                SelectedPerson       = EditedSellFactor.Person;
                pdpDate.GeorgianDate = EditedSellFactor.Date;
                lblFactorId.Text     = EditedSellFactor.Id.ToString();
                txtDescription.Text  = EditedSellFactor.Description;
                txtTotalPrice.Text   = EditedSellFactor.TotalPrice.ToString("#,#");
                dtpTime.Value        = EditedSellFactor.Date;

                foreach (var item in EditedSellFactor.SellFactorItems)
                {
                    dgvItems.Rows.Add(item.Product.Id, item.Product.Name, item.Price, item.Numbers, item.TotalPrice);
                }

                btnPrint.Enabled          = true;
                btnKitchenReceipt.Enabled = true;
                btnNobat.Enabled          = true;

                lblTurn.Text = "نوبت : " + getTurn().ToString();
            }

            btnPerson.Text = SelectedPerson.Name;
        }
Пример #10
0
        private void dgvFactorsRefresh()
        {
            dgvFactors.Rows.Clear();

            var db = new shampazEntities();
            var to = pDateTo.GeorgianDate + new TimeSpan(23, 59, 59);

            //var items = from factor in db.SellFactors
            //           where factor.Date >= pDateFrom.GeorgianDate && factor.Date <= to
            //           select factor;

            //MessageBox.Show(items.Count().ToString());
            //return;

            var rows = from factor in db.SellFactors
                       where DbFunctions.TruncateTime(factor.Date) >= pDateFrom.GeorgianDate && DbFunctions.TruncateTime(factor.Date) <= pDateTo.GeorgianDate
                       group factor by DbFunctions.TruncateTime(factor.Date) into g
                       select new
            {
                Date            = g.Key,
                FactorsQuantity = g.Count(),
                ItemsQuantity   = g.Select(w => w.SellFactorItems.Sum(s => s.Numbers)).Sum(),
                TotalPrice      = g.Select(t => t.TotalPrice).Sum()
            };


            //where factor.Date >= pDateFrom.GeorgianDate && factor.Date <= to
            //group factor by DbFunctions.TruncateTime(factor.Date) into g

            //select new
            // {
            //    Date = g.Key,
            //    FactorsQuantity = g.Count(),
            //    Items = g.Select(w => w.SellFactorItems),
            //    TotalPrice = g.Select(t => t.TotalPrice).Sum()
            // };

            //txtFactorsCount.Text = factors.Count.ToString("#,#");

            var     itemsCount = 0;
            decimal totalPrice = 0;

            foreach (var row in rows)
            {
                var             day   = Convert.ToDateTime(row.Date);
                PersianCalendar pc    = new PersianCalendar();
                string          pDate = string.Format("{0}/{1}/{2}", pc.GetYear(day), pc.GetMonth(day), pc.GetDayOfMonth(day));
                dgvFactors.Rows.Add(pDate, row.FactorsQuantity, row.ItemsQuantity, row.TotalPrice.ToString("#,#"));

                itemsCount += row.ItemsQuantity;
                totalPrice += row.TotalPrice;
            }

            txtFactorItemsCount.Text  = itemsCount.ToString("#,#");
            txtFactorsTotalPrice.Text = totalPrice.ToString("#,#");
        }
Пример #11
0
        private void dgvPersonsRefresh()
        {
            dgvPersons.Rows.Clear();

            var db = new shampazEntities();

            foreach (var p in db.Persons.ToList())
            {
                dgvPersons.Rows.Add(p.Id, p.Name, p.Mobile, p.Address);
            }
        }
Пример #12
0
        private void dgvProductsRefresh()
        {
            dgvProducts.Rows.Clear();

            var db = new shampazEntities();

            foreach (var product in db.Products.ToList())
            {
                dgvProducts.Rows.Add(product.Id, product.Name, product.Price, product.Profit);
            }
        }
Пример #13
0
 private void ProductAddForm_Load(object sender, EventArgs e)
 {
     if (EditMode)
     {
         var db = new shampazEntities();
         var p  = db.Products.Where(x => x.Id == ProductId).FirstOrDefault();
         txtName.Text   = p.Name;
         txtPrice.Text  = p.Price.ToString();
         txtProfit.Text = p.Profit.ToString();
     }
 }
Пример #14
0
        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();
        }
Пример #15
0
        private void PersonAddFrom_Load(object sender, EventArgs e)
        {
            if (EditMode)
            {
                var db = new shampazEntities();
                var p  = db.Persons.Where(x => x.Id == PersonId).FirstOrDefault();

                txtName.Text    = p.Name;
                txtMobile.Text  = p.Mobile;
                txtAddress.Text = p.Address;
            }
        }
Пример #16
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (dgvProducts.SelectedRows.Count == 0)
            {
                return;
            }

            var db = new shampazEntities();
            var id = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells["clnProductId"].Value);

            SelectedProduct = db.Products.Where(x => x.Id == id).FirstOrDefault();
            DialogResult    = DialogResult.OK;
            Close();
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dgvFactors.SelectedRows.Count == 0)
            {
                return;
            }

            var id   = Convert.ToInt32(dgvFactors.SelectedRows[0].Cells["clnId"].Value);
            var db   = new shampazEntities();
            var form = new SellFactorForm();

            form.EditedSellFactor = db.SellFactors.Where(x => x.Id == id).FirstOrDefault();
            form.ShowDialog();
        }
Пример #18
0
        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);
        }
Пример #19
0
        private void txtSerach_TextChanged(object sender, EventArgs e)
        {
            var subject = txtSerach.Text;

            var db      = new shampazEntities();
            var persons = from p in db.Persons
                          where p.Name.Contains(subject) || p.Mobile.Contains(subject) || p.Address.Contains(subject)
                          select p;

            dgvPersons.Rows.Clear();
            foreach (var p in persons)
            {
                dgvPersons.Rows.Add(p.Id, p.Name, p.Mobile, p.Address);
            }
        }
Пример #20
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            var subject = txtSearch.Text;

            var db       = new shampazEntities();
            var products = from p in db.Products
                           where p.Name.Contains(subject)
                           select p;

            dgvProducts.Rows.Clear();
            foreach (var p in products)
            {
                dgvProducts.Rows.Add(p.Id, p.Name, p.Price);
            }
        }
Пример #21
0
        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 dgvFactorsRefresh()
        {
            dgvFactors.Rows.Clear();

            var db = new shampazEntities();

            var to    = pDateTo.GeorgianDate + new TimeSpan(23, 59, 59);
            var query = from item in db.SellFactorItems
                        join f in db.SellFactors on item.SellFactorId equals f.Id
                        where f.Date >= pDateFrom.GeorgianDate && f.Date <= to
                        select new
            {
                f.PersonId,
                f.Person,
                Quantity = item.Numbers,
                item.TotalPrice
            };

            var items = (
                from item in query
                group item by item.PersonId into g
                select new
            {
                PersonId = g.Key,
                PersonName = g.Select(p => p.Person).FirstOrDefault().Name,
                Quantity = g.Select(q => q.Quantity).Sum(),
                TotalPrice = g.Select(t => t.TotalPrice).Sum()
            }
                ).ToList();

            int     itemsCount = 0;
            decimal totalPrice = 0;

            foreach (var item in items)
            {
                dgvFactors.Rows.Add(item.PersonId, item.PersonName, item.Quantity, item.TotalPrice.ToString("#,#"));
                itemsCount += item.Quantity;
                totalPrice += item.TotalPrice;
            }

            txtSumNumbers.Text = itemsCount.ToString("#,#");
            txtSumPrice.Text   = totalPrice.ToString("#,#");
        }
Пример #23
0
        private void deleteFactor(SellFactor factor)
        {
            var db = new shampazEntities();

            db.SaveChanges();
        }
Пример #24
0
        private void dgvFactorsRefresh()
        {
            dgvFactors.Rows.Clear();

            var db           = new shampazEntities();
            var to           = pDateTo.GeorgianDate + new TimeSpan(23, 59, 59);
            var factorsQuery = db.BuyFactors.Where(x => x.Date >= pDateFrom.GeorgianDate && x.Date <= to);

            //MessageBox.Show(cmbStatus.SelectedValue.ToString());
            switch (cmbStatus.SelectedValue.ToString())
            {
            case "bihesab":
                factorsQuery = factorsQuery.Where(x => x.TotalPrice == x.PaymentPrice);
                break;

            case "bestankar":
                factorsQuery = factorsQuery.Where(x => x.TotalPrice > x.PaymentPrice);
                break;

            case "bedehkar":
                factorsQuery = factorsQuery.Where(x => x.TotalPrice < x.PaymentPrice);
                break;
            }

            var factors = factorsQuery.ToList();

            txtFactorsCount.Text = factors.Count.ToString("#,#");

            double  itemsCount = 0;
            decimal totalPrice = 0;

            foreach (var factor in factors)
            {
                PersianCalendar pc    = new PersianCalendar();
                string          pDate = string.Format("{0}/{1}/{2}", pc.GetYear(factor.Date), pc.GetMonth(factor.Date), pc.GetDayOfMonth(factor.Date));

                var numbers = factor.BuyFactorItems.Sum(x => x.Quantity);

                // Status
                string status;
                if (factor.TotalPrice < factor.PaymentPrice)
                {
                    status = "بدهکار";
                }
                else if (factor.TotalPrice > factor.PaymentPrice)
                {
                    status = "بستانکار";
                }
                else
                {
                    status = "بی حساب";
                }

                var remaining = factor.TotalPrice - factor.PaymentPrice;

                dgvFactors.Rows.Add(
                    factor.Id, pDate,
                    factor.Person.Name,
                    numbers,
                    factor.TotalPrice.ToString("#,#"),
                    factor.PaymentPrice.ToString("#,#"),
                    status,
                    remaining.ToString("#,#")
                    );

                itemsCount += numbers;
                totalPrice += factor.TotalPrice;
            }

            txtFactorItemsCount.Text  = itemsCount.ToString("#,#");
            txtFactorsTotalPrice.Text = totalPrice.ToString("#,#");
        }
        private void dgvFactorsRefresh()
        {
            dgvFactors.Rows.Clear();

            var db = new shampazEntities();
            //var items = (from item in db.BuyFactorItems
            //            join f in db.BuyFactors on item.BuyFactorId equals f.Id
            //            where f.Date >= pDateFrom.GeorgianDate && f.Date <= pDateTo.GeorgianDate
            //            group f by f.PersonId into g
            //            select new
            //            {
            //                PersonId = g.Key,
            //                PersonName = g.Select(n => n.Person).FirstOrDefault().Name,
            //                TotalPrice = g.Select(t => t.TotalPrice).Distinct().Sum(),
            //                Quantity = g.Select(q => q.PersonId).Count(),
            //                PaymentPrice = g.Select(t => t.PaymentPrice).Distinct().Sum(),
            //            }).ToList();
            var to    = pDateTo.GeorgianDate + new TimeSpan(23, 59, 59);
            var query = from item in db.BuyFactorItems
                        join f in db.BuyFactors on item.BuyFactorId equals f.Id
                        where f.Date >= pDateFrom.GeorgianDate && f.Date <= to
                        select new
            {
                f.PersonId,
                f.Person,
                f.PaymentPrice,
                item.Quantity,
                item.TotalPrice,
            };

            var items = (
                from item in query
                group item by item.PersonId into g
                select new
            {
                PersonId = g.Key,
                PersonName = g.Select(n => n.Person).FirstOrDefault().Name,
                TotalPrice = g.Select(t => t.TotalPrice).Distinct().Sum(),
                Quantity = g.Select(q => q.Quantity).Sum(),
                PaymentPrice = g.Select(t => t.PaymentPrice).Distinct().Sum(),
            }
                ).ToList();

            double  itemsCount = 0;
            decimal totalPrice = 0;

            foreach (var item in items)
            {
                var    remaiming = Math.Abs(item.TotalPrice - item.PaymentPrice);
                string nature;
                // Status
                if (item.TotalPrice < item.PaymentPrice)
                {
                    nature = "بدهکار";
                }
                else if (item.TotalPrice > item.PaymentPrice)
                {
                    nature = "بستانکار";
                }
                else
                {
                    nature = "بی حساب";
                }

                dgvFactors.Rows.Add(
                    item.PersonId,
                    item.PersonName,
                    item.Quantity,
                    item.TotalPrice.ToString("#,#"),
                    item.PaymentPrice.ToString("#,#"),
                    remaiming,
                    nature
                    );
                itemsCount += item.Quantity;
                totalPrice += item.TotalPrice;
            }

            txtSumNumbers.Text = itemsCount.ToString("#,#");
            txtSumPrice.Text   = totalPrice.ToString("#,#");
        }
Пример #26
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            var db = new shampazEntities();

            db.Persons.FirstOrDefault();
        }
Пример #27
0
        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();
        }