Ejemplo n.º 1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         EmpSalary oEmpSalary = new EmpSalary();
         if (lsvEmpSalary.SelectedItems != null && lsvEmpSalary.SelectedItems.Count > 0)
         {
             oEmpSalary = (EmpSalary)lsvEmpSalary.SelectedItems[0].Tag;
             if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 using (DEWSRMEntities db = new DEWSRMEntities())
                 {
                     db.EmpSalaries.Attach(oEmpSalary);
                     db.EmpSalaries.Remove(oEmpSalary);
                     db.SaveChanges();
                 }
                 RefreshList();
             }
         }
     }
     catch (Exception Ex)
     {
         MessageBox.Show("Cannot delete item due to " + Ex.Message);
     }
 }
Ejemplo n.º 2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    int[]       selRows  = ((GridView)grdModels.MainView).GetSelectedRows();
                    DataRowView oModelID = (DataRowView)(((GridView)grdModels.MainView).GetRow(selRows[0]));
                    int         nModelID = Convert.ToInt32(oModelID["ModelID"]);
                    Model       oModel   = db.Models.FirstOrDefault(p => p.ModelID == nModelID);
                    if (nModelID > 0)
                    {
                        if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            db.Models.Attach(oModel);
                            db.Models.Remove(oModel);
                            //Save to database
                            db.SaveChanges();

                            RefreshList();
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Cannot delete item due to " + Ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    int[]       selRows    = ((GridView)grdCategorys.MainView).GetSelectedRows();
                    DataRowView oCategoryD = (DataRowView)(((GridView)grdCategorys.MainView).GetRow(selRows[0]));

                    int      nCategoryID = Convert.ToInt32(oCategoryD["CategoryID"]);
                    Category oCategory   = db.Categorys.FirstOrDefault(p => p.CategoryID == nCategoryID);

                    if (oCategory == null)
                    {
                        MessageBox.Show("select an item to delete", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        db.Categorys.Attach(oCategory);
                        db.Categorys.Remove(oCategory);
                        db.SaveChanges();
                        MessageBox.Show("Data Deleted Successfully.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        RefreshList();
                    }
                    ;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool isNew = false;
                if (!IsValid())
                {
                    return;
                }
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    if (_Expenditure.ExpenditureID <= 0)
                    {
                        RefreshObject();
                        _Expenditure.ExpenditureID = db.Expenditures.Count() > 0? db.Expenditures.Max(obj => obj.ExpenditureID) + 1:1;
                        db.Expenditures.Add(_Expenditure);
                        isNew = true;
                    }
                    else
                    {
                        _Expenditure = db.Expenditures.FirstOrDefault(obj => obj.ExpenditureID == _Expenditure.ExpenditureID);
                        RefreshObject();
                    }

                    db.SaveChanges();

                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (!isNew)
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _Expenditure = new Expenditure();
                        RefreshValue();
                        txtVoucherNo.Text = GenerateVoucher();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 5
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         User oUser = new User();
         if (lsvUsers.SelectedItems != null && lsvUsers.SelectedItems.Count > 0)
         {
             oUser = (User)lsvUsers.SelectedItems[0].Tag;
             if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 using (DEWSRMEntities db = new DEWSRMEntities())
                 {
                     db.Users.Attach(oUser);
                     db.Users.Remove(oUser);
                     db.SaveChanges();
                     RefreshList();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                int[]    selRows   = ((GridView)grdCompany.MainView).GetSelectedRows();
                Supplier oSupplier = (Supplier)(((GridView)grdCompany.MainView).GetRow(selRows[0]));

                if (oSupplier == null)
                {
                    MessageBox.Show("select an item to edit", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    db.Suppliers.Attach(oSupplier);
                    db.Suppliers.Remove(oSupplier);
                    //Save to database
                    db.SaveChanges();
                    MessageBox.Show("Data Deleted Successfully.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    RefreshList();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Cannot delete item due to " + Ex.Message);
            }
        }
Ejemplo n.º 7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                int[]       selRows        = ((GridView)grdExpenditures.MainView).GetSelectedRows();
                DataRowView oExpenditureID = (DataRowView)(((GridView)grdExpenditures.MainView).GetRow(selRows[0]));

                int         nExpenditureID = Convert.ToInt32(oExpenditureID["ID"]);
                Expenditure oExpenditure   = db.Expenditures.FirstOrDefault(p => p.ExpenditureID == nExpenditureID);

                if (oExpenditure == null)
                {
                    MessageBox.Show("select an item to delete", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    db.Expenditures.Attach(oExpenditure);
                    db.Expenditures.Remove(oExpenditure);
                    db.SaveChanges();
                    MessageBox.Show("Data Deleted Successfully.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    RefreshList();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Cannot delete item due to " + Ex.Message);
            }
        }
Ejemplo n.º 8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    if (!IsValid())
                    {
                        return;
                    }
                    using (DEWSRMEntities db = new DEWSRMEntities())
                    {
                        if (_Designation.DesignationID <= 0)
                        {
                            RefreshObject();
                            _Designation.DesignationID = db.Designations.Count() > 0 ? db.Designations.Max(obj => obj.DesignationID) + 1 : 1;
                            db.Designations.Add(_Designation);
                        }
                        else
                        {
                            _Designation = db.Designations.FirstOrDefault(obj => obj.DesignationID == _Designation.DesignationID);
                            RefreshObject();
                        }

                        db.SaveChanges();
                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (MessageBox.Show("Do you want to create another Designation?", "Create Designation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            this.Close();
                        }
                        else
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            _Designation = new Designation();
                            RefreshValue();
                            txtCode.Text = GenerateDegCode();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                bool IsNew = false;

                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    List <MenuPermission> oNewMenuPermissions = new List <MenuPermission>();
                    int id = db.MenuPermissions.Count() > 0 ? db.MenuPermissions.Max(obj => obj.MenuPermissionID) + 1 : 1;
                    RefreshObject(oNewMenuPermissions, id);
                    db.MenuPermissions.AddRange(oNewMenuPermissions);

                    foreach (MenuPermission item in _oMenuPermissions)
                    {
                        db.MenuPermissions.Attach(item);
                    }
                    db.MenuPermissions.RemoveRange(_oMenuPermissions);
                    db.SaveChanges();

                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (!IsNew)
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _MenuPermission = new MenuPermission();
                        RefreshValue();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool IsNew = false;
                if (!IsValid())
                {
                    return;
                }

                if (_CardTypeSetup.CardTypeSetupID <= 0)
                {
                    RefreshObject();
                    _CardTypeSetup.CardTypeSetupID = db.CardTypeSetups.Count() > 0 ? db.CardTypeSetups.Max(obj => obj.CardTypeSetupID) + 1 : 1;
                    db.CardTypeSetups.Add(_CardTypeSetup);
                    IsNew = true;
                }
                else
                {
                    _CardTypeSetup = db.CardTypeSetups.FirstOrDefault(obj => obj.CardTypeSetupID == _CardTypeSetup.CardTypeSetupID);
                    RefreshObject();
                }

                db.SaveChanges();
                MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (!IsNew)
                {
                    if (ItemChanged != null)
                    {
                        ItemChanged();
                    }
                    this.Close();
                }
                else
                {
                    if (ItemChanged != null)
                    {
                        ItemChanged();
                    }
                    _CardTypeSetup = new CardTypeSetup();
                    RefreshValue();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    using (DEWSRMEntities db = new DEWSRMEntities())
                    {
                        if (_EmpSalary.EmpSalaryID <= 0)
                        {
                            RefreshObject();
                            _EmpSalary.EmpSalaryID = db.EmpSalaries.Count() > 0 ? db.EmpSalaries.Max(obj => obj.EmpSalaryID) + 1 : 1;
                            db.EmpSalaries.Add(_EmpSalary);
                        }
                        else
                        {
                            _EmpSalary = db.EmpSalaries.FirstOrDefault(obj => obj.EmpSalaryID == _EmpSalary.EmpSalaryID);
                            RefreshObject();
                        }

                        db.SaveChanges();

                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (MessageBox.Show("Do you want to paid another employee salary?", "Salary Paid.", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            this.Close();
                        }
                        else
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            _EmpSalary = new EmpSalary();
                            RefreshValue();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    using (DEWSRMEntities db = new DEWSRMEntities())
                    {
                        if (_SystemInformation.SystemInfoID <= 0)
                        {
                            RefreshObject();
                            _SystemInformation.SystemInfoID = db.SystemInformations.Count() > 0 ? db.SystemInformations.Max(obj => obj.SystemInfoID) + 1 : 1;
                            db.SystemInformations.Add(_SystemInformation);
                        }
                        else
                        {
                            _SystemInformation = db.SystemInformations.FirstOrDefault(obj => obj.SystemInfoID == _SystemInformation.SystemInfoID);
                            RefreshObject();
                        }

                        db.SaveChanges();
                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //if (MessageBox.Show("Do you want to create another Customer?", "Create Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        //{
                        //    if (ItemChanged != null)
                        //    {
                        //        ItemChanged();
                        //    }
                        //    this.Close();
                        //}
                        //else
                        //{
                        //    if (ItemChanged != null)
                        //    {
                        //        ItemChanged();
                        //    }
                        //    _SystemInformation = new INVENTORY.DA.SystemInformation();
                        //    RefreshValue();

                        //}
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                bool IsNew = false;

                List <UserRole> oNewUserRoles = new List <UserRole>();
                int             id            = db.UserRoles.Count() > 0 ? db.UserRoles.Max(obj => obj.UserRoleID) + 1 : 1;
                RefreshObject(oNewUserRoles, id);
                db.UserRoles.AddRange(oNewUserRoles);

                foreach (UserRole item in _oUserRoles)
                {
                    db.UserRoles.Attach(item);
                }
                db.UserRoles.RemoveRange(_oUserRoles);
                db.SaveChanges();

                MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (!IsNew)
                {
                    if (ItemChanged != null)
                    {
                        ItemChanged();
                    }
                    this.Close();
                }
                else
                {
                    if (ItemChanged != null)
                    {
                        ItemChanged();
                    }
                    _UserRole = new UserRole();
                    RefreshValue();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 14
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    using (DEWSRMEntities db = new DEWSRMEntities())
                    {
                        if (_Employee.EmployeeID <= 0)
                        {
                            RefreshObject();
                            _Employee.EmployeeID = db.Employees.Count() > 0 ? db.Employees.Max(obj => obj.EmployeeID) + 1 : 1;
                            db.Employees.Add(_Employee);
                        }
                        else
                        {
                            _Employee = db.Employees.FirstOrDefault(obj => obj.EmployeeID == _Employee.EmployeeID);
                            RefreshObject();
                        }

                        db.SaveChanges();

                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (MessageBox.Show("Do you want to create another Employee?", "Create Employee", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            this.Close();
                        }
                        else
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            _Employee = new Employee();
                            RefreshValue();
                            txtEmpCode.Text = GenerateEmpCode();
                        }
                    }
                }
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }
Ejemplo n.º 15
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }

            if (MessageBox.Show("Do you want to send SMS?", "Send SMS", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    IQueryable <Customer> CustomerList = null;

                    if (chkSendToAllCustomer.Checked)
                    {
                        CustomerList = db.Customers;
                    }
                    else if (ctlCustomer._IDList != null)
                    {
                        CustomerList = db.Customers.Where(i => ctlCustomer.IDList.Contains(i.CustomerID));
                    }
                    else
                    {
                        CustomerList = db.Customers.Where(i => i.CustomerType == (int)cboCustomerType.SelectedValue);
                    }

                    List <SMSRequest> smsList = new List <SMSRequest>();
                    SMSRequest        sms     = null;
                    foreach (var item in CustomerList)
                    {
                        sms            = new SMSRequest();
                        sms.CustomerID = item.CustomerID;
                        sms.MobileNo   = item.ContactNo;
                        sms.SMS        = txtSMS.Text;
                        sms.SMSType    = EnumSMSType.Offer;
                        smsList.Add(sms);
                    }

                    var response = await Task.Run(() => SMSHTTPService.SendSMSAsync(EnumtestbdType.NumberSms, smsList, Global.SystemInfo));

                    if (response.Count > 0)
                    {
                        db.SMSStatuses.AddRange(response);
                        db.SaveChanges();
                        MessageBox.Show("Successfully sent SMS: " + response.Where(i => i.SendingStatus == (int)EnumSMSSendStatus.Success).Count() + " ,Failed: " + response.Where(i => i.SendingStatus == (int)EnumSMSSendStatus.Fail).Count(), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to send", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 16
0
 public void ReturnBankDepositTransaction(int BankTranID)
 {
     if (BankTranID != 0)
     {
         using (var dbC = new DEWSRMEntities())
         {
             var BankTrans = dbC.BankTransactions.FirstOrDefault(i => i.BankTranID == BankTranID);
             if (BankTrans != null)
             {
                 var bank = dbC.Banks.FirstOrDefault(i => i.BankID == BankTrans.BankID);
                 bank.TotalAmount -= BankTrans.Amount;
                 dbC.BankTransactions.Remove(BankTrans);
                 dbC.SaveChanges();
             }
         }
     }
 }
Ejemplo n.º 17
0
 private void btnStockEdit_Click(object sender, EventArgs e)
 {
     try
     {
         if (StockID > 0)
         {
             if (numCurrPrice.Value > 0)
             {
                 oSTUpdate.PMPrice = numChangePrice.Value;
                 db.SaveChanges();
                 RefreshStock();
                 MessageBox.Show("Successfully Price Update.");
             }
         }
         else
         {
             MessageBox.Show("Please select stock entry for update Purchase Rate.", "Stock Update");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                bool IsNew = false;

                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    if (_Product.ProductID <= 0)
                    {
                        _Product.ProductID = db.Products.Count() > 0 ? db.Products.Max(obj => obj.ProductID) + 1 : 1;
                        RefreshObject();

                        if (txtName.Text.Length > 0)
                        {
                            Product oProductInfo = null;
                            oProductInfo = (Product)db.Products.FirstOrDefault(o => o.ProductName.Trim().ToUpper() == txtName.Text.Trim().ToUpper() && (o.CompanyID == _Product.CompanyID) && (o.CategoryID == _Product.CategoryID) && (o.ModelID == _Product.ModelID) && (o.UnitType == _Product.UnitType));

                            if (oProductInfo != null)
                            {
                                MessageBox.Show("This product already exists", "Duplicate Product", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtName.Focus();
                                return;
                            }
                        }

                        db.Products.Add(_Product);
                        IsNew = true;
                    }
                    else
                    {
                        _Product = db.Products.FirstOrDefault(obj => obj.ProductID == _Product.ProductID);
                        RefreshObject();
                    }

                    db.SaveChanges();
                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (ItemChanged != null)
                    {
                        ItemChanged();
                    }

                    if (!IsNew)
                    {
                        this.Close();
                    }
                    else
                    {
                        _Product = new Product();
                        //RefreshValue();
                        txtCode.Text = GenerateProductCode();
                        //pbxEmpPic.Image = null;
                        txtName.Text    = "";
                        numMinQTY.Value = 0;
                        numBQty.Value   = 0;

                        RefreshControl();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 19
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool isNew = false;
                if (!IsValid())
                {
                    return;
                }
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    if (_ShareInvestmentHead.SIHID <= 0)
                    {
                        #region Validation Check
                        if (txtName.Text.Length > 0)
                        {
                            ShareInvestmentHead oShareInvestmentHead = (ShareInvestmentHead)(db.ShareInvestmentHeads.FirstOrDefault(o => o.Name.Trim().ToUpper() == txtName.Text.Trim().ToUpper()));
                            if (oShareInvestmentHead != null)
                            {
                                MessageBox.Show("Investment name already Exists.", "Duplicate Invest Item.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtName.Focus();
                                return;
                            }
                        }

                        #endregion

                        RefreshObject();
                        _ShareInvestmentHead.SIHID = db.ShareInvestmentHeads.Count() > 0 ? db.ShareInvestmentHeads.Max(obj => obj.SIHID) + 1 : 1;
                        db.ShareInvestmentHeads.Add(_ShareInvestmentHead);
                        isNew = true;
                    }
                    else
                    {
                        _ShareInvestmentHead = db.ShareInvestmentHeads.FirstOrDefault(obj => obj.SIHID == _ShareInvestmentHead.SIHID);
                        RefreshObject();
                    }

                    db.SaveChanges();
                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (!isNew)
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _ShareInvestmentHead = new ShareInvestmentHead();
                        RefreshValue();
                        txtCode.Text = GenerateInvestCode();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 20
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    int[]       selRows = ((GridView)grdBanks.MainView).GetSelectedRows();
                    DataRowView oBankD  = (DataRowView)(((GridView)grdBanks.MainView).GetRow(selRows[0]));

                    int  nBankID = Convert.ToInt32(oBankD["BankID"]);
                    Bank oBank   = db.Banks.FirstOrDefault(p => p.BankID == nBankID);

                    if (oBank == null)
                    {
                        MessageBox.Show("select an item to delete", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        db.Banks.Attach(oBank);
                        db.Banks.Remove(oBank);
                        db.SaveChanges();
                        MessageBox.Show("Data Deleted Successfully.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        RefreshList();
                    }
                    ;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            //try
            //{
            //    Category oCategory = new Category();
            //    if (lsvCategory.SelectedItems != null && lsvCategory.SelectedItems.Count > 0)
            //    {
            //        oCategory = (Category)lsvCategory.SelectedItems[0].Tag;
            //        if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
            //            MessageBoxIcon.Question) == DialogResult.Yes)
            //        {
            //            using (DEWSRMEntities db = new DEWSRMEntities())
            //            {
            //                db.Categorys.Attach(oCategory);
            //                db.Categorys.Remove(oCategory);
            //                //Save to database
            //                db.SaveChanges();
            //            }
            //            RefreshList();
            //        }
            //    }

            //}
            //catch (Exception Ex)
            //{
            //    MessageBox.Show("Cannot delete item due to " + Ex.Message);
            //}
        }
Ejemplo n.º 21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                #region Save Return
                if (_Return.ReturnID <= 0)
                {
                    RefreshObject();
                    #region Return Orders

                    _Return.ReturnID    = db.Returns.Count() > 0 ? db.Returns.Max(obj => obj.ReturnID) + 1 : 1;
                    _Return.CreatedBy   = Global.CurrentUser.UserID;
                    _Return.CreatedDate = DateTime.Now;
                    int detailid    = db.ReturnDetails.Count() > 0 ? db.ReturnDetails.Max(obj => obj.ReturnDetailsID) + 1 : 1;
                    var ProductList = db.Products.ToList();

                    foreach (ReturnDetail item in _ReturnDetails)
                    {
                        item.ReturnDetailsID = detailid;
                        item.ReturnID        = _Return.ReturnID;
                        db.ReturnDetails.Add(item);
                        detailid++;
                    }
                    db.Returns.Add(_Return);

                    #endregion

                    #region Stock Updates
                    foreach (ReturnDetail item in _ReturnDetails)
                    {
                        _TranStock       = null;
                        _TranStockDetail = null;
                        _TranStockDetail = db.StockDetails.FirstOrDefault(o => o.SDetailID == item.SDetailID);
                        _TranStock       = db.Stocks.FirstOrDefault(o => o.ProductID == item.ProductID && o.ColorID == _TranStockDetail.ColorID);

                        var oProduct = ProductList.FirstOrDefault(i => i.ProductID == item.ProductID);
                        if (oProduct.ProductType == (int)EnumProductType.NoBarCode)
                        {
                            _TranStockDetail.Quantity -= (decimal)item.Quantity;
                            if (_TranStockDetail.Quantity == 0)
                            {
                                _TranStockDetail.Status = (int)EnumStockDetailStatus.Sold;
                            }
                        }
                        else
                        {
                            _TranStockDetail.Status = (int)EnumStockDetailStatus.Sold;
                        }

                        _TranStock.Quantity  = _TranStock.Quantity - (decimal)item.Quantity;
                        _TranStock.EntryDate = DateTime.Today;
                        #endregion

                        #region Update Supplier Due Amount

                        _oSupplier          = (Supplier)(db.Suppliers.FirstOrDefault(o => o.SupplierID == _Return.SupplierID));
                        _oSupplier.TotalDue = numPrevDue.Value - numTotalDueAmt.Value;

                        #endregion

                        //_oCustomer = (Customer)(db.Customers.FirstOrDefault(o => o.CustomerID == _Return.CustomerID));
                        //_oCustomer.TotalDue = numPrevDue.Value - (numTotalDueAmt.Value);
                    }
                }
                else //Update
                {
                    int detailid = db.ReturnDetails.Count() > 0 ? db.ReturnDetails.Max(obj => obj.ReturnDetailsID) + 1 : 1;
                    RefreshObject();

                    _Return.ModifiedBy   = (int)Global.CurrentUser.UserID;
                    _Return.ModifiedDate = (DateTime)DateTime.Today;

                    if (_RemoveReturnDetail != null)
                    {
                        foreach (ReturnDetail item in _RemoveReturnDetail)
                        {
                            //_TranStock = db.Stocks.FirstOrDefault(o => o.ProductID == item.ProductID && o.GodownID == item.GodownID);
                            _TranStockDetail          = db.StockDetails.FirstOrDefault(o => o.ProductID == item.ProductID && o.SDetailID == item.SDetailID);
                            _TranStock                = db.Stocks.FirstOrDefault(o => o.ProductID == item.ProductID && o.ColorID == _TranStockDetail.ColorID);
                            _TranStock.Quantity       = _TranStock.Quantity + (decimal)item.Quantity;
                            _TranStock.EntryDate      = DateTime.Today;
                            _TranStockDetail.Quantity = _TranStockDetail.Quantity + item.Quantity;
                            #region Update Supplier Due Amount

                            _oSupplier          = (Supplier)(db.Suppliers.FirstOrDefault(o => o.SupplierID == _Return.SupplierID));
                            _oSupplier.TotalDue = numPrevDue.Value + _currentCredit - numTotalDueAmt.Value;

                            #endregion

                            //_oCustomer = (Customer)(db.Customers.FirstOrDefault(o => o.CustomerID == _Return.CustomerID));
                            //_oCustomer.TotalDue = numPrevDue.Value + _currentCredit - numTotalDueAmt.Value;

                            db.SaveChanges();
                            db.ReturnDetails.Remove(item);
                        }
                    }

                    foreach (ReturnDetail item in _ReturnDetails)
                    {
                        if (item.ReturnDetailsID <= 0)
                        {
                            item.ReturnDetailsID = detailid;
                            item.ReturnID        = _Return.ReturnID;
                            db.ReturnDetails.Add(item);
                            detailid++;
                        }
                    }
                }

                RefreshObject();
                db.SaveChanges();
                MessageBox.Show("Returned successfully.", "Return Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                #endregion
                GenerateReturnInvoice(_Return);
                ItemChanged();
                numPrevDue.Value     = 0;
                numTotalDueAmt.Value = 0;

                _Return        = new Return();
                _ReturnDetails = new List <ReturnDetail>();
                RefreshValue();
                RefreshControl();
                RefreshGrid();
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
            //RefreshStock();
            //RefreshCustomerDue();
            //RefreshSupplierDue();
        }
Ejemplo n.º 22
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                bool isNew = false;
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    if (_Godown.GodownID <= 0)
                    {
                        #region Validaton Check
                        if (txtName.Text.Length > 0)
                        {
                            Godown oGodown = (Godown)(db.Godowns.FirstOrDefault(o => o.GodownName.Trim().ToUpper() == txtName.Text.Trim().ToUpper()));
                            if (oGodown != null)
                            {
                                MessageBox.Show("This Godown already exists.", "Duplicate Godown.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtName.Focus();
                                return;
                            }
                        }
                        #endregion

                        RefreshObject();
                        _Godown.GodownID = db.Godowns.Count() > 0 ? db.Godowns.Max(obj => obj.GodownID) + 1 : 1;
                        db.Godowns.Add(_Godown);
                        isNew = true;
                    }
                    else
                    {
                        _Godown = db.Godowns.FirstOrDefault(obj => obj.GodownID == _Godown.GodownID);
                        RefreshObject();
                    }

                    db.SaveChanges();
                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (!isNew)
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _Godown = new Godown();
                        RefreshValue();
                        txtCode.Text = GenerateCode();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 23
0
        private void btnReturn_Click(object sender, EventArgs e)
        {
            try
            {
                int[]       selRows     = ((GridView)grdOrders.MainView).GetSelectedRows();
                DataRowView oOrderID    = (DataRowView)((GridView)grdOrders.MainView).GetRow(selRows[0]);
                DataRowView InvoiceDate = (DataRowView)(((GridView)grdOrders.MainView).GetRow(selRows[0]));

                int      nOrdersID    = Convert.ToInt32(oOrderID["OrderID"]);
                DateTime dInvoiceDate = Convert.ToDateTime(InvoiceDate["OrderDate"]);

                List <Stock>       oStockList  = db.Stocks.ToList();
                List <StockDetail> oStockDList = db.StockDetails.ToList();

                if (nOrdersID <= 0)
                {
                    MessageBox.Show("Select an item to cancel order.", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (Global.CurrentUser.ISEditable == 1)
                {
                    if (dInvoiceDate < DateTime.Today)
                    {
                        MessageBox.Show("This order can't be return, Please contact BD Team", "Unauthorized Access", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                if (MessageBox.Show("Do you want to return this order sure?", "Return Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (nOrdersID > 0)
                    {
                        _Order = db.SOrders.FirstOrDefault(s => s.SOrderID == nOrdersID);

                        if (_Order.Status == (int)EnumSalesType.Return)
                        {
                            MessageBox.Show("This item already return please select correct item.", "Return Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                        #region Update SOrder Data
                        _Order.Status = (int)EnumSalesType.Return;
                        #endregion

                        #region Stock Data
                        Stock       oStock       = null;
                        StockDetail oStockDetail = null;
                        Product     oProduct     = null;
                        foreach (SOrderDetail sODetail in _Order.SOrderDetails)
                        {
                            oProduct     = db.Products.FirstOrDefault(i => i.ProductID == sODetail.ProductID);
                            oStockDetail = oStockDList.FirstOrDefault(sd => sd.SDetailID == sODetail.StockDetailID);

                            if (oStockDetail != null)
                            {
                                oStock = oStockList.FirstOrDefault(o => o.ProductID == sODetail.ProductID && o.StockID == oStockDetail.StockID);
                            }

                            oStock.Quantity     = oStock.Quantity + sODetail.Quantity;
                            oStockDetail.Status = (int)EnumStockDetailStatus.Stock;
                            if (oProduct.ProductType == (int)EnumProductType.NoBarCode)
                            {
                                oStockDetail.Quantity += sODetail.Quantity;
                            }
                        }
                        #endregion

                        #region Update Customer Due Amount

                        Customer oCustomer = db.Customers.FirstOrDefault(c => c.CustomerID == _Order.CustomerID);
                        if (oCustomer != null)
                        {
                            oCustomer.TotalDue = (decimal)(oCustomer.TotalDue - _Order.PaymentDue);
                        }
                        #endregion

                        #region Bank Transactions and Bank Update
                        if (_Order.BankTranID != 0)
                        {
                            FCreditSales bankdepo = new FCreditSales();
                            bankdepo.ReturnBankDepositTransaction(_Order.BankTranID);
                        }
                        #endregion

                        db.SaveChanges();
                        MessageBox.Show("Order return successfully.", "Return Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        RefreshList();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 24
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                bool IsNew = false;
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    if (_Company.CompanyID <= 0)
                    {
                        if (txtName.Text.Length > 0)
                        {
                            Company oCompany = (Company)(db.Companies.FirstOrDefault(o => o.Description.Trim().ToUpper() == txtName.Text.Trim().ToUpper()));

                            if (oCompany != null)
                            {
                                MessageBox.Show("This Company already exists.", "Duplicate Company.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtName.Focus();
                                return;
                            }
                        }
                        RefreshObject();
                        _Company.CompanyID = db.Companies.Count() > 0 ? db.Companies.Max(obj => obj.CompanyID) + 1 : 1;
                        db.Companies.Add(_Company);
                        IsNew = true;
                    }
                    else
                    {
                        _Company = db.Companies.FirstOrDefault(obj => obj.CompanyID == _Company.CompanyID);
                        RefreshObject();
                    }

                    db.SaveChanges();
                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (!IsNew)
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _Company = new Company();
                        RefreshValue();
                        txtCode.Text = GenerateCode();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 25
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                bool IsNew = false;
                using (DEWSRMEntities db = new DEWSRMEntities())
                {
                    //if (_Bank.BankID <= 0)
                    //{
                    //    if (txtName.Text.Length > 0)
                    //    {
                    //        Bank oBank = null;

                    //        oBank = (Bank)db.Banks.FirstOrDefault(o => o.BankName.Trim().ToUpper() == txtName.Text.Trim().ToUpper());
                    //        if (oBank != null)
                    //        {
                    //            MessageBox.Show("This Bank already Exists.", "Duplicate Category", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //            txtName.Focus();
                    //            return;
                    //        }
                    //    }
                    //}
                    if (_Bank.BankID <= 0)
                    {
                        RefreshObject();
                        _Bank.BankID = db.Banks.Count() > 0 ? db.Banks.Max(obj => obj.BankID) + 1 : 1;
                        db.Banks.Add(_Bank);
                        IsNew = true;
                    }
                    else
                    {
                        _Bank = db.Banks.FirstOrDefault(obj => obj.BankID == _Bank.BankID);
                        RefreshObject();
                    }

                    db.SaveChanges();
                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (!IsNew)
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _Bank = new Bank();
                        RefreshValue();
                        txtCode.Text = GenerateCategoryCode();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 26
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    bool isNew = false;

                    #region Stock
                    if (_stock != null)
                    {
                        _stock.Quantity = _stock.Quantity - numQTY.Value;
                    }

                    if (_StockDetail != null)
                    {
                        _StockDetail.Status = (int)EnumStockDetailStatus.Damage;
                    }

                    //if (_oProduct.IsBarCode == 3)
                    //{
                    //    if (numStock.Value == 0)
                    //    {
                    //        _StockDetail.Status = (int)EnumStockDetailStatus.Sold;
                    //    }
                    //}
                    //else
                    //{
                    //    _StockDetail.Status = (int)EnumStockDetailStatus.Sold;
                    //}

                    #endregion

                    if (_DamageProduct.DamageProID <= 0)
                    {
                        RefreshObject();
                        _DamageProduct.CreatedBy  = Global.CurrentUser.UserID;
                        _DamageProduct.CreateDate = DateTime.Now;
                        _DamageProduct.SDetailID  = _StockDetail.SDetailID;
                        //_DamageProduct.DamageProID = db.DamageProducts.Count() > 0 ? db.DamageProducts.Max(obj => obj.DamageProID) + 1 : 1;
                        db.DamageProducts.Add(_DamageProduct);
                        isNew = true;
                    }
                    else
                    {
                        _DamageProduct = db.DamageProducts.FirstOrDefault(obj => obj.DamageProID == _DamageProduct.DamageProID);
                        RefreshObject();
                        _DamageProduct.SDetailID    = ctlProduct.SelectedID;
                        _DamageProduct.ModifiedDate = (DateTime)DateTime.Today;
                        _DamageProduct.ModifiedBy   = (int)Global.CurrentUser.UserID;
                    }

                    db.SaveChanges();
                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (!isNew)
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _DamageProduct = new DamageProduct();
                        RefreshValue();
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 27
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    if (_CashCollection.CashCollectionID <= 0)
                    {
                        RefreshObject();
                        _CashCollection.CashCollectionID = db.CashCollections.Count() > 0 ? db.CashCollections.Max(obj => obj.CashCollectionID) + 1 : 1;
                        db.CashCollections.Add(_CashCollection);

                        if (_oCustomer != null)
                        {
                            _oCustomer.TotalDue -= (decimal)_CashCollection.Amount + (decimal)_CashCollection.AdjustAmt;
                        }
                    }
                    else
                    {
                        _CashCollection = db.CashCollections.FirstOrDefault(obj => obj.CashCollectionID == _CashCollection.CashCollectionID);
                        RefreshObject();

                        if (_oCustomer != null)
                        {
                            _oCustomer.TotalDue  = _oCustomer.TotalDue + PrvCashCollAmt;
                            _oCustomer.TotalDue -= ((decimal)_CashCollection.Amount + _CashCollection.AdjustAmt);
                        }
                    }

                    db.SaveChanges();

                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (MessageBox.Show("Do you want to create another Collection?", "Create Collection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        if (_oCustomer != null)
                        {
                            MoneyReceipt(_CashCollection);
                        }
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (_oCustomer != null)
                        {
                            MoneyReceipt(_CashCollection);
                        }
                        if (ItemChanged != null)
                        {
                            ItemChanged();
                        }
                        _CashCollection = new CashCollection();
                        RefreshValue();
                        txtReceiptNo.Text = GenerateReceipt();
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 28
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool IsNew = false;
                if (!IsValid())
                {
                    return;
                }

                if (_BankTransaction.BankTranID <= 0)
                {
                    RefreshObject();



                    if (_BankTransaction.TransactionType == 1)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;



                        Previous          = Previous + (double)_BankTransaction.Amount;
                        oBank.TotalAmount = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 2)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;

                        if (Previous < (double)_BankTransaction.Amount)
                        {
                            MessageBox.Show("Amount is not availabe", "Bank Amount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            numRPAmount.Focus();
                            return;
                        }

                        Previous          = Previous - (double)_BankTransaction.Amount;
                        oBank.TotalAmount = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 3)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;
                        Previous          = Previous + (double)_BankTransaction.Amount;
                        oBank.TotalAmount = (decimal)Previous;


                        Previous = (double)_Customer.TotalDue;


                        Previous           = Previous - (double)_BankTransaction.Amount;
                        _Customer.TotalDue = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 4)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;

                        if (Previous < (double)_BankTransaction.Amount)
                        {
                            MessageBox.Show("Amount is not availabe", "Bank Amount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            numRPAmount.Focus();
                            return;
                        }

                        Previous          = Previous - (double)_BankTransaction.Amount;
                        oBank.TotalAmount = (decimal)Previous;


                        Previous           = (double)_Supplier.TotalDue;
                        Previous           = Previous - (double)_BankTransaction.Amount;
                        _Supplier.TotalDue = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 5)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;
                        Previous = Previous - (double)_BankTransaction.Amount;
                        if (Previous < (double)_BankTransaction.Amount)
                        {
                            MessageBox.Show("Amount is not availabe", "Bank Amount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            numRPAmount.Focus();
                            return;
                        }
                        if (ctlBank.SelectedID == ctlAnotherBank.SelectedID)
                        {
                            MessageBox.Show("Fund Transfer to same bank is not possible", "Fund Transfer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ctlAnotherBank.Focus();
                            return;
                        }
                        oBank.TotalAmount = (decimal)Previous;



                        Previous = (double)_AnotherBank.TotalAmount;
                        Previous = Previous + (double)_BankTransaction.Amount;
                        _AnotherBank.TotalAmount = (decimal)Previous;
                    }

                    _BankTransaction.BankTranID = db.BankTransactions.Count() > 0 ? db.BankTransactions.Max(obj => obj.BankTranID) + 1 : 1;
                    db.BankTransactions.Add(_BankTransaction);

                    IsNew = true;
                }
                else
                {
                    if (_BankTransaction.TransactionType == 1)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;

                        double changeAmt = (double)numRPAmount.Value - (double)numEditAmt.Value;

                        Previous          = Previous + changeAmt - (double)numEditAmt.Value;
                        oBank.TotalAmount = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 2)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;

                        if (Previous < (double)_BankTransaction.Amount)
                        {
                            MessageBox.Show("Amount is not availabe", "Bank Amount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            numRPAmount.Focus();
                            return;
                        }
                        double changeAmt = (double)numRPAmount.Value - (double)numEditAmt.Value;

                        Previous          = Previous - changeAmt - (double)numEditAmt.Value;
                        oBank.TotalAmount = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 3)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;
                        Previous          = Previous + (double)_BankTransaction.Amount;
                        oBank.TotalAmount = (decimal)Previous;


                        Previous = (double)_Customer.TotalDue;
                        double changeAmt = (double)numRPAmount.Value - (double)numEditAmt.Value;

                        Previous           = Previous - changeAmt - (double)numEditAmt.Value;
                        _Customer.TotalDue = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 4)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;
                        Previous          = Previous - (double)_BankTransaction.Amount;
                        oBank.TotalAmount = (decimal)Previous;


                        Previous = (double)_Supplier.TotalDue;
                        double changeAmt = (double)numRPAmount.Value - (double)numEditAmt.Value;
                        Previous           = Previous - changeAmt - (double)numEditAmt.Value;
                        _Supplier.TotalDue = (decimal)Previous;
                    }
                    else if (_BankTransaction.TransactionType == 5)
                    {
                        Bank   oBank    = db.Banks.FirstOrDefault(o => o.BankID == _BankTransaction.BankID);
                        double Previous = (double)oBank.TotalAmount;
                        Previous = Previous - (double)_BankTransaction.Amount;
                        if (Previous < (double)_BankTransaction.Amount)
                        {
                            MessageBox.Show("Amount is not availabe", "Bank Amount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            numRPAmount.Focus();
                            return;
                        }
                        if (ctlBank.SelectedID == ctlAnotherBank.SelectedID)
                        {
                            MessageBox.Show("Fund Transfer to same bank is not possible", "Fund Transfer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ctlAnotherBank.Focus();
                            return;
                        }
                        oBank.TotalAmount = (decimal)Previous;



                        Previous = (double)_AnotherBank.TotalAmount;
                        double changeAmt = (double)numRPAmount.Value - (double)numEditAmt.Value;
                        Previous = Previous + changeAmt;
                        _AnotherBank.TotalAmount = (decimal)Previous;
                    }


                    _BankTransaction = db.BankTransactions.FirstOrDefault(obj => obj.BankTranID == _BankTransaction.BankTranID);
                    RefreshObject();
                }



                db.SaveChanges();
                MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (!IsNew)
                {
                    if (ItemChanged != null)
                    {
                        ItemChanged();
                    }
                    this.Close();
                }
                else
                {
                    if (ItemChanged != null)
                    {
                        ItemChanged();
                    }
                    _BankTransaction = new BankTransaction();
                    RefreshValue();
                }
                //}
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 29
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    if (!IsValid())
                    {
                        return;
                    }

                    using (DEWSRMEntities db = new DEWSRMEntities())
                    {
                        if (_User.UserID <= 0)
                        {
                            if (txtUserName.Text.Length > 0)
                            {
                                User oUser = (User)(db.Users.FirstOrDefault(o => o.UserName.Trim().ToUpper() == txtUserName.Text.Trim().ToUpper()));

                                if (oUser != null)
                                {
                                    MessageBox.Show("This User already exists.", "Duplicate User.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    txtUserName.Focus();
                                    return;
                                }
                            }

                            RefreshObject();
                            _User.UserID = db.Users.Count() > 0 ? db.Users.Max(obj => obj.UserID) + 1 : 1;
                            db.Users.Add(_User);
                        }
                        else
                        {
                            _User = db.Users.FirstOrDefault(obj => obj.UserID == _User.UserID);
                            RefreshObject();
                        }

                        db.SaveChanges();

                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (MessageBox.Show("Do you want to create another User?", "Create User", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            this.Close();
                        }
                        else
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            _User = new User();
                            RefreshValue();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                CreditSale oCreditSale = new CreditSale();
                _oFCreditSale = new FCreditSale();

                List <Stock>       oStockList  = db.Stocks.ToList();
                List <StockDetail> oStockDList = db.StockDetails.ToList();

                int[]       selRows = ((GridView)grdCreditSalesCustomers.MainView).GetSelectedRows();
                DataRowView oCreditSalesCustomerD = (DataRowView)(((GridView)grdCreditSalesCustomers.MainView).GetRow(selRows[0]));

                int nCreditSalesCustomerID = Convert.ToInt32(oCreditSalesCustomerD["CreditSalesID"]);

                Product     oProduct     = null;
                Stock       oStock       = null;
                StockDetail oStockDetail = null;

                if (nCreditSalesCustomerID > 0)
                {
                    oCreditSale = db.CreditSales.FirstOrDefault(p => p.CreditSalesID == nCreditSalesCustomerID);
                    if (oCreditSale != null)
                    {
                        if (MessageBox.Show("Do you want to return the selected item?", "Return Item", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            List <CreditSaleProduct> CSP = db.CreditSaleProducts.Where(cp => cp.CreditSalesID == oCreditSale.CreditSalesID).ToList();

                            foreach (CreditSaleProduct item in CSP)
                            {
                                oProduct     = db.Products.FirstOrDefault(i => i.ProductID == item.ProductID);
                                oStockDetail = oStockDList.FirstOrDefault(sd => sd.SDetailID == item.StockDetailID);

                                if (oStockDetail != null)
                                {
                                    oStock = oStockList.FirstOrDefault(o => o.ProductID == item.ProductID && o.StockID == oStockDetail.StockID);
                                }

                                oStock.Quantity     = (decimal)(oStock.Quantity + item.Quantity);
                                oStockDetail.Status = (int)EnumStockDetailStatus.Stock;
                                if (oProduct.ProductType == (int)EnumProductType.NoBarCode)
                                {
                                    oStockDetail.Quantity += (decimal)item.Quantity;
                                }

                                //Stock oStock = db.Stocks.FirstOrDefault(o => o.ProductID == item.ProductID && o.ColorID == item.ColorInfoID);
                            }

                            List <CreditSalesDetail> CSD = db.CreditSalesDetails.Where(o => o.CreditSalesID == oCreditSale.CreditSalesID).ToList();
                            foreach (CreditSalesDetail oCSD in CSD)
                            {
                                db.CreditSalesDetails.Attach(oCSD);
                                db.CreditSalesDetails.Remove(oCSD);
                            }

                            foreach (CreditSaleProduct oCSP in CSP)
                            {
                                db.CreditSaleProducts.Attach(oCSP);
                                db.CreditSaleProducts.Remove(oCSP);
                            }

                            #region Customer Due Amount Update

                            Customer oCustomer = db.Customers.FirstOrDefault(c => c.CustomerID == oCreditSale.CustomerID);
                            if (oCustomer != null)
                            {
                                oCustomer.CreditDue = (decimal)(oCustomer.CreditDue - oCreditSale.Remaining);
                            }
                            #endregion

                            db.CreditSales.Attach(oCreditSale);
                            db.CreditSales.Remove(oCreditSale);
                            if (oCreditSale.BankTranID != 0)
                            {
                                ReturnBankDepositTransaction(oCreditSale.BankTranID);
                            }

                            db.SaveChanges();
                            RefreshList();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }