private void LoadDataKC()
        {
            //Thực hiện cho loại hình không phải tour, công trình
            if (CommonInfo.CompareCompanyType("DL") || CommonInfo.CompareCompanyType("XD") || CommonInfo.CompareCompanyType("SX"))
            {
                #region Kết chuyển loại hình Du lịch, Xây dựng
                Load_KetChuyen_GridView(KetChuyen_bsFromToDateEdit.FromDate.Date, this.KetChuyen_bsFromToDateEdit.ToDate.Date, CommonInfo.CompanyInfo.CompanyID);

                string value = KetChuyenType_radioGroup.EditValue.ToString();
                switch (value)
                {
                case "CK":
                    LoadKCCK();
                    break;
                }
                #endregion Kết chuyển loại hình Du lịch, Xây dựng
            }
            else
            {
                #region Kết chuyển loại hình thương mại và sản xuất
                Load_KetChuyen_GridView(KetChuyen_bsFromToDateEdit.FromDate.Date, this.KetChuyen_bsFromToDateEdit.ToDate.Date, CommonInfo.CompanyInfo.CompanyID);
                LoadKCCK();
                #endregion Kết chuyển loại hình thương mại và sản xuất
            }
        }
 private void KetChuyen_Load(object sender, EventArgs e)
 {
     if (CommonInfo.CompareCompanyType("DL") || CommonInfo.CompareCompanyType("XD") || CommonInfo.CompareCompanyType("SX"))
     {
         #region Kết chuyển loại hình Du lịch, Xây dựng
         KetChuyenType_radioGroup.EditValue = "DD";
         #endregion Kết chuyển loại hình Du lịch, Xây dựng
     }
     else
     {
         #region kết chuyển loại hình Thương mại, Sản xuất
         KetChuyenType_radioGroup.EditValue = "CK";
         KetChuyenType_radioGroup.Enabled   = false;
         #endregion kết chuyển loại hình Thương mại, Sản xuất
     }
 }
        private void Load_KetChuyen_GridView(DateTime StartDate, DateTime EndDate, string CompanyID)
        {
            KetChuyenController controller = new KetChuyenController();

            if (CommonInfo.CompareCompanyType("DL") || CommonInfo.CompareCompanyType("XD") || CommonInfo.CompareCompanyType("SX"))
            {
                #region Kết chuyển loại hình Du lịch, Xây dựng
                string value = KetChuyenType_radioGroup.EditValue.ToString();
                switch (value)
                {
                case "DD":
                    //Lấy dữ liệu dở dang
                    KetChuyenData = new BindingList <KetChuyenValue>(controller.KetChuyenDoDangtableSelect(StartDate, EndDate, CommonInfo.CompanyInfo.CompanyID));
                    break;

                case "TP":
                    //Lấy dữ liệu thành phẩm
                    KetChuyenData = new BindingList <KetChuyenValue>(controller.KetChuyenThanhPhamtableSelect(StartDate, EndDate, CommonInfo.CompanyInfo.CompanyID));
                    break;

                case "GV":
                    //Lấy dữ liệu giá vốn
                    KetChuyenData = new BindingList <KetChuyenValue>(controller.KetChuyenKetChuyenGiaVontableSelect(StartDate, EndDate, CommonInfo.CompanyInfo.CompanyID));
                    break;

                case "CK":
                    //Lấy dữ liệu cuối kỳ
                    KetChuyenData = new BindingList <KetChuyenValue>(controller.KetChuyenCuoiKytableSelect(StartDate, EndDate, CommonInfo.CompanyInfo.CompanyID));
                    break;
                }
                KetChuyenListData_gridControl.DataSource = KetChuyenData;
                #endregion Kết chuyển loại hình Du lịch, Xây dựng
            }
            else
            {
                #region kết chuyển loại hình thương mại, sản xuất
                KetChuyenData = new BindingList <KetChuyenValue>(controller.KetChuyentableSelect(StartDate, EndDate, CommonInfo.CompanyInfo.CompanyID));
                KetChuyenListData_gridControl.DataSource = KetChuyenData;
                #endregion kết chuyển loại hình thương mại, sản xuất
            }
        }
 private void Init_KetChuyen_GridView()
 {
     this.KetChuyenListData_gridView.Columns.Clear();
     this.KetChuyenListData_gridView.AddColumn("KetChuyenDebitAccountID", "TK Nợ", 110, false);
     this.KetChuyenListData_gridView.AddColumn("KetChuyenDebitAccountDetailID", "T.Kê Nợ", 60, false);
     this.KetChuyenListData_gridView.AddColumn("KetChuyenCreditAccountID", "TK Có", 110, false);
     this.KetChuyenListData_gridView.AddColumn("KetChuyenCreditAccountDetailID", "T.Kê Có", 60, false);
     this.KetChuyenListData_gridView.AddSpinEditColumn("Amount", "Tiền", 150, false, "###,###,###,###,##0");
     //this.KetChuyenListData_gridView.AddColumn("CustomerID", "Mã KH", 110, false);
     this.KetChuyenListData_gridView.AddSearchLookupEditColumn("CustomerID", "Mã KH", 60, VoucherControl.materialDT, "CustomerID", "CustomerSName", popupFormWidth: 850, isBestFitColumn: true, isAllowEdit: false);
     this.KetChuyenListData_gridView.AddSearchLookupEditColumn("QLID", VoucherControl.columnnameShowCompanyTypeMa, 110, VoucherControl._quanLies, "QLID", "QLMa", popupFormWidth: 850, isBestFitColumn: true, isAllowEdit: false);
     //Nếu tồn tại nghiệp vụ xây dựng, du lịch thì sẽ có mã công trình.
     if (CommonInfo.CompareCompanyType("DL") || CommonInfo.CompareCompanyType("XD"))
     {
         KetChuyenListData_gridView.Columns["QLID"].Visible = true;
     }
     else
     {
         KetChuyenListData_gridView.Columns["QLID"].Visible = false;
     }
 }
        public void InitDTCTGrid()
        {
            this.DTCT_gridView.Columns.Clear();
            //Cần hiển thị mã công trình
            // [QLID] [varchar](50) NULL,
            this.DTCT_gridView.AddSearchLookupEditColumn("QLID", VoucherControl.columnnameShowCompanyTypeMa, 60, VoucherControl._quanLies, "QLID", "QLMa", popupFormWidth: 850, isBestFitColumn: true, isAllowEdit: true, columns: VoucherControl.PopupColumnQuanLy());
            //Nếu tồn tại nghiệp vụ xây dựng, du lịch thì sẽ có mã công trình.
            if (CommonInfo.CompareCompanyType("DL") || CommonInfo.CompareCompanyType("XD"))
            {
                DTCT_gridView.Columns["QLID"].Visible = true;
            }
            else
            {
                DTCT_gridView.Columns["QLID"].Visible = false;
            }

            //Cần hiển thị tên sản phẩm
            // [ItemID] [varchar](50) NULL,
            List <ColumnInfo> columns = new List <ColumnInfo>
            {
                new ColumnInfo("ItemID", "ItemID", 140),
                new ColumnInfo("ItemSName", "Mã Hàng Hóa", 140),
                new ColumnInfo("ItemName", "Tên Hàng Hóa", 140),
                new ColumnInfo("ItemUnitID", "Đơn vị tính", 180),
            };

            this.DTCT_gridView.AddSearchLookupEditColumn("ItemID", "SP", 70, VoucherControl.items, "ItemID", "ItemSName", columns: columns, isAllowEdit: true);

            //Cần hiển thị tên đơn vị tính
            //    [ItemUnitID] [varchar](50) NULL,
            this.DTCT_gridView.AddColumn("ItemUnitID", "ĐVT", 40, false);
            //Cần hiển thị tên sản phẩm thay thế
            //     [ItemReplaceID] [varchar](50) NULL,
            this.DTCT_gridView.AddSearchLookupEditColumn("ItemReplaceID", "SP", 70, VoucherControl.items, "ItemID", "ItemSName", columns: columns, isAllowEdit: true);

            //Cần hiển thị đơn vị tính thay thế
            // [ItemUnitReplaceID] [varchar](50) NULL,
            this.DTCT_gridView.AddColumn("ItemUnitReplaceID", "ĐVT", 40, false);

            //Giữ nguyên như file excel
            // [MaVT] [varchar](50) NULL,
            this.DTCT_gridView.AddColumn("MaVT", "Mã vật tư", 75, true);
            //Giữ nguyên như file excel
            //[TenVT] [nvarchar](max) NULL,
            this.DTCT_gridView.AddColumn("TenVT", "Tên vật tư", 75, true);
            //Giữ nguyên như file excel
            //[SoLuong] [decimal](18, 0) NULL,
            this.DTCT_gridView.AddSpinEditColumn("SoLuong", "Số lượng", 75, true, "###,###,###,###,##0.00", DevExpress.Data.SummaryItemType.Sum, "{0:###,###,###,###,###}");

            //Giữ nguyên như file excel
            //[DonGia] [money] NULL,
            this.DTCT_gridView.AddSpinEditColumn("DonGia", "Đơn giá", 100, true, "###,###,###,###,##0", DevExpress.Data.SummaryItemType.Sum, "{0:###,###,###,###,###}");
            //Giữ nguyên như file excel
            //[ThanhTien] [money] NULL,
            this.DTCT_gridView.AddSpinEditColumn("ThanhTien", "Thành Tiền", 120, true, "###,###,###,###,##0", DevExpress.Data.SummaryItemType.Sum, "{0:###,###,###,###,###}");
            //Giữ nguyên như file excel
            // [STTUuTien] [int] NULL,
            this.DTCT_gridView.AddColumn("STTUuTien", "Ưu tiên", 50, true);
            //Phần mềm tính
            //[SoLuongXuat] [decimal](18, 0) NULL,
            this.DTCT_gridView.AddSpinEditColumn("SoLuongXuat", "SL Xuất", 100, true, "###,###,###,###,##0.00", DevExpress.Data.SummaryItemType.Sum, "{0:###,###,###,###,###}");

            //Phần mềm tính [Đây là đơn giá bình quân] - Nếu lách thì có các tính khác
            //[DonGiaXuat] [money] NULL,
            this.DTCT_gridView.AddSpinEditColumn("DonGiaXuat", "ĐG Xuất", 100, true, "###,###,###,###,##0", DevExpress.Data.SummaryItemType.Sum, "{0:###,###,###,###,###}");

            //Phần mềm tính
            //[ThanhTienXuat] [money] NULL,
            this.DTCT_gridView.AddSpinEditColumn("ThanhTienXuat", "TT Xuất", 120, true, "###,###,###,###,##0", DevExpress.Data.SummaryItemType.Sum, "{0:###,###,###,###,###}");

            //[Createuser] [varchar](50) NULL,
            this.DTCT_gridView.AddColumn("Createuser", "N.Tạo", 75, true);
            //[Updateuser] [varchar](50) NULL,
            this.DTCT_gridView.AddColumn("Updateuser", "N.Sửa", 75, true);

            DTCT_gridView.Columns["QLID"].ColumnEdit.KeyDown += DTCT_gridViewColumnsQLID_KeyDown;
        }
        private void KetChuyenSumit_simpleButton_Click(object sender, EventArgs e)
        {
            #region kiểm tra dữ liệu có đang bị khóa sổ
            if (VoucherControl.CheckLockDBCompany(KetChuyen_bsFromToDateEdit.ToDate.Date, CommonInfo.CompanyInfo.CompanyID))
            {
                //Dữ liệu đang nằm trong vùng khóa sổ
                MessageBoxHelper.ShowErrorMessage("Dữ liệu đang bị khóa sổ!\n");
                return;
            }
            #endregion kiểm tra dữ liệu có đang bị khóa sổ

            //Thực hiện cho loại hình không phải tour, công trình
            if (CommonInfo.CompareCompanyType("DL") || CommonInfo.CompareCompanyType("XD") || CommonInfo.CompareCompanyType("SX"))
            {
                #region Kết chuyển loại hình Du lịch, Xây dựng
                // Load_KetChuyen_GridView(KetChuyen_bsFromToDateEdit.FromDate.Date, this.KetChuyen_bsFromToDateEdit.ToDate.Date, CommonInfo.CompanyInfo.CompanyID);
                string value = KetChuyenType_radioGroup.EditValue.ToString();
                switch (value)
                {
                case "CK":
                    //Lấy dữ liệu cuối kỳ
                    LuuKCCK();
                    break;

                default:
                    //Lưu kết chuyển Dang Dở, Thành Phẩm, Giá Vốn
                    int statusKC = 0;
                    #region Kết chuyển loại hình Du lịch, Xây dựng
                    foreach (KetChuyenValue item in KetChuyenData)
                    {
                        if (item.Amount == 0)
                        {
                            continue;
                        }
                        #region set value to Insert Voucher
                        Voucher voucher = new Voucher
                        {
                            VoucherAmount      = item.Amount,
                            VoucherDescription = this.KetChuyenContent_textEdit.EditValue.ToString(),
                            VouchersTypeID     = "KC",
                            VoucherDate        = this.KetChuyen_bsFromToDateEdit.ToDate.Date,
                            CompanyID          = CommonInfo.CompanyInfo.CompanyID,
                            Status             = ModifyMode.Insert
                        };
                        #endregion set value to Insert Voucher
                        //Setup value to voucherdetail
                        List <VoucherDetail> VoucherDetailData = new List <VoucherDetail>();
                        VoucherDetail        voucherDetail     = new VoucherDetail
                        {
                            CompanyID       = CommonInfo.CompanyInfo.CompanyID,
                            AccountID       = item.KetChuyenCreditAccountID,
                            AccountDetailID = item.KetChuyenCreditAccountDetailID,
                            CustomerID      = item.CustomerID?.ToString(),
                            QLID            = item.QLID?.ToString(),
                            Amount          = item.Amount,
                            NV     = "C",
                            Status = ModifyMode.Insert
                        };
                        VoucherDetailData.Add(voucherDetail);
                        voucherDetail = new VoucherDetail
                        {
                            CompanyID       = CommonInfo.CompanyInfo.CompanyID,
                            AccountID       = item.KetChuyenDebitAccountID,
                            AccountDetailID = item.KetChuyenDebitAccountDetailID,
                            CustomerID      = item.CustomerID?.ToString(),
                            QLID            = item.QLID?.ToString(),
                            Amount          = item.Amount,
                            NV     = "N",
                            Status = ModifyMode.Insert
                        };
                        VoucherDetailData.Add(voucherDetail);
                        List <VoucherDetail> saveData = VoucherDetailData;
                        if (saveData?.Count > 0)
                        {
                            VoucherDetailController controller = new VoucherDetailController();
                            if (controller.SaveVoucher_Detail(saveData, voucher))
                            {
                                //  MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000001);
                            }
                            else
                            {
                                MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000002);
                                statusKC = 1;
                            }
                        }
                    }
                    Load_KetChuyen_GridView(KetChuyen_bsFromToDateEdit.FromDate.Date, this.KetChuyen_bsFromToDateEdit.ToDate.Date, CommonInfo.CompanyInfo.CompanyID);
                    if (statusKC == 0)
                    {
                        MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000001);
                    }
                    #endregion Kết chuyển loại hình Du lịch, Xây dựng
                    break;
                }
                #endregion Kết chuyển loại hình Du lịch, Xây dựng
            }
            else
            {
                LuuKCCK();
            }
        }