Exemple #1
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();
            }
        }
Exemple #2
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();
            }
        }
Exemple #3
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();
            }
        }
Exemple #4
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();
            }
        }