Exemplo n.º 1
0
        public bool _ExportExportCustom(TM.Connection.Oracle Oracle, TM.Connection.OleDBF FoxPro, Common.DefaultObj obj, Models.EXPORT_CUSTOM EXPORT_CUSTOM)
        {
            try
            {
                //Remove Old File
                TM.IO.FileDirectory.Delete($"{obj.DataSource}{EXPORT_CUSTOM.TABLE_NAME}.dbf", false);
                //Create New File
                FoxPro.Connection.Query(EXPORT_CUSTOM.QUERY_CREATE);

                var data         = Oracle.Connection.Query(EXPORT_CUSTOM.QUERY_SELECT.Replace("$kyhoadon", obj.KYHD.ToString())).ToList();
                var qry          = $"SELECT * FROM EXPORT_TABLE WHERE APP_KEY='{EXPORT_CUSTOM.ID}' AND TABLE_TYPE={(int)Common.Objects.TABLE_TYPE.EXPORT_CUSTOM}";
                var EXPORT_TABLE = Oracle.Connection.Query <Models.EXPORT_TABLE>(qry).ToList();
                var ColumnExport = new Dictionary <string, string>();
                FoxPro.Connection.InsertList3(EXPORT_CUSTOM.TABLE_NAME, EXPORT_TABLE, data);

                //Execute Query
                FoxPro.Connection.Query($"USE {EXPORT_CUSTOM.TABLE_NAME}");
                _ExportQueryExportCustom(FoxPro, EXPORT_CUSTOM.TABLE_NAME, EXPORT_CUSTOM.QUERY_END);
                //FoxPro.Connection.Query($"USE {EXPORT_CUSTOM.TABLE_NAME}");
                //if (EXPORT_CUSTOM.QUERY_END != null)
                //{
                //    var QUERY_END = EXPORT_CUSTOM.QUERY_END.Trim(';').Split(';');
                //    foreach (var i in QUERY_END)
                //        FoxPro.Connection.Query(i.Trim().TrimStart('\n').Replace("$table", EXPORT_CUSTOM.TABLE_NAME));
                //}
                //Delete .BAK
                FileManagerController.RemoveFileSource(obj.DataSource, false);
                return(true);
            }
            catch (Exception) { throw; }
        }
Exemplo n.º 2
0
        public JsonResult GeneralUpload(Common.DefaultObj obj)
        {
            var SQLServer = new TM.Connection.SQLServer();
            var index     = 0;

            obj.DataSource = Common.Directories.HDDataSource;
            obj            = getDefaultObj(obj);
            string strUpload = "Cập nhật thành công ";
            var    qry       = "";

            try
            {
                //
                qry = "SELECT * FROM DICHVU_VT_BKN WHERE TT_SUDUNG=2";
                var DICHVU_VT_BKN = SQLServer.Connection.Query <Models.DICHVU_VT_BKN>(qry);
                var fileUpload    = new List <string>();
                var dvvt          = DICHVU_VT_BKN.FirstOrDefault(d => d.DICHVUVT_ID == obj.data_id);
                if (obj.data_type == 0 || obj.data_type == 2)
                {
                    if (dvvt != null)
                    {
                        fileUpload.Add($"{dvvt.MA_DVVT.ToLower()}.dbf");
                    }
                    var upload = UploadData(obj.DataSource, strUpload, fileUpload);
                    if (upload == (int)Common.Objects.ResultCode._extension)
                    {
                        return(Json(new { danger = "Tệp phải định dạng .dbf!" }, JsonRequestBehavior.AllowGet));
                    }
                    else if (upload == (int)Common.Objects.ResultCode._length)
                    {
                        return(Json(new { danger = "Chưa đủ tệp!" }, JsonRequestBehavior.AllowGet));
                    }
                }
                if (dvvt != null && obj.data_type > 0)
                {
                    strUpload += ImportData(obj, dvvt);
                }
                //Delete .BAK
                FileManagerController.RemoveFileSource(obj.DataSource, false);
                return(Json(new { success = strUpload }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex) { return(Json(new { danger = ex.Message + " - Index: " + index }, JsonRequestBehavior.AllowGet)); }
        }
Exemplo n.º 3
0
        public JsonResult XuLyKH(Common.DefaultObj obj)
        {
            var ok    = new System.Text.StringBuilder();
            var err   = new System.Text.StringBuilder();
            var index = 0;

            obj.DataSource = Common.Directories.HDData;
            obj            = getDefaultObj(obj);
            var FoxPro   = new TM.Connection.OleDBF(obj.DataSource);
            var hddttime = obj.datetime.ToString("MMyyyy");

            // Loại bỏ
            obj.data_value = string.IsNullOrEmpty(obj.data_value) ? null : $",{obj.data_value.Trim(',')},";
            try
            {
                var listKey          = new List <string>();
                var hasError         = false;
                var fileName         = "cus";
                var hdallhddt        = "hdall_hddt" + obj.time;
                var fileNameDBFHDDT  = TM.OleDBF.DataSource + hdallhddt + ".dbf";
                var fileNameXMLFull  = TM.OleDBF.DataSource + fileName + ".xml";
                var fileNameZIPFull  = TM.OleDBF.DataSource + fileName + ".zip";
                var fileNameXMLError = TM.OleDBF.DataSource + fileName + "_Error.xml";
                //Xóa file HDDT cũ
                FileManagerController.DeleteDirFile(fileNameZIPFull);
                FileManagerController.DeleteDirFile(fileNameXMLError);
                //Get data from HDDT
                var data = FoxPro.Connection.Query <Models.HD_DT>($"SELECT * FROM {hdallhddt}").ToList().Trim(); //TM.OleDBF.ToDataTable("SELECT * FROM " + hdallhddt);
                using (System.IO.Stream outfile = new System.IO.FileStream(TM.IO.FileDirectory.MapPath(fileNameXMLFull), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
                {
                    ok.Append("<Customers>").AppendLine();
                    err.Append("<Customers>").AppendLine();
                    foreach (var i in data)
                    {
                        index++;
                        var MA_TT = i.MA_TT.Replace("-", "");
                        #region List Product
                        //<Product>
                        //<ProdName>Dịch vụ Internet</ProdName>
                        //<ProdUnit></ProdUnit>
                        //<ProdQuantity></ProdQuantity>
                        //<ProdPrice></ProdPrice>
                        //<Amount>1</Amount>
                        //</Product>
                        //<Product>
                        //<ProdName>Dịch vụ MyTv</ProdName>
                        //<ProdUnit></ProdUnit>
                        //<ProdQuantity></ProdQuantity>
                        //<ProdPrice></ProdPrice>
                        //<Amount>0</Amount>
                        //</Product>
                        //<Product>
                        //<ProdName>Dịch vụ Cố định</ProdName>
                        //<ProdUnit></ProdUnit>
                        //<ProdQuantity></ProdQuantity>
                        //<ProdPrice></ProdPrice>
                        //<Amount>20000</Amount>
                        //</Product>
                        //<Product>
                        //<ProdName>Dịch vụ Di động</ProdName>
                        //<ProdUnit></ProdUnit>
                        //<ProdQuantity></ProdQuantity>
                        //<ProdPrice></ProdPrice>
                        //<Amount>0</Amount>
                        //</Product>
                        //<Product>
                        //<ProdName>Khuyến mại, giảm trừ</ProdName>
                        //<ProdUnit></ProdUnit>
                        //<ProdQuantity></ProdQuantity>
                        //<ProdPrice></ProdPrice>
                        //<Amount>0</Amount>
                        //</Product>
                        #endregion
                        //Check EzPay
                        var check = true;
                        if (i.KIEU_TT == 1)
                        {
                            err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Is Ezpay</error></Inv>").AppendLine();
                            check    = false;
                            hasError = true;
                        }
                        //Check Error
                        if (string.IsNullOrEmpty(MA_TT))
                        {
                            err.Append($"<Customer><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Null Or Empty HDDT Khách hàng</error></Customer>").AppendLine();
                            check    = false;
                            hasError = true;
                        }
                        else
                        {
                            if (listKey.Contains(MA_TT))
                            {
                                err.Append($"<Customer><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Trùng mã thanh toán Khách hàng</error></Customer>").AppendLine();
                                check    = false;
                                hasError = true;
                            }
                        }
                        if (!string.IsNullOrEmpty(obj.data_value) && obj.data_value.IndexOf($",{MA_TT}{hddttime},") < 0)
                        {
                            err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Loại bỏ</error></Inv>").AppendLine();
                            check    = false;
                            hasError = true;
                        }
                        //Run
                        if (check)
                        {
                            var customer = "<Customer>" +
                                           $"<Name><![CDATA[{(obj.ckhTCVN3 ? i.TEN_TT.TCVN3ToUnicode() : i.TEN_TT)}]]></Name>" +
                                           $"<Code>{MA_TT}</Code>" +
                                           $"<TaxCode>{i.MS_THUE}</TaxCode>" +
                                           $"<Address><![CDATA[{(obj.ckhTCVN3 ? i.DIACHI_TT.TCVN3ToUnicode() : i.TEN_TT)}]]></Address>" +
                                           "<BankAccountName></BankAccountName>" +
                                           "<BankName></BankName>" +
                                           $"<BankNumber>{i.BANKNUMBER}</BankNumber>" +
                                           "<Email></Email>" +
                                           "<Fax></Fax>" +
                                           $"<Phone>{getCusPhone(i.ACC_NET, i.ACC_TV, i.SO_DD, i.SO_CD)}</Phone>" +
                                           "<ContactPerson></ContactPerson>" +
                                           "<RepresentPerson></RepresentPerson>" +
                                           "<CusType>0</CusType>" +
                                           $"<MaThanhToan><![CDATA[{getMaThanhToanKH(obj.month_year_time, MA_TT, i.MA_IN == 2 ? Common.HDDT.DetailDiDong : Common.HDDT.DetailCoDinh)}]]></MaThanhToan>" +
                                           "</Customer>";
                            ok.Append(customer).AppendLine();
                            listKey.Add(MA_TT);
                        }
                        if (index % 100 == 0)
                        {
                            outfile.Write(System.Text.Encoding.UTF8.GetBytes(ok.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(ok.ToString()));
                            ok = new System.Text.StringBuilder();
                        }
                    }
                    ok.Append("</Customers>");
                    outfile.Write(System.Text.Encoding.UTF8.GetBytes(ok.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(ok.ToString()));
                    //
                    outfile.Close();
                }
                if (hasError)
                {
                    using (System.IO.Stream outfile = new System.IO.FileStream(TM.IO.FileDirectory.MapPath(fileNameXMLError), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
                    {
                        err.Append("</Customers>");
                        outfile.Write(System.Text.Encoding.UTF8.GetBytes(err.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(err.ToString()));
                        outfile.Close();
                    }
                    //this.danger("Có lỗi xảy ra Truy cập File Manager \"~\\" + TM.OleDBF.DataSource.Replace("Uploads\\", "") + "\" để tải file");
                }
                //ZipFile
                if (obj.ckhZipFile)
                {
                    TM.IO.Zip.ZipFile(new List <string>()
                    {
                        fileNameXMLFull
                    }, fileNameZIPFull, 9);
                }
                //Insert To File Manager
                FileManagerController.DeleteDirFile(fileNameXMLFull);
                FileManagerController.InsertFile(fileNameZIPFull);
                FileManagerController.InsertFile(fileNameXMLError);
                //Insert To File Manager hdallhddt
                FileManagerController.InsertFile(fileNameDBFHDDT);
                //Delete .BAK
                FileManagerController.RemoveFileSource(obj.DataSource, false);
                return(Json(new { success = $"Tạo hóa đơn điện tử thành công! Truy cập File Manager \"~\\{TM.OleDBF.DataSource.Replace("Uploads\\", "")}\" để tải file" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex) { return(Json(new { danger = $"{ex.Message} - Index: {index}" }, JsonRequestBehavior.AllowGet)); }
            finally { FoxPro.Close(); }
        }
Exemplo n.º 4
0
        public ActionResult Mergin(string time, bool ckhMerginMonth)
        {
            try
            {
                //Declare
                var    hdall = "hdall" + time;
                string hdcd  = "hdcd" + time;
                string hddd  = "hddd" + time;
                string hdnet = "hdnet" + time;
                string hdtv  = "hdtv" + time;
                //Kiểm tra tháng đầu vào
                if (ckhMerginMonth)
                {
                    time = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
                }
                //Source
                var fileNameSource = new List <string>();
                var dtMergin       = new System.Data.DataTable();
                var check_file     = 0;
                fileNameSource.Add(hdcd + ".dbf");
                fileNameSource.Add(hddd + ".dbf");
                fileNameSource.Add(hdnet + ".dbf");
                fileNameSource.Add(hdtv + ".dbf");
                //Datasource
                TM.OleDBF.DataSource = TM.Common.Directories.HDData + time + "\\";

                var fileList = TM.IO.FileDirectory.FilesToList(TM.OleDBF.DataSource);
                foreach (var item in fileList)
                {
                    if (fileNameSource.Contains(item))
                    {
                        check_file++;
                    }
                }
                if (check_file < 4)
                {
                    this.danger("Chưa tải đủ tệp!");
                    return(RedirectToAction("Index"));
                }

                //Xóa file hdall cũ
                FileManagerController.DeleteDirFile(TM.OleDBF.DataSource + hdall + ".dbf");

                //Tạo bảng hóa đơn ghép
                //Mã in
                //- gộp = 1
                //- net = 2
                //- tv = 3
                //- cd = 4
                //- dd = 5
                TM.OleDBF.CreateTable(hdall, new Dictionary <string, string>()
                {
                    { "ma_dvi", "n(10)" },
                    { "ma_tt", "c(20)" },
                    { "acc_net", "c(20)" },
                    { "acc_tv", "c(20)" },
                    { "so_dd", "c(20)" },
                    { "so_cd", "c(20)" },
                    { "ten_tt", "c(100)" },
                    { "diachi_tt", "c(150)" },
                    { "dienthoai", "c(20)" },
                    { "ma_tuyen", "c(10)" },
                    { "ms_thue", "c(15)" },
                    { "banknumber", "c(16)" },
                    { "ma_dt", "n(10)" },
                    { "ma_cbt", "n(15)" },
                    { "tong_cd", "n(15)" },
                    { "tong_dd", "n(15)" },
                    { "tong_net", "n(15)" },
                    { "tong_tv", "n(15)" },
                    { "vat", "n(15,2)" },
                    { "tong", "n(15)" },
                    { "kthue", "n(15)" },
                    { "giam_tru", "n(15)" },
                    { "tongcong", "n(15)" },
                    { "stk", "c(100)" },
                    { "ezpay", "n(1)" },
                    { "kieu", "c(10)" },
                    { "ghep", "n(1)" },
                    { "ma_in", "n(1)" },
                    { "kieu_tt", "n(1)" },
                    { "flag", "n(1)" },
                    { "app_id", "n(10)" },
                });
                #region old
                //TM.OleDBF.Execute(
                //    "CREATE TABLE " + hdall + @"(
                //        [Ma_dvi] n(2),
                //        [ma_cq] c(50),
                //        [acc_net] c(50),
                //        [acc_tv] c(50),
                //        [so_dd] c(50),
                //        [so_cd] c(50),
                //        [ten_tb] c(100),
                //        [dia_chi] c(100),
                //        [ma_tuyen] c(50),
                //        [ma_st] c(15),
                //        [banknumber] c(16),
                //        [ma_dt] n(1),
                //        [ma_cbt] n(15),
                //        [tong_cd] n(12),
                //        [tong_dd] n(12),
                //        [tong_net] n(12),
                //        [tong_tv] n(12),
                //        [vat] n(12, 2),
                //        [tong] n(12),
                //        [kthue] n(12),
                //        [giam_tru] n(12),
                //        [tongcong] n(12),
                //        [ezpay] n(1),
                //        [Kieu] c(10),
                //        [ghep] n(1),
                //        [ma_in] n(1),
                //        [flag] n(1),
                //        [app_id] n(10))", hdall);
                #endregion

                //insert_hdall
                //Nhập hóa đơn cố định vào hóa đơn ghép
                TM.OleDBF.Execute(InsertString(hdall, hdcd, new Dictionary <string, string>()
                {
                    { "ma_dvi", "dvql_id" },
                    { "ma_tt", "Ma_kh1" },
                    { "so_cd", "so_tb" },
                    { "ten_tt", "ten_cq" },
                    { "diachi_tt", "dia_chi" },
                    { "ma_tuyen", "ma_tuyen" },
                    { "ms_thue", "ma_st" },
                    { "ma_dt", "ma_dt" },
                    { "ma_cbt", "ma_cbt" },
                    { "tong_cd", "tong" },
                    { "vat", "vat" },
                    { "tong", "tong" },
                    { "tongcong", "tong_cuoc" },
                    { "ezpay", "0" },
                    { "kieu", "1" },
                    { "ghep", "0" },
                    { "ma_in", "4" },
                    { "flag", "1" },
                }), "Insert " + hdcd);

                //Nhập hóa đơn net vào hóa đơn ghép
                TM.OleDBF.Execute(InsertString(hdall, hdnet, new Dictionary <string, string>()
                {
                    { "ma_dvi", "ma_dvi" },
                    { "ma_tt", "ma_tt" },
                    { "acc_net", "ma_tb" },
                    { "ten_tt", "ten_tt" },
                    { "diachi_tt", "diachi_tt" },
                    { "dienthoai", "dienthoai" },
                    { "ma_tuyen", "ma_tuyen" },
                    { "ms_thue", "ms_thue" },
                    { "ma_dt", "ma_dt" },
                    { "ma_cbt", "ma_cbt" },
                    { "tong_net", "Tong" },
                    { "vat", "vat" },
                    { "tong", "tong" },
                    { "tongcong", "tongcong" },
                    { "ezpay", "0" },
                    { "kieu", "1" },
                    { "ghep", "0" },
                    { "ma_in", "2" },
                    { "flag", "1" },
                }), "Insert " + hdnet);

                //Nhập hóa đơn tv vào hóa đơn ghép
                TM.OleDBF.Execute(InsertString(hdall, hdtv, new Dictionary <string, string>()
                {
                    { "ma_dvi", "ma_dvi" },
                    { "ma_tt", "ma_tt" },
                    { "acc_tv", "ma_tb" },
                    { "ten_tt", "ten_tt" },
                    { "diachi_tt", "diachi_tt" },
                    { "dienthoai", "dienthoai" },
                    { "ma_tuyen", "ma_tuyen" },
                    { "ms_thue", "ms_thue" },
                    { "ma_dt", "ma_dt" },
                    { "ma_cbt", "ma_cbt" },
                    { "tong_tv", "Tong" },
                    { "vat", "vat" },
                    { "tong", "tong" },
                    { "tongcong", "tongcong" },
                    { "ezpay", "0" },
                    { "kieu", "1" },
                    { "ghep", "0" },
                    { "ma_in", "3" },
                    { "flag", "1" },
                }), "Insert " + hdtv);

                //Nhập hóa đơn di động vào hóa đơn ghép
                TM.OleDBF.Execute(InsertString(hdall, hddd, new Dictionary <string, string>()
                {
                    { "ma_dvi", "ma_dvi" },
                    { "ma_tt", "ma_cq" },
                    { "so_dd", "so_tb" },
                    { "ten_tt", "ten_tt" },
                    { "diachi_tt", "diachi_tt" },
                    { "ma_tuyen", "ma_tuyen" },
                    { "ms_thue", "ms_thue" },
                    { "banknumber", "taikhoan" },
                    { "ma_dt", "ma_dt" },
                    { "ma_cbt", "ma_cbt" },
                    { "tong_dd", "cuoc_cthue" },
                    { "vat", "thue" },
                    { "tong", "cuoc_cthue+cuoc_kthue" },
                    { "kthue", "cuoc_kthue" },
                    { "giam_tru", "giamtru" },
                    { "tongcong", "tongcong" },
                    { "ezpay", "ezpay" },
                    { "kieu", "1" },
                    { "ghep", "0" },
                    { "ma_in", "5" },
                    { "flag", "1" },
                }), "Insert " + hddd);

                //Update Ma_dt 0 -> 1
                TM.OleDBF.Execute($"UPDATE {hdall} SET ma_dt=1 WHERE ma_dt=0", hdall);

                //Remove tongcong<=1000
                TM.OleDBF.Execute($"UPDATE {hdall} SET flag=0 WHERE tongcong<=1000", hdall);

                //Tạo thêm cột app_id
                //try
                //{
                //    TM.OleDBF.Execute(string.Format("ALTER TABLE {0} ADD COLUMN {1} n(10)", file, app_id), "Tạo cột app_id - " + extraEX);
                //}
                //catch (Exception) { }
                //Cập nhật app_id = Auto Increment
                //TM.OleDBF.Execute(string.Format("UPDATE {0} SET {1}=RECNO()", hdall, app_id), "Cập nhật app_id = Auto Increment ");

                //Remove Duplicate hdall
                //Xử lý trùng mã thanh toán khác đơn vị
                RemoveDuplicate(TM.OleDBF.DataSource, hdall,
                                new string[] { "tong_cd", "tong_dd", "tong_net", "tong_tv", "vat", "tong", "kthue", "giam_tru", "tongcong" },
                                new string[] { "acc_net", "acc_tv", "so_dd", "so_cd", "diachi_tt", "ma_tuyen", "ms_thue", "ma_dt", "ma_cbt" },
                                "Remove Duplicate hoadon", "ma_dvi", "ma_tt", "ma_in=1");
                //Cập nhật STK
                UpdateSTK_MA_DVI(Common.Objects.stk_ma_dvi, hdall);

                //Update NULL
                TM.OleDBF.Execute($"UPDATE {hdall} SET ezpay=0 WHERE ezpay is null", hdall);
                TM.OleDBF.Execute($"UPDATE {hdall} SET tong_cd=0 WHERE tong_cd is null", hdall);
                TM.OleDBF.Execute($"UPDATE {hdall} SET tong_dd=0 WHERE tong_dd is null", hdall);
                TM.OleDBF.Execute($"UPDATE {hdall} SET tong_net=0 WHERE tong_net is null", hdall);
                TM.OleDBF.Execute($"UPDATE {hdall} SET tong_tv=0 WHERE tong_tv is null", hdall);
                TM.OleDBF.Execute($"UPDATE {hdall} SET kthue=0 WHERE kthue is null", hdall);
                TM.OleDBF.Execute($"UPDATE {hdall} SET giam_tru=0 WHERE giam_tru is null", hdall);

                //Remove Bak file
                var deleteFile = FileManagerController.RemoveFileSource(TM.OleDBF.DataSource);

                //Add hdall to FileManager
                FileManagerController.InsertFile(TM.OleDBF.DataSource + hdall + ".dbf");

                //Return Download File
                //return RedirectToAction("DownloadFiles");
                this.success("Ghép hóa đơn thành công");
            }
            catch (Exception ex)
            {
                this.danger(ex.Message);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public ActionResult MerginSelf(string time, bool ckhMerginMonth)
        {
            try
            {
                //Kiểm tra tháng đầu vào
                if (ckhMerginMonth)
                {
                    time = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
                }
                //Declare
                string hdcd  = "hdcd" + time;
                string hddd  = "hddd" + time;
                string hdnet = "hdnet" + time;
                string hdtv  = "hdtv" + time;
                //Source
                var fileNameSource = new List <string>();
                fileNameSource.Add(hdcd + ".dbf");
                fileNameSource.Add(hddd + ".dbf");
                fileNameSource.Add(hdnet + ".dbf");
                fileNameSource.Add(hdtv + ".dbf");
                //Datasource
                TM.OleDBF.DataSource = TM.Common.Directories.HDData + time + "\\";

                //Delete old File
                //var fileList = TM.IO.FileDirectory.FilesToList(TM.OleDBF.DataSource);
                //foreach (var item in fileList)
                //    if (!fileNameSource.Contains(item.ToLower()))
                //        FileManagerController.DeleteDirFile(TM.OleDBF.DataSource + item); //TM.IO.FileDirectory.Delete(DataSource + item);
                //    else
                //        check_file++;
                //var deleteFile = RemoveFileSource(TM.OleDBF.DataSource, ".bak", fileNameSource);
                var deleteFile = FileManagerController.RemoveFileSource(TM.OleDBF.DataSource);

                //if (deleteFile.CountException < 4)
                //{
                //    //this.danger("Vui lòng chọn đủ 4 tệp hdcd+MM+yy.dbf, hddd+MM+yy.dbf, hdnet+MM+yy.dbf, hdtv+MM+yy.dbf !");
                //    this.danger("Chưa tải đủ tệp!");
                //    return RedirectToAction("Index");
                //}

                //Backup File
                //TM.IO.FileDirectory.Copy(TM.OleDBF.DataSource + hdcd + ".dbf", TM.OleDBF.DataSource + hdcd + "_old.dbf");
                //FileManagerController.InsertFile(TM.OleDBF.DataSource + hdcd + "_old.dbf");
                //TM.IO.FileDirectory.Copy(TM.OleDBF.DataSource + hdnet + ".dbf", TM.OleDBF.DataSource + hdnet + "_old.dbf");
                //FileManagerController.InsertFile(TM.OleDBF.DataSource + hdnet + "_old.dbf");
                //TM.IO.FileDirectory.Copy(TM.OleDBF.DataSource + hdtv + ".dbf", TM.OleDBF.DataSource + hdtv + "_old.dbf");
                //FileManagerController.InsertFile(TM.OleDBF.DataSource + hdtv + "_old.dbf");
                //TM.IO.FileDirectory.Copy(TM.OleDBF.DataSource + hddd + ".dbf", TM.OleDBF.DataSource + hddd + "_old.dbf");
                //FileManagerController.InsertFile(TM.OleDBF.DataSource + hddd + "_old.dbf");

                //Remove Duplicate
                RemoveDuplicate(TM.OleDBF.DataSource, hdcd, new string[] { "tong", "vat", "tong_cuoc" },
                                new string[] { "ten_cq", "dia_chi", "ma_st" }, "Remove Duplicate " + hdcd, "dvql_id", "ma_kh1");

                RemoveDuplicate(TM.OleDBF.DataSource, hddd, new string[] { "cuoc_cthue", "thue", "tongcong", "cuoc_kthue", "giamtru" },
                                new string[] { "ten_tt", "diachi_tt", "ms_thue", "taikhoan" }, "Remove Duplicate " + hddd, "ma_dvi", "ma_cq");

                RemoveDuplicate(TM.OleDBF.DataSource, hdnet, new string[] { "tong", "vat", "tongcong" },
                                new string[] { "ten_tt", "diachi_tt", "ms_thue", "dienthoai" }, "Remove Duplicate " + hdnet, "ma_dvi", "ma_tt");

                RemoveDuplicate(TM.OleDBF.DataSource, hdtv, new string[] { "tong", "vat", "tongcong" },
                                new string[] { "ten_tt", "diachi_tt", "ms_thue", "dienthoai" }, "Remove Duplicate " + hdtv, "ma_dvi", "ma_tt");

                ReExtensionToLower(TM.OleDBF.DataSource);

                //Update HDCD
                TM.OleDBF.Execute("ALTER TABLE " + hdcd + " ALTER COLUMN Dia_chi char(100)", hdcd);
                TM.OleDBF.Execute("ALTER TABLE " + hdcd + " ALTER COLUMN Ma_cq char(30)", hdcd);

                //Update Ezpay HDDD
                TM.OleDBF.Execute("UPDATE " + hddd + " SET ezpay=0 WHERE ezpay is null", "UPDATE Ezpay " + hddd);

                //Remove Bak file
                deleteFile = FileManagerController.RemoveFileSource(TM.OleDBF.DataSource);

                this.success("Ghép hóa đơn lẻ thành công!");
            }
            catch (Exception ex)
            {
                this.danger(ex.Message);
            }
            return(RedirectToAction("Index"));
        }