Exemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var existingProduct = uowBatch.Repository.GetAll().Where(p => p.BatchCode == txtBatchCode.Text.Trim()).FirstOrDefault();

            if (existingProduct != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtBatchCode.Text.Trim());
            }
            else
            {
                var batchToAdd = new Batch
                {
                    BatchCode   = txtBatchCode.Text.Trim(),
                    ProductId   = cbProductCode.SelectedValue.ToString(),
                    Quantity    = Convert.ToInt32(txtQuantity.Text.Trim()),
                    EntryDate   = DateTime.Parse(dtpEntryDate.Value.ToString("yyyy-MM-dd")),
                    ExpiredDate = DateTime.Parse(dtpExpiredDate.Value.ToString("yyyy-MM-dd")),

                    // Audit Fields
                    CreatedBy  = Properties.Settings.Default.CurrentUserId,
                    CreatedAt  = DateTime.Now,
                    ModifiedBy = Properties.Settings.Default.CurrentUserId,
                    ModifiedAt = DateTime.Now
                };
                uowBatch.Repository.Add(batchToAdd);
                uowBatch.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var existingTop = uowTop.Repository.GetAll().Where(t => t.TermCode == txtTermCode.Text.Trim()).FirstOrDefault();

            if (existingTop != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtTermCode.Text.Trim());
            }
            else
            {
                var topToAdd = new TermOfPayment
                {
                    TermCode    = txtTermCode.Text.Trim(),
                    Description = txtDescription.Text.Trim(),

                    // Audit Fields
                    CreatedBy  = Properties.Settings.Default.CurrentUserId,
                    CreatedAt  = DateTime.Now,
                    ModifiedBy = Properties.Settings.Default.CurrentUserId,
                    ModifiedAt = DateTime.Now
                };
                uowTop.Repository.Add(topToAdd);
                uowTop.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }
            var existingUom = uowUom.Repository.GetAll().Where(u => u.UomCode == txtUomCode.Text.Trim()).FirstOrDefault();

            if (existingUom != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtUomCode.Text.Trim());
            }
            else
            {
                var uomToAdd = new UnitOfMeasurement
                {
                    UomCode     = txtUomCode.Text.Trim(),
                    Description = txtUomDesc.Text.Trim(),

                    // Audit Fields
                    CreatedBy  = Properties.Settings.Default.CurrentUserId,
                    CreatedAt  = DateTime.Now,
                    ModifiedBy = Properties.Settings.Default.CurrentUserId,
                    ModifiedAt = DateTime.Now
                };
                uowUom.Repository.Add(uomToAdd);
                uowUom.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowTop.Repository.GetById(txtTermId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtTermCode.Text.Trim());
            }
            else
            {
                var topToUpdate = uowTop.Repository.GetById(txtTermId.Text.Trim());
                topToUpdate.TermCode    = txtTermCode.Text.Trim();
                topToUpdate.Description = txtDescription.Text.Trim();
                topToUpdate.ModifiedBy  = Properties.Settings.Default.CurrentUserId;
                topToUpdate.ModifiedAt  = DateTime.Now;

                uowTop.Repository.Update(topToUpdate);
                uowTop.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowBatch.Repository.GetById(txtBatchId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtBatchCode.Text.Trim());
            }
            else
            {
                var batchToUpdate = uowBatch.Repository.GetById(txtBatchId.Text.Trim());
                batchToUpdate.BatchCode   = txtBatchCode.Text.Trim();
                batchToUpdate.ProductId   = cbProductCode.SelectedValue.ToString();
                batchToUpdate.Quantity    = Convert.ToInt32(txtQuantity.Text.Trim());
                batchToUpdate.EntryDate   = DateTime.Parse(dtpEntryDate.Value.ToString("yyyy-MM-dd"));
                batchToUpdate.ExpiredDate = DateTime.Parse(dtpExpiredDate.Value.ToString("yyyy-MM-dd"));
                batchToUpdate.ModifiedBy  = Properties.Settings.Default.CurrentUserId;
                batchToUpdate.ModifiedAt  = DateTime.Now;

                uowBatch.Repository.Update(batchToUpdate);
                uowBatch.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 6
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }
            var existingRole = uowArea.Repository.GetAll().Where(r => r.AreaCode == txtAreaCode.Text.Trim()).FirstOrDefault();

            if (existingRole != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtAreaCode.Text.Trim());
            }
            else
            {
                var areaToAdd = new SalesArea
                {
                    AreaCode         = txtAreaCode.Text.Trim(),
                    Description      = txtDescription.Text.Trim(),
                    RepresentativeId = cbRepresentative.SelectedValue.ToString(),

                    // Audit Fields
                    CreatedBy  = Properties.Settings.Default.CurrentUserId,
                    CreatedAt  = DateTime.Now,
                    ModifiedBy = Properties.Settings.Default.CurrentUserId,
                    ModifiedAt = DateTime.Now
                };
                uowArea.Repository.Add(areaToAdd);
                uowArea.Commit();
                isAdd = true;
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            if (chkChangePassword.Checked && !txtPassword.Text.Trim().Equals(txtRetypePassword.Text.Trim()))
            {
                MessageBox.Show("Pastikan password yang anda masukkan sama."
                                , "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var repoLastUpdated = uowUser.Repository.GetById(txtUserId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtUserModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtUsername.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var uowUsr       = new UnitOfWork <User>(dbContext);
                    var userToUpdate = uowUsr.Repository.GetById(txtUserId.Text.Trim());
                    userToUpdate.Username = txtUsername.Text.Trim();

                    if (chkChangePassword.Checked)
                    {
                        userToUpdate.Password = new UserHelper().HashPassword(txtPassword.Text.Trim());
                    }

                    userToUpdate.FullName   = txtFullName.Text.Trim();
                    userToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                    userToUpdate.ModifiedAt = DateTime.Now;
                    uowUsr.Repository.Update(userToUpdate);
                    uowUsr.Commit();

                    var uowUsrRole       = new UnitOfWork <UserRole>(dbContext);
                    var userRoleToUpdate = uowUsrRole.Repository.GetById(txtUserRoleId.Text.ToString().Trim());
                    userRoleToUpdate.UserId     = txtUserId.Text.Trim();
                    userRoleToUpdate.RoleId     = cbRole.SelectedValue.ToString().Trim();
                    userRoleToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                    userRoleToUpdate.ModifiedAt = DateTime.Now;
                    uowUsrRole.Repository.Update(userRoleToUpdate);
                    uowUsrRole.Commit();

                    dbContextTransaction.Commit();
                }

                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }
            var existingCust = uowCust.Repository.GetAll()
                               .Where(r => r.CustomerCode == txtCustomerCode.Text.Trim() &&
                                      r.Address == txtAddress.Text.Trim())
                               .FirstOrDefault();

            if (existingCust != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtCustomerCode.Text.Trim() + " dengan alamat " + txtAddress.Text.Trim());
            }
            else
            {
                var custToAdd = new Customer
                {
                    CustomerCode    = txtCustomerCode.Text.Trim(),
                    CustomerName    = txtCustomerName.Text.Trim(),
                    Address         = txtAddress.Text.Trim(),
                    ProvinceId      = cbProvince.SelectedValue.ToString(),
                    DistrictId      = cbDistrict.SelectedValue.ToString(),
                    PostalCode      = txtPostCode.Text.Trim(),
                    Phone           = txtPhone.Text.Trim(),
                    Email           = txtEmail.Text.Trim(),
                    Npwp            = txtNpwp.Text.Trim(),
                    PharmacistName  = txtPharmacistName.Text.Trim(),
                    SipaNo          = txtSipaNo.Text.Trim(),
                    SipaExpiredDate = DateTime.Parse(dtpSipaExpiredDate.Value.ToString("yyyy-MM-dd")),
                    SiaNo           = txtSiaNo.Text.Trim(),
                    OutletTypeId    = cbOutletType.SelectedValue.ToString(),
                    SalesAreaId     = cbSalesArea.SelectedValue.ToString(),


                    // Audit Fields
                    CreatedBy  = Properties.Settings.Default.CurrentUserId,
                    CreatedAt  = DateTime.Now,
                    ModifiedBy = Properties.Settings.Default.CurrentUserId,
                    ModifiedAt = DateTime.Now
                };
                uowCust.Repository.Add(custToAdd);
                uowCust.Commit();
                isAdd = false;
                cbSalesArea.Enabled = isAdd;
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowCust.Repository.GetById(txtCustomerId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtCustomerCode.Text.Trim());
            }
            else
            {
                var custToUpdate = uowCust.Repository.GetById(txtCustomerId.Text.Trim());
                custToUpdate.CustomerCode    = txtCustomerCode.Text.Trim();
                custToUpdate.CustomerName    = txtCustomerName.Text.Trim();
                custToUpdate.Address         = txtAddress.Text.Trim();
                custToUpdate.ProvinceId      = cbProvince.SelectedValue.ToString();
                custToUpdate.DistrictId      = cbDistrict.SelectedValue.ToString();
                custToUpdate.PostalCode      = txtPostCode.Text.Trim();
                custToUpdate.Phone           = txtPhone.Text.Trim();
                custToUpdate.Email           = txtEmail.Text.Trim();
                custToUpdate.Npwp            = txtNpwp.Text.Trim();
                custToUpdate.PharmacistName  = txtPharmacistName.Text.Trim();
                custToUpdate.SipaNo          = txtSipaNo.Text.Trim();
                custToUpdate.SipaExpiredDate = DateTime.Parse(dtpSipaExpiredDate.Value.ToString("yyyy-MM-dd"));
                custToUpdate.SiaNo           = txtSiaNo.Text.Trim();
                custToUpdate.OutletTypeId    = cbOutletType.SelectedValue.ToString();
                custToUpdate.SalesAreaId     = cbSalesArea.SelectedValue.ToString();

                custToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                custToUpdate.ModifiedAt = DateTime.Now;

                uowCust.Repository.Update(custToUpdate);
                uowCust.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }
            var existingRole = uowRole.Repository.GetAll().Where(r => r.RoleCode == txtRoleCode.Text.Trim()).FirstOrDefault();

            if (existingRole != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtRoleCode.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var roleToAdd = new Role
                    {
                        RoleCode    = txtRoleCode.Text.Trim(),
                        Description = txtDescription.Text.Trim(),

                        // Audit Fields
                        CreatedBy  = Properties.Settings.Default.CurrentUserId,
                        CreatedAt  = DateTime.Now,
                        ModifiedBy = Properties.Settings.Default.CurrentUserId,
                        ModifiedAt = DateTime.Now
                    };
                    var uwRole = new UnitOfWork <Role>(dbContext);
                    uwRole.Repository.Add(roleToAdd);
                    uwRole.Commit();

                    var permRolesToAdd = GetSelectedRolePermisions(roleToAdd.Id);
                    var uwPermRole     = new UnitOfWork <PermissionRole>(dbContext);
                    uwPermRole.Repository.Add(permRolesToAdd);
                    uwPermRole.Commit();

                    dbContextTransaction.Commit();
                }


                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 11
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }
            var productCode     = GetCurrentProductCode();
            var existingProduct = uowProduct.Repository.GetAll().Where(p => p.ProductCode == productCode).FirstOrDefault();

            if (existingProduct != null)
            {
                CommonMessageHelper.DataAlreadyExist(GetCurrentProductCode());
            }
            else
            {
                var prodToAdd = new Product
                {
                    ProductCode     = GetCurrentProductCode(),
                    ProductName     = txtProductName.Text.Trim(),
                    Price           = decimal.Parse(txtPrice.Text.Trim(), System.Globalization.NumberStyles.Currency),
                    PriceDecreeDate = DateTime.Parse(dtpDecreeDate.Value.ToString("yyyy-MM-dd")),
                    Discount        = float.Parse(txtDiscount.Text.Trim()),
                    RestockLevel    = Convert.ToInt32(txtRestock.Text.Trim()),
                    UnitId          = cbUom.SelectedValue.ToString(),
                    MedicineCatId   = cbMedCat.SelectedValue.ToString(),
                    UsageTypeId     = cbUsageType.SelectedValue.ToString(),
                    PrincipalId     = cbPrincipal.SelectedValue.ToString(),

                    // Audit Fields
                    CreatedBy  = Properties.Settings.Default.CurrentUserId,
                    CreatedAt  = DateTime.Now,
                    ModifiedBy = Properties.Settings.Default.CurrentUserId,
                    ModifiedAt = DateTime.Now
                };
                uowProduct.Repository.Add(prodToAdd);
                uowProduct.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowProduct.Repository.GetById(txtProductId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(GetCurrentProductCode());
            }
            else
            {
                var prodToUpdate = uowProduct.Repository.GetById(txtProductId.Text.Trim());
                prodToUpdate.ProductCode = GetCurrentProductCode();
                prodToUpdate.ProductName = txtProductName.Text.Trim();
                //Price = decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["price"].Value.ToString(), System.Globalization.NumberStyles.Currency),
                //prodToUpdate.Price = Convert.ToDecimal(txtPrice.Text.Trim());
                prodToUpdate.Price           = decimal.Parse(txtPrice.Text.Trim(), System.Globalization.NumberStyles.Currency);
                prodToUpdate.PriceDecreeDate = DateTime.Parse(dtpDecreeDate.Value.ToString("yyyy-MM-dd"));
                prodToUpdate.Discount        = float.Parse(txtDiscount.Text.Trim());
                prodToUpdate.RestockLevel    = Convert.ToInt32(txtRestock.Text.Trim());
                prodToUpdate.UnitId          = cbUom.SelectedValue.ToString();
                prodToUpdate.MedicineCatId   = cbMedCat.SelectedValue.ToString();
                prodToUpdate.UsageTypeId     = cbUsageType.SelectedValue.ToString();
                prodToUpdate.PrincipalId     = cbPrincipal.SelectedValue.ToString();
                prodToUpdate.ModifiedBy      = Properties.Settings.Default.CurrentUserId;
                prodToUpdate.ModifiedAt      = DateTime.Now;

                uowProduct.Repository.Update(prodToUpdate);
                uowProduct.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 13
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }
            var existingSalesman = uowSalesman.Repository.GetAll().Where(r => r.SalesmanCode == txtSalesmanCode.Text.Trim()).FirstOrDefault();

            if (existingSalesman != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtSalesmanCode.Text.Trim());
            }
            else
            {
                var salesmanToAdd = new Salesman
                {
                    SalesmanCode = txtSalesmanCode.Text.Trim(),
                    FullName     = txtFullName.Text.Trim(),
                    Gender       = rbFemale.Checked ? Constant.Gender.Female : Constant.Gender.Male,
                    Address      = txtAddress.Text.Trim(),
                    PostalCode   = txtPostCode.Text.Trim(),
                    Phone        = txtPhone.Text.Trim(),
                    Email        = txtEmail.Text.Trim(),
                    ProvinceId   = cbProvince.SelectedValue.ToString(),
                    DistrictId   = cbDistrict.SelectedValue.ToString(),

                    // Audit Fields
                    CreatedBy  = Properties.Settings.Default.CurrentUserId,
                    CreatedAt  = DateTime.Now,
                    ModifiedBy = Properties.Settings.Default.CurrentUserId,
                    ModifiedAt = DateTime.Now
                };
                uowSalesman.Repository.Add(salesmanToAdd);
                uowSalesman.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 14
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowSalesman.Repository.GetById(txtSalesmanId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtSalesmanCode.Text.Trim());
            }
            else
            {
                var salesmanToUpdate = uowSalesman.Repository.GetById(txtSalesmanId.Text.Trim());
                salesmanToUpdate.SalesmanCode = txtSalesmanCode.Text.Trim();
                salesmanToUpdate.FullName     = txtFullName.Text.Trim();
                salesmanToUpdate.Gender       = rbFemale.Checked ? Constant.Gender.Female : Constant.Gender.Male;
                salesmanToUpdate.Address      = txtAddress.Text.Trim();
                salesmanToUpdate.PostalCode   = txtPostCode.Text.Trim();
                salesmanToUpdate.Phone        = txtPhone.Text.Trim();
                salesmanToUpdate.Email        = txtEmail.Text.Trim();
                salesmanToUpdate.ProvinceId   = cbProvince.SelectedValue.ToString();
                salesmanToUpdate.DistrictId   = cbDistrict.SelectedValue.ToString();

                salesmanToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                salesmanToUpdate.ModifiedAt = DateTime.Now;

                uowSalesman.Repository.Update(salesmanToUpdate);
                uowSalesman.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 15
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowRole.Repository.GetById(txtRoleId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtRoleCode.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var roleToUpdate = uowRole.Repository.GetById(txtRoleId.Text.Trim());
                    roleToUpdate.RoleCode    = txtRoleCode.Text.Trim();
                    roleToUpdate.Description = txtDescription.Text.Trim();
                    roleToUpdate.ModifiedBy  = Properties.Settings.Default.CurrentUserId;
                    roleToUpdate.ModifiedAt  = DateTime.Now;

                    var uwRole = new UnitOfWork <Role>(dbContext);
                    uwRole.Repository.Update(roleToUpdate);
                    uwRole.Commit();


                    var uwPermRole          = new UnitOfWork <PermissionRole>(dbContext);
                    var existingAccessCodes = GetExistingAccessCodes();
                    for (int i = 0; i < cblMasterData.Items.Count; i++)
                    {
                        var permissionCode = existingAccessCodes.Where(a => cblMasterData.Items[i].ToString().Contains(a.ToString())).FirstOrDefault().ToString();
                        var permission     = new UnitOfWork <Permission>(dbContext).Repository.GetAll()
                                             .Where(perm => perm.PermissionCode == permissionCode).FirstOrDefault();
                        var permRole = uwPermRole.Repository.GetAll().Where(pr => pr.PermisionId == permission.Id && pr.RoleId == roleToUpdate.Id).FirstOrDefault();

                        if (cblMasterData.GetItemCheckState(i) == CheckState.Unchecked && permRole != null)
                        {
                            uwPermRole.Repository.Delete(permRole);
                        }
                        else if (cblMasterData.GetItemCheckState(i) == CheckState.Checked && permRole == null)
                        {
                            var permRoleToAdd = new PermissionRole
                            {
                                RoleId      = roleToUpdate.Id,
                                PermisionId = permission.Id,

                                // Audit Fields
                                CreatedBy  = Properties.Settings.Default.CurrentUserId,
                                CreatedAt  = DateTime.Now,
                                ModifiedBy = Properties.Settings.Default.CurrentUserId,
                                ModifiedAt = DateTime.Now
                            };
                            uwPermRole.Repository.Add(permRoleToAdd);
                        }

                        uwPermRole.Commit();
                    }

                    for (int i = 0; i < cblTransaksi.Items.Count; i++)
                    {
                        var permissionCode = existingAccessCodes.Where(a => cblTransaksi.Items[i].ToString().Contains(a.ToString())).FirstOrDefault().ToString();
                        var permission     = new UnitOfWork <Permission>(dbContext).Repository.GetAll()
                                             .Where(perm => perm.PermissionCode == permissionCode).FirstOrDefault();
                        var permRole = uwPermRole.Repository.GetAll().Where(pr => pr.PermisionId == permission.Id && pr.RoleId == roleToUpdate.Id).FirstOrDefault();

                        if (cblTransaksi.GetItemCheckState(i) == CheckState.Unchecked && permRole != null)
                        {
                            uwPermRole.Repository.Delete(permRole);
                        }
                        else if (cblTransaksi.GetItemCheckState(i) == CheckState.Checked && permRole == null)
                        {
                            var permRoleToAdd = new PermissionRole
                            {
                                RoleId      = roleToUpdate.Id,
                                PermisionId = permission.Id,

                                // Audit Fields
                                CreatedBy  = Properties.Settings.Default.CurrentUserId,
                                CreatedAt  = DateTime.Now,
                                ModifiedBy = Properties.Settings.Default.CurrentUserId,
                                ModifiedAt = DateTime.Now
                            };
                            uwPermRole.Repository.Add(permRoleToAdd);
                        }

                        uwPermRole.Commit();
                    }

                    for (int i = 0; i < cblReporting.Items.Count; i++)
                    {
                        var permissionCode = existingAccessCodes.Where(a => cblReporting.Items[i].ToString().Contains(a.ToString())).FirstOrDefault().ToString();
                        var permission     = new UnitOfWork <Permission>(dbContext).Repository.GetAll()
                                             .Where(perm => perm.PermissionCode == permissionCode).FirstOrDefault();
                        var permRole = uwPermRole.Repository.GetAll().Where(pr => pr.PermisionId == permission.Id && pr.RoleId == roleToUpdate.Id).FirstOrDefault();

                        if (cblReporting.GetItemCheckState(i) == CheckState.Unchecked && permRole != null)
                        {
                            uwPermRole.Repository.Delete(permRole);
                        }
                        else if (cblReporting.GetItemCheckState(i) == CheckState.Checked && permRole == null)
                        {
                            var permRoleToAdd = new PermissionRole
                            {
                                RoleId      = roleToUpdate.Id,
                                PermisionId = permission.Id,

                                // Audit Fields
                                CreatedBy  = Properties.Settings.Default.CurrentUserId,
                                CreatedAt  = DateTime.Now,
                                ModifiedBy = Properties.Settings.Default.CurrentUserId,
                                ModifiedAt = DateTime.Now
                            };
                            uwPermRole.Repository.Add(permRoleToAdd);
                        }

                        uwPermRole.Commit();
                    }

                    dbContextTransaction.Commit();
                }


                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 16
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }
            var existingRole = uowUser.Repository.GetAll().Where(u => u.Username == txtUsername.Text.Trim()).FirstOrDefault();

            if (existingRole != null)
            {
                CommonMessageHelper.DataAlreadyExist(txtUsername.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var userToAdd = new User
                    {
                        Username = txtUsername.Text.Trim(),
                        Password = new UserHelper().HashPassword(txtPassword.Text.Trim()),
                        FullName = txtFullName.Text.Trim(),

                        // Audit Fields
                        CreatedBy  = Properties.Settings.Default.CurrentUserId,
                        CreatedAt  = DateTime.Now,
                        ModifiedBy = Properties.Settings.Default.CurrentUserId,
                        ModifiedAt = DateTime.Now
                    };
                    var uowUsr = new UnitOfWork <User>(dbContext);

                    uowUsr.Repository.Add(userToAdd);
                    uowUsr.Commit();

                    var uowUsrRole = new UnitOfWork <UserRole>(dbContext);
                    //var existingUsrRole = uowUsrRole.Repository.GetAll().
                    //    Where(u => u.UserId == txtUserId.Text.Trim() && u.RoleId == txtRoleId.Text.Trim()).FirstOrDefault();
                    //if (existingUsrRole != null)
                    //{
                    //    CommonMessageHelper.DataAlreadyExist(txtUsername.Text.Trim() + " dan " + cbRole.SelectedText);
                    //    return;
                    //}

                    var userRoleToAdd = new UserRole
                    {
                        UserId = userToAdd.Id.ToString().ToUpper(),
                        RoleId = cbRole.SelectedValue.ToString().ToUpper(),

                        // Audit Fields
                        CreatedBy  = Properties.Settings.Default.CurrentUserId,
                        CreatedAt  = DateTime.Now,
                        ModifiedBy = Properties.Settings.Default.CurrentUserId,
                        ModifiedAt = DateTime.Now
                    };
                    uowUsrRole.Repository.Add(userRoleToAdd);
                    uowUsrRole.Commit();

                    dbContextTransaction.Commit();
                }

                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
                chkChangePassword.Visible = false;
            }
        }
Exemplo n.º 17
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = _uow.Repository.GetById(txtSalesOrderId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(lblSalesNo.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var customerId = cbCustomer.SelectedValue.ToString();
                    var customer   = new UnitOfWork <Customer>(dbContext).Repository.GetById(customerId);
                    var salesman   = new UnitOfWork <Salesman>(dbContext).Repository.GetById(cbSalesman.SelectedValue.ToString());
                    var top        = new UnitOfWork <TermOfPayment>(dbContext).Repository.GetById(cbTermOfPayment.SelectedValue.ToString());
                    var salesArea  = new UnitOfWork <SalesArea>(dbContext).Repository.GetById(cbSalesArea.SelectedValue.ToString());
                    var prov       = new UnitOfWork <Location>(dbContext).Repository.GetById(cbProvince.SelectedValue.ToString());
                    var district   = new UnitOfWork <Location>(dbContext).Repository.GetById(cbDistrict.SelectedValue.ToString());

                    #region parent
                    var uwSalesOrder = new UnitOfWork <SalesOrder>(dbContext);
                    var soToUpdate   = uwSalesOrder.Repository.GetById(txtSalesOrderId.Text.Trim());

                    soToUpdate.CustomerId          = customerId;
                    soToUpdate.CustomerName        = customer.CustomerName;
                    soToUpdate.CustomerAddress     = customer.Address;
                    soToUpdate.CustomerProvinceId  = customer.ProvinceId;
                    soToUpdate.CustomerProvince    = GetLocationName(customer.ProvinceId);
                    soToUpdate.CustomerDistrictId  = customer.DistrictId;
                    soToUpdate.CustomerDistrict    = GetLocationName(customer.DistrictId);
                    soToUpdate.CustomerPostalCode  = customer.PostalCode;
                    soToUpdate.CustomerPhone       = customer.Phone;
                    soToUpdate.CustomerEmail       = customer.Email;
                    soToUpdate.CustomerNpwp        = customer.Npwp;
                    soToUpdate.SalesmanId          = cbSalesman.SelectedValue.ToString();
                    soToUpdate.SalesmanCode        = salesman.SalesmanCode;
                    soToUpdate.TermOfPaymentId     = cbTermOfPayment.SelectedValue.ToString();
                    soToUpdate.TermOfPaymentCode   = top.TermCode;
                    soToUpdate.SalesDate           = dtpSalesOrderDate.Value;
                    soToUpdate.DueDate             = dtpDueDate.Value;
                    soToUpdate.DeliveryAddress     = txtDeliveryAddress.Text;
                    soToUpdate.DeliveryProvinceId  = cbProvince.SelectedValue.ToString();
                    soToUpdate.DeliveryProvince    = prov.Name;
                    soToUpdate.DeliveryDistrictId  = cbDistrict.SelectedValue.ToString();
                    soToUpdate.DeliveryDistrict    = district.Name;
                    soToUpdate.SalesAreaId         = cbSalesArea.SelectedValue.ToString();
                    soToUpdate.SalesAreaCode       = salesArea.AreaCode;
                    soToUpdate.SubTotalAmount      = decimal.Parse(txtSubTotal.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.ExtraDiscountAmount = decimal.Parse(txtExtraDiscount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.TaxBaseAmount       = decimal.Parse(txtTaxBaseAmount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.ValueAddedTaxAmount = decimal.Parse(txtValueAddedTaxAmount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.GrandTotalAmount    = decimal.Parse(lblTotal.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.UserId   = Properties.Settings.Default.CurrentUserId;
                    soToUpdate.Username = Properties.Settings.Default.CurrentUser;

                    // Audit fields
                    soToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                    soToUpdate.ModifiedAt = DateTime.Now;

                    uwSalesOrder.Repository.Update(soToUpdate);
                    uwSalesOrder.Commit();

                    #endregion parent

                    #region child

                    var uwSoItem = new UnitOfWork <SalesOrderItem>(dbContext);

                    // clear all item for the identified Sales Order
                    var tobeClearedItems = uwSoItem.Repository.GetAll().Where(soi => soi.SalesOrderId == txtSalesOrderId.Text.Trim());
                    uwSoItem.Repository.Delete(tobeClearedItems);
                    uwSoItem.Commit();

                    // add with updated items
                    List <SalesOrderItem> orderItems = new List <SalesOrderItem>();
                    for (int i = 0; i < dgvSalesOrderItem.Rows.Count; ++i)
                    {
                        if (dgvSalesOrderItem.Rows[i].Cells["productCode"].Value == null)
                        {
                            continue;
                        }

                        var expiredDate     = commonHelper.GetEndOfMonth(DateTime.Parse(dgvSalesOrderItem.Rows[i].Cells["expDate"].Value.ToString()));
                        var qty             = Convert.ToInt32(decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["qty"].Value.ToString(), System.Globalization.NumberStyles.Currency));
                        var nettPrice       = Math.Round(decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["price"].Value.ToString(), System.Globalization.NumberStyles.Currency), 5, MidpointRounding.AwayFromZero);
                        var discountPercent = Math.Round(Convert.ToDecimal(ValidateDiscount(dgvSalesOrderItem.Rows[i].Cells["discPercent"].Value.ToString().Replace("%", ""))) / 100, 5, MidpointRounding.AwayFromZero);
                        var grossValue      = Math.Round(qty * nettPrice, 5, MidpointRounding.AwayFromZero);
                        var subTotal        = salesOrderHelper.CalculateTaxBaseAmount(qty, nettPrice, discountPercent);

                        var soiToUpdate = new SalesOrderItem
                        {
                            SalesOrderId       = txtSalesOrderId.Text.Trim(),
                            ProductId          = dgvSalesOrderItem.Rows[i].Cells["productId"].Value.ToString(),
                            ProductCode        = dgvSalesOrderItem.Rows[i].Cells["productCode"].Value.ToString(),
                            ProductName        = dgvSalesOrderItem.Rows[i].Cells["productName"].Value.ToString(),
                            BatchId            = dgvSalesOrderItem.Rows[i].Cells["batchId"].Value.ToString(),
                            BatchCode          = dgvSalesOrderItem.Rows[i].Cells["batchCode"].Value.ToString(),
                            ExpiredDate        = commonHelper.StandardizeDate(expiredDate),
                            Quantity           = qty,
                            UomId              = dgvSalesOrderItem.Rows[i].Cells["uomId"].Value.ToString(),
                            UomCode            = dgvSalesOrderItem.Rows[i].Cells["uomCode"].Value.ToString(),
                            Price              = nettPrice,
                            DiscountPercentage = float.Parse(dgvSalesOrderItem.Rows[i].Cells["discPercent"].Value.ToString().Replace("%", "")),
                            TotalAmount        = subTotal,

                            // Audit Fields
                            CreatedBy  = Properties.Settings.Default.CurrentUserId,
                            CreatedAt  = DateTime.Now,
                            ModifiedBy = Properties.Settings.Default.CurrentUserId,
                            ModifiedAt = DateTime.Now
                        };
                        orderItems.Add(soiToUpdate);
                    }
                    uwSoItem.Repository.Add(orderItems);
                    uwSoItem.Commit();

                    #endregion child

                    dbContextTransaction.Commit();
                }

                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 18
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            using (var dbContextTransaction = dbContext.Database.BeginTransaction())
            {
                var customer  = new UnitOfWork <Customer>(dbContext).Repository.GetById(cbCustomer.SelectedValue.ToString());
                var salesman  = new UnitOfWork <Salesman>(dbContext).Repository.GetById(cbSalesman.SelectedValue.ToString());
                var top       = new UnitOfWork <TermOfPayment>(dbContext).Repository.GetById(cbTermOfPayment.SelectedValue.ToString());
                var salesArea = new UnitOfWork <SalesArea>(dbContext).Repository.GetById(cbSalesArea.SelectedValue.ToString());
                var district  = new UnitOfWork <Location>(dbContext).Repository.GetById(cbDistrict.SelectedValue.ToString());

                #region parent
                var uwSalesOrder = new UnitOfWork <SalesOrder>(dbContext);
                var soToAdd      = new SalesOrder();
                soToAdd.SalesNo             = CreateSalesOrderNo();
                soToAdd.CustomerId          = cbCustomer.SelectedValue.ToString();
                soToAdd.CustomerName        = customer.CustomerName;
                soToAdd.CustomerAddress     = customer.Address;
                soToAdd.CustomerProvinceId  = customer.ProvinceId;
                soToAdd.CustomerProvince    = GetLocationName(customer.ProvinceId);
                soToAdd.CustomerDistrictId  = customer.DistrictId;
                soToAdd.CustomerDistrict    = GetLocationName(customer.DistrictId);
                soToAdd.CustomerPostalCode  = customer.PostalCode;
                soToAdd.CustomerPhone       = customer.Phone;
                soToAdd.CustomerEmail       = customer.Email;
                soToAdd.CustomerNpwp        = customer.Npwp;
                soToAdd.DeliveryAddress     = txtDeliveryAddress.Text;
                soToAdd.DeliveryProvinceId  = cbProvince.SelectedValue.ToString();
                soToAdd.DeliveryProvince    = GetLocationName(cbProvince.SelectedValue.ToString());
                soToAdd.DeliveryDistrictId  = cbDistrict.SelectedValue.ToString();
                soToAdd.DeliveryDistrict    = GetLocationName(cbDistrict.SelectedValue.ToString());
                soToAdd.SalesAreaId         = cbSalesArea.SelectedValue.ToString();
                soToAdd.SalesAreaCode       = salesArea.AreaCode;
                soToAdd.SalesDate           = dtpSalesOrderDate.Value;
                soToAdd.TermOfPaymentId     = cbTermOfPayment.SelectedValue.ToString();
                soToAdd.TermOfPaymentCode   = top.TermCode;
                soToAdd.DueDate             = dtpDueDate.Value;
                soToAdd.PersonInCharge      = Properties.Settings.Default.SalesPicName;
                soToAdd.SipaNo              = Properties.Settings.Default.SalesPicSipaNo;
                soToAdd.SalesmanId          = cbSalesman.SelectedValue.ToString();
                soToAdd.SalesmanCode        = salesman.SalesmanCode;
                soToAdd.SubTotalAmount      = decimal.Parse(txtSubTotal.Text.Trim(), System.Globalization.NumberStyles.Currency);
                soToAdd.ExtraDiscountAmount = decimal.Parse(txtExtraDiscount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                soToAdd.TaxBaseAmount       = decimal.Parse(txtTaxBaseAmount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                soToAdd.ValueAddedTaxAmount = decimal.Parse(txtValueAddedTaxAmount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                soToAdd.GrandTotalAmount    = decimal.Parse(lblTotal.Text.Trim(), System.Globalization.NumberStyles.Currency);
                soToAdd.UserId              = Properties.Settings.Default.CurrentUserId;
                soToAdd.Username            = Properties.Settings.Default.CurrentUser;
                soToAdd.Status              = Constant.RecordStatus.Active;
                soToAdd.CreatedBy           = Properties.Settings.Default.CurrentUserId;
                soToAdd.CreatedAt           = DateTime.Now;
                soToAdd.ModifiedBy          = Properties.Settings.Default.CurrentUserId;
                soToAdd.ModifiedAt          = DateTime.Now;

                uwSalesOrder.Repository.Add(soToAdd);
                uwSalesOrder.Commit();

                #endregion parent

                #region child

                var uwSoItem = new UnitOfWork <SalesOrderItem>(dbContext);
                for (int i = 0; i < dgvSalesOrderItem.Rows.Count; ++i)
                {
                    if (dgvSalesOrderItem.Rows[i].Cells["productCode"].Value == null)
                    {
                        continue;
                    }

                    DateTime expiredDate = DateTime.Parse(dgvSalesOrderItem.Rows[i].Cells["expDate"].Value.ToString());
                    expiredDate = commonHelper.GetEndOfMonth(expiredDate);

                    var qty             = Convert.ToInt32(decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["qty"].Value.ToString(), System.Globalization.NumberStyles.Currency));
                    var nettPrice       = Math.Round(decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["price"].Value.ToString(), System.Globalization.NumberStyles.Currency), 5, MidpointRounding.AwayFromZero);
                    var discountPercent = Math.Round(Convert.ToDecimal(ValidateDiscount(dgvSalesOrderItem.Rows[i].Cells["discPercent"].Value.ToString().Replace("%", ""))) / 100, 5, MidpointRounding.AwayFromZero);
                    var subTotal        = salesOrderHelper.CalculateTaxBaseAmount(qty, nettPrice, discountPercent);

                    var soiToAdd = new SalesOrderItem
                    {
                        SalesOrderId       = soToAdd.Id,
                        ProductId          = dgvSalesOrderItem.Rows[i].Cells["productId"].Value.ToString(),
                        ProductCode        = dgvSalesOrderItem.Rows[i].Cells["productCode"].Value.ToString(),
                        ProductName        = dgvSalesOrderItem.Rows[i].Cells["productName"].Value.ToString(),
                        BatchId            = dgvSalesOrderItem.Rows[i].Cells["batchId"].Value.ToString(),
                        BatchCode          = dgvSalesOrderItem.Rows[i].Cells["batchCode"].Value.ToString(),
                        ExpiredDate        = commonHelper.StandardizeDate(expiredDate),
                        Quantity           = qty,
                        UomId              = dgvSalesOrderItem.Rows[i].Cells["uomId"].Value.ToString(),
                        UomCode            = dgvSalesOrderItem.Rows[i].Cells["uomCode"].Value.ToString(),
                        Price              = nettPrice,
                        DiscountPercentage = float.Parse(dgvSalesOrderItem.Rows[i].Cells["discPercent"].Value.ToString().Replace("%", "")),
                        TotalAmount        = subTotal,

                        // Audit Fields
                        CreatedBy  = Properties.Settings.Default.CurrentUserId,
                        CreatedAt  = DateTime.Now,
                        ModifiedBy = Properties.Settings.Default.CurrentUserId,
                        ModifiedAt = DateTime.Now
                    };
                    uwSoItem.Repository.Add(soiToAdd);
                }
                var res = uwSoItem.Commit();

                #endregion child

                dbContextTransaction.Commit();

                // when commit succeed, update the key fields
                lblSalesNo.Text      = soToAdd.SalesNo;
                txtSalesOrderId.Text = soToAdd.Id;
                txtModifiedAt.Text   = soToAdd.ModifiedAt.ToString();
            }

            NavigateRecord(RecordNavigation.Last);
            CommonMessageHelper.DataSavedSuccessfully();
        }