protected override void btnSave_Click(object sender, EventArgs e)
 {
     if (ValidateInput())
     {
         string result = string.Empty;
         GuaranteeFeeConfiguration configuration = GetConfigurationInfo();
         if (_isUpdating)
         {
             configuration.id = SelectedItemID;
             result           = _business.Update(configuration);
         }
         else
         {
             configuration.id = IDGenerator.NewId <GuaranteeFeeConfiguration>(true);
             result           = _business.Insert(configuration);
         }
         if (string.IsNullOrEmpty(result))
         {
             ChangeViewStatus(false);
             DataBind();
         }
         else
         {
             MessageBox.Show(result, Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        private User GetUserInfo(bool isUpdating)
        {
            User user;

            if (isUpdating)
            {
                user = _business.Get(SelectedUserID);
            }
            else
            {
                user              = new User();
                user.id           = IDGenerator.NewId <User>(true);
                user.user_name    = tbUserName.Text.ToLowerInvariant();
                user.created_date = DateTime.Now;
                user.created_by   = SystemParam.CurrentUser.id;
                user.deleted      = false;
            }
            var password = string.IsNullOrEmpty(tbNewPassword.Text) ? tbCurrentPassword.Text : tbNewPassword.Text;

            password           = PasswordServiceProvider.Encrypt(user.user_name, password);
            user.password      = password;
            user.role          = cboRole.SelectedValue.ToString();
            user.staff_id      = tbStaffID.Text;
            user.active_status = chkActive.Checked;
            return(user);
        }
Esempio n. 3
0
        public override bool HandleSaveTask()
        {
            bool success = false;

            try
            {
                Customer customer = _isUpdating ? _customers.FirstOrDefault(c => c.id.Equals(SelectedCustomerID)) : new Customer();
                if (customer != null && ValidateInput())
                {
                    if (string.IsNullOrEmpty(customer.id))
                    {
                        customer.id = IDGenerator.NewId <Customer>(true);
                    }
                    // Collects customer information
                    customer.company        = tbCompany.Text;
                    customer.phone          = tbPhone.Text;
                    customer.address1       = tbAddress1.Text;
                    customer.address2       = tbAddress2.Text;
                    customer.name           = tbName.Text;
                    customer.mobile         = tbMobile.Text;
                    customer.id_card_number = tbIDCardNumber.Text;
                    customer.created_by     = SystemParam.CurrentUser.id;
                    customer.created_date   = DateTime.Now;

                    string result = _isUpdating ? _business.Update(customer) : _business.Insert(customer);
                    if (string.IsNullOrEmpty(result))
                    {
                        MessageBox.Show("Thông tin khách hàng đã được lưu thành công.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None);
                        _isEditing = false;
                        ChangeControlStatus(_isEditing);
                        success = true;
                        DataBind();
                        //PopulateCustomerInfo(customer);
                    }
                    else
                    {
                        MessageBox.Show(result, Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                AppLogger.logError(this.ToString(), ex);
                MessageBox.Show("Có lỗi xảy ra trong khi lưu thông tin khách hàng.", Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(success);
        }
        protected override void LogAuditTrail(RegularOrder order, string action)
        {
            if (CurrentUser != null)
            {
                action = action.ToUpperInvariant();
                if (_orderHistoryRepository == null)
                {
                    _orderHistoryRepository = new GenericRepository <OrderHistory>(Repository.Context);
                }
                if (_orderHistoryDetailRepository == null)
                {
                    _orderHistoryDetailRepository = new GenericRepository <OrderHistoryDetail>(Repository.Context);
                }

                // Logs audit trail
                OrderHistory orderHistory = new OrderHistory();
                orderHistory.id        = IDGenerator.NewId <OrderHistory>(true);
                orderHistory.order_id  = order.id;
                orderHistory.action    = action;
                orderHistory.date_time = DateTime.Now;
                orderHistory.user_id   = SystemParam.CurrentUser.id;
                _orderHistoryRepository.Insert(orderHistory);

                switch (order.EntityState)
                {
                case EntityState.Added:
                {
                    foreach (var property in order.GetType().GetProperties())
                    {
                        OrderHistoryDetail orderHistoryDetail = new OrderHistoryDetail();
                        orderHistoryDetail.id            = Guid.NewGuid().ToString();
                        orderHistoryDetail.parent_id     = orderHistory.id;
                        orderHistoryDetail.property_name = property.Name;
                        orderHistoryDetail.old_value     = string.Empty;
                        orderHistoryDetail.new_value     = property.GetValue(order, null) != null?property.GetValue(order, null).ToString() : null;

                        _orderHistoryDetailRepository.Insert(orderHistoryDetail);
                    }
                }
                break;

                case EntityState.Modified:
                {
                    var stateEntry = Repository.Context.ObjectStateManager.GetObjectStateEntry(order);
                    foreach (var propertyName in stateEntry.GetModifiedProperties())
                    {
                        OrderHistoryDetail orderHistoryDetail = new OrderHistoryDetail();
                        orderHistoryDetail.id            = Guid.NewGuid().ToString();
                        orderHistoryDetail.parent_id     = orderHistory.id;
                        orderHistoryDetail.property_name = propertyName;
                        orderHistoryDetail.old_value     = stateEntry.OriginalValues[propertyName] != null ? stateEntry.OriginalValues[propertyName].ToString() : null;
                        orderHistoryDetail.new_value     = stateEntry.CurrentValues[propertyName] != null ? stateEntry.CurrentValues[propertyName].ToString() : null;
                        _orderHistoryDetailRepository.Insert(orderHistoryDetail);
                    }
                }
                break;

                default: break;
                }
            }
        }
Esempio n. 5
0
        private void btnCreateOrder_Click(object sender, EventArgs e)
        {
            if (ValidateInput() &&
                MessageBox.Show(Constants.Messages.CREATE_ORDER_CONFIRMATION_MESSAGE, Constants.Messages.CREATE_ORDER_CONFIRMATION_CAPTION, MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                bool   success    = true;
                string saveResult = string.Empty;
                try
                {
                    // Creates OrderBase instance and gets general info
                    OrderBase order = new OrderBase();
                    order.id = rbtnOrderType_Regular.Checked ? IDGenerator.NewId <RegularOrder>() : IDGenerator.NewId <IrregularOrder>();
                    AppLogger.logDebug(this.ToString(), string.Format("Id: {0}", order.id));
                    order.payment_status = this.rbtnPaymentStatus_Paid.Checked ? Constants.PaymentStatus.Paid.ToString() : Constants.PaymentStatus.Unpaid.ToString();
                    order.order_status   = Constants.DeliveryStatus.Waiting.ToString();
                    order.tour_id        = cboDestination.SelectedValue.ToString();
                    order.created_date   = DateTime.Now;
                    order.created_by     = SystemParam.CurrentUser.user_name;
                    int     totalQuantity = 0;
                    decimal totalValue    = 0;
                    decimal totalCost     = 0;
                    foreach (var item in ucItemsList.OrderItems)
                    {
                        item.id        = IDGenerator.NewOrderItemId(order.id, ucItemsList.OrderItems.IndexOf(item) + 1);
                        item.order_id  = order.id;
                        totalQuantity += item.quantity;
                        totalValue    += item.value * item.quantity;
                        totalCost     += item.cost;
                    }
                    order.total_quantity = totalQuantity;
                    order.total_value    = totalValue;
                    order.total_cost     = totalCost;

                    // Convert order info per order type
                    if (rbtnOrderType_Regular.Checked)
                    {
                        RegularOrder regularOrder = order.ToRegular();
                        regularOrder.sender_id    = Sender.id;
                        regularOrder.recipient_id = Recipient.id;

                        saveResult = _regularBusiness.Insert(regularOrder, ucItemsList.OrderItems);
                    }
                    else
                    {
                        IrregularOrder irregularOrder = order.ToIrregular();
                        irregularOrder.sender_name          = tbSenderName.Text;
                        irregularOrder.sender_phone         = tbSenderPhoneNumber.Text;
                        irregularOrder.sender_id_card_no    = tbSenderIDCardNo.Text;
                        irregularOrder.sender_address       = tbSenderAddress.Text;
                        irregularOrder.recipient_name       = tbRecipientName.Text;
                        irregularOrder.recipient_phone      = tbRecipientPhoneNumber.Text;
                        irregularOrder.recipient_id_card_no = tbRecipientIDCardNo.Text;
                        irregularOrder.recipient_address    = tbRecipientAddress.Text;

                        if (rbtnPaymentStatus_Paid.Checked &&
                            (new IrregularOrderPaymentView(irregularOrder, ucItemsList.OrderItems)).ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            AppLogger.logDebug(this.ToString(), "Payment process cancelled.");
                            return;
                        }
                        saveResult = _irregularBusiness.Insert(irregularOrder, ucItemsList.OrderItems);
                    }
                }
                catch (Exception ex)
                {
                    AppLogger.logError(this.ToString(), ex.Message, ex);
                    success = false;
                }
                if (success && string.IsNullOrEmpty(saveResult))
                {
                    AppLogger.logInfo(this.ToString(), "Finish inserting new order into database.");
                    MessageBox.Show("Đã tạo thành công đơn hàng mới.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None);
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                else
                {
                    if (string.IsNullOrEmpty(saveResult))
                    {
                        saveResult = Constants.Messages.CREATE_ORDER_ERROR_MESSAGE;
                    }
                    MessageBox.Show(saveResult, Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }