예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateService())
            {
                return;
            }
            if (Mode == Models.EntryMode.New)
            {
                var service = new Models.CustomerService();
                service.CGST            = 0;// Convert.ToDecimal(lblCGST.Text.Trim());
                service.CustomerAddress = txtAddress.Text.Trim();
                service.CustomerName    = txtName.Text.Trim();
                service.CustomerPhone   = txtPhone.Text.Trim();
                service.Date            = dtpServiceDate.Value;
                service.GrandTotal      = Convert.ToDecimal(lblGrandTotal.Text.Trim());
                service.NetTotal        = 0; // Convert.ToDecimal(lblNetTotal.Text.Trim());
                service.Note            = "";
                service.SGST            = 0; // Convert.ToDecimal(lblSGST.Text.Trim());


                foreach (var r in grdService.Rows)
                {
                    var row = (DataGridViewRow)r;

                    var serviceId = Convert.ToInt32(row.Cells[0].Value);
                    var note      = row.Cells[2].Value.ToString();
                    var amount    = Convert.ToInt32(row.Cells[3].Value);

                    var serviceDetails = new Models.CustomerServiceDetail()
                    {
                        Amount    = amount,
                        Note      = note,
                        ServiceId = serviceId
                    };
                    service.CustomerServiceDetails.Add(serviceDetails);
                }
                db.CustomerServices.Add(service);
                db.SaveChanges();
                if (MessageBox.Show("Saved Successfully ! Do you want to print?", "Success", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    RegistryHandler objRegistryHandler = new RegistryHandler();
                    objRegistryHandler.TakeBackUp();
                    objRegistryHandler.SetPrintSetup();

                    print(service);

                    objRegistryHandler.Restore();
                }

                ClearForm();
            }
            else if (Mode == EntryMode.Edit)
            {
                var service = db.CustomerServices.Find(CustomerServiceId);
                if (service != null)
                {
                    service.CGST            = 0;// Convert.ToDecimal(lblCGST.Text.Trim());
                    service.CustomerAddress = txtAddress.Text.Trim();
                    service.CustomerName    = txtName.Text.Trim();
                    service.CustomerPhone   = txtPhone.Text.Trim();
                    service.Date            = dtpServiceDate.Value;
                    service.GrandTotal      = Convert.ToDecimal(lblGrandTotal.Text.Trim());
                    service.NetTotal        = 0; // Convert.ToDecimal(lblNetTotal.Text.Trim());
                    service.Note            = "";
                    service.SGST            = 0; // Convert.ToDecimal(lblSGST.Text.Trim());

                    service.CustomerServiceDetails.Clear();
                    foreach (var r in grdService.Rows)
                    {
                        var row = (DataGridViewRow)r;

                        var serviceId = Convert.ToInt32(row.Cells[0].Value);
                        var note      = row.Cells[2].Value.ToString();
                        var amount    = Convert.ToDouble(row.Cells[3].Value);

                        var serviceDetails = new Models.CustomerServiceDetail()
                        {
                            Amount    = Convert.ToDecimal(amount),
                            Note      = note,
                            ServiceId = serviceId
                        };
                        service.CustomerServiceDetails.Add(serviceDetails);
                    }
                    db.SaveChanges();
                    MessageBox.Show("Saved Successfully !");
                }
            }
            DialogResult = DialogResult.OK;
        }