Пример #1
0
        private void Customer_GridView_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            //Console.WriteLine("Customer_GridView_CellValueChanging");
            if (!Customer_GridView.IsFilterRow(e.RowHandle) && e.Column.FieldName == CUSTOMER_SNAME)
            {
                var status = Customer_GridView.GetFocusedRow().CastTo <Customer>()?.Status;

                if (status != ModifyMode.Insert)
                {
                    return;
                }

                CustomerIDTemp = Customer_GridView.GetFocusedRowCellValue(CUSTOMER_IDTEMP).ToString();

                // filter grid
                Customer_GridView.SetRowCellValue(e.RowHandle, CUSTOMER_SNAME, e.Value);

                IsFiltering = true;
                string filter = string.Empty;
                if (!string.IsNullOrEmpty(e.Value?.ToString()))
                {
                    filter = $"StartsWith([{CUSTOMER_SNAME}], '{e.Value}')";
                }

                Customer_GridView.ActiveFilterString = filter;

                IsFiltering    = false;
                CustomerIDTemp = string.Empty;
            }
        }
        private void Customer_GridView_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            Customer_GridView.ClearColumnErrors();

            Customer row  = e.Row.CastTo <Customer>();
            GridView view = sender as GridView;

            if (string.IsNullOrEmpty(row.CustomerName))
            {
                e.Valid = false;
                //Set errors with specific descriptions for the columns
                GridColumn column = view.Columns[nameof(row.CustomerName)];
                view.SetColumnError(column, BSMessage.BSM000015);
            }

            if (string.IsNullOrEmpty(row.CustomerSName))
            {
                e.Valid = false;
                //Set errors with specific descriptions for the columns
                GridColumn column = view.Columns[nameof(row.CustomerSName)];
                view.SetColumnError(column, BSMessage.BSM000012);
            }

            // Kiểm tra tồn tại trong grid
            if (CustommersData.ToList().Count(o => o.CustomerSName == row.CustomerSName) > 1)
            {
                e.Valid = false;
                //Set errors with specific descriptions for the columns
                GridColumn column = view.Columns[nameof(row.CustomerSName)];
                view.SetColumnError(column, BSMessage.BSM000010);
            }
        }
Пример #3
0
        private void Customer_GridView_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
        {
            int rowIndex = Customer_GridView.FocusedRowHandle;

            if (!Customer_GridView.IsRowSelected(rowIndex))
            {
                return;
            }

            var  selected = Customer_GridView.GetFocusedRow().CastTo <Customer>();
            bool isNewRow = Customer_GridView.IsNewItemRow(rowIndex);

            if (selected == null)
            {
                return;
            }

            // Dòng thêm mới
            if (isNewRow || selected.Status == ModifyMode.Insert)
            {
                return;
            }

            // Có quyền kế toán trưởng
            if (ClientCommon.HasAuthority(UserInfo.UserRole, BSRole.KeToanTruong))
            {
                return;
            }

            if (selected.CreateUser.ToUpper() != UserInfo.UserID.ToUpper())
            {
                Customer_GridView.UnselectRow(rowIndex);
            }
        }
Пример #4
0
 private void Customer_GridView_ColumnFilterChanged(object sender, EventArgs e)
 {
     if (IsFiltering && !string.IsNullOrEmpty(CustomerIDTemp))
     {
         //Console.WriteLine("Customer_GridView_ColumnFilterChanged");
         Customer_GridView.SetFocusRowByValue(CUSTOMER_IDTEMP, CustomerIDTemp);
         Customer_GridView.FocusedColumn = Customer_GridView.Columns[CUSTOMER_SNAME];
         Customer_GridView.ShowEditor();
         if (Customer_GridView.ActiveEditor is DevExpress.XtraEditors.TextEdit editor)
         {
             editor.SelectionStart = editor.Text.Length;
         }
     }
 }
Пример #5
0
        private void Select_Button_Click(object sender, EventArgs e)
        {
            Customer row = Customer_GridView.GetFocusedRow().CastTo <Customer>();

            if (SelectedRow == null && (row == null || string.IsNullOrEmpty(row.CustomerID)))
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000026);
                return;
            }

            if (row != null)
            {
                SelectedRow = ModelHelper.CopyToNew <Customer, Customer>(row);
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
        private void Customer_GridView_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            Customer row = e.Row.CastTo <Customer>();

            bool isNewRow = Customer_GridView.IsNewItemRow(e.RowHandle);

            if (isNewRow)
            {
                row.Status = ModifyMode.Insert;
                return;
            }

            if (row.Status == ModifyMode.Insert)
            {
                return;
            }

            row.Status = ModifyMode.Update;
        }
Пример #7
0
        private void Save_Button_Click(object sender, EventArgs e)
        {
            if (!IsCheckValidate())
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000039);
                return;
            }

            List <Customer> saveData = this.CustommersData.Where(o => o.Status == ModifyMode.Insert || o.Status == ModifyMode.Update).ToList();

            if (this.CustomersDeleteData != null)
            {
                saveData?.InsertRange(0, this.CustomersDeleteData);
            }

            if (saveData?.Count > 0)
            {
                CustomerController controller = new CustomerController();
                if (controller.SaveCustommers(saveData, out string customerID))
                {
                    MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000001);
                    CustomersDeleteData = new List <Customer>();
                    this.LoadGridView();
                    ReloadData.CustomerUpdate();

                    // Chọn KH sau khi lưu thành công
                    if (!string.IsNullOrEmpty(customerID))
                    {
                        Customer_GridView.SetFocusRowByValue("CustomerID", customerID);
                        SelectedRow = Customer_GridView.GetFocusedRow().CastTo <Customer>();
                    }
                }
                else
                {
                    MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000002);
                }
            }
        }
Пример #8
0
        private void Customer_GridView_ShowingEditor(object sender, CancelEventArgs e)
        {
            int  rowIndex = Customer_GridView.FocusedRowHandle;
            var  selected = Customer_GridView.GetFocusedRow().CastTo <Customer>();
            bool isNewRow = Customer_GridView.IsNewItemRow(rowIndex);

            // Dòng thêm mới
            if (isNewRow || selected.Status == ModifyMode.Insert)
            {
                return;
            }

            // Có quyền kế toán trưởng
            if (ClientCommon.HasAuthority(UserInfo.UserRole, BSRole.KeToanTruong))
            {
                return;
            }

            if (selected.CreateUser.ToUpper() != UserInfo.UserID.ToUpper())
            {
                e.Cancel = true;
            }
        }