Exemplo n.º 1
0
 public ActionResult Index()
 {
     FileManagerController.InsertDirectory(Common.Directories.HDData);
     ViewBag.directory = TM.IO.FileDirectory.DirectoriesToList(Common.Directories.HDData).OrderByDescending(d => d).ToList();
     //var b = "LỚP TRUNG CẤP LÝ LUẬN CHÍNH TRỊ".UnicodeToTCVN3();
     //var c = "Lớp Trung Cấp Lý Luận Chính Trị".UnicodeToTCVN3();
     return(View());
 }
Exemplo n.º 2
0
        public JsonResult ExportToDBF(Common.DefaultObj obj)
        {
            var OWNER  = "TTKD_BKN";
            var Oracle = new TM.Connection.Oracle(OWNER);
            var index  = 0;

            obj.DataSource = Common.Directories.HDData;
            FileManagerController.InsertDirectory(obj.DataSource);
            obj = getDefaultObj(obj);
            FileManagerController.InsertDirectory(obj.DataSource, false);
            //
            var FoxPro = new TM.Connection.OleDBF(obj.DataSource);

            try
            {
                var tmp_qry_fox  = "";
                var tmp_qry_sql  = "";
                var condition    = "";
                var qry          = $"SELECT * FROM EXPORT_TABLE WHERE TABLE_TYPE={(int)Common.Objects.TABLE_TYPE.DBF} AND TABLE_NAME='{obj.file}' AND FLAG=1 ORDER BY ORDERS";
                var EXPORT_TABLE = Oracle.Connection.Query <Models.EXPORT_TABLE>(qry).ToList();
                //
                if (EXPORT_TABLE.Count <= 0)
                {
                    return(Json(new { warning = "Vui lòng cấu hình dữ liệu Export trước!" }, JsonRequestBehavior.AllowGet));
                }
                qry = CreateTable(obj.DataSource, obj.file, EXPORT_TABLE);
                FoxPro.Connection.Query(qry);
                //
                var ColumnExport = new List <string>();
                foreach (var i in EXPORT_TABLE)
                {
                    ColumnExport.Add(i.COLUMN_NAME_EXPORT);
                    tmp_qry_fox += $"{i.COLUMN_NAME_EXPORT},";
                    tmp_qry_sql += $"{i.COLUMN_NAME},";
                    if (!string.IsNullOrEmpty(i.CONDITION))
                    {
                        condition += MappingCondition(i.COLUMN_TYPE, i.COLUMN_NAME, i.CONDITION) + " AND ";
                    }
                }
                //
                qry = $"SELECT {tmp_qry_sql.Trim(',')} FROM {obj.file} {(!string.IsNullOrEmpty(condition) ? "WHERE " + condition.Substring(0, condition.Length - 5) : "")}";
                var data = Oracle.Connection.Query <dynamic>(qry).ToList();
                //FoxPro.Insert(data);
                //
                qry = $"INSERT INTO {obj.file}({tmp_qry_fox.Trim(',')}) VALUES(";
                foreach (var i in data)
                {
                    qry += "";
                }
                CRUDFoxPro.InsertList(FoxPro.Connection, obj.file, ColumnExport, data);
                FileManagerController.InsertFile(obj.DataSource + obj.file + ".DBF", false);
                return(Json(new { success = "Xử lý thành công!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex) { return(Json(new { danger = ex.Message + " - Index: " + index }, JsonRequestBehavior.AllowGet)); }
            finally { Oracle.Connection.Close(); FoxPro.Connection.Close(); }
        }
Exemplo n.º 3
0
 public ActionResult Index()
 {
     try
     {
         FileManagerController.InsertDirectory(Common.Directories.HDDataSource);
         ViewBag.directory = TM.IO.FileDirectory.DirectoriesToList(Common.Directories.HDDataSource).OrderByDescending(d => d).ToList();
     }
     catch (Exception ex) { this.danger(ex.Message); }
     return(View());
 }
Exemplo n.º 4
0
 public ActionResult Index()
 {
     try
     {
         var SQLServer = new TM.Connection.SQLServer();
         FileManagerController.InsertDirectory(Common.Directories.HDData);
         ViewBag.directory = TM.IO.FileDirectory.DirectoriesToList(Common.Directories.HDData).OrderByDescending(d => d).ToList();
         ViewBag.dvvt      = SQLServer.Connection.Query <Models.DICHVU_VT_BKN>("SELECT * FROM DICHVU_VT_BKN WHERE TT_UPLOAD=1 AND FLAG=1 ORDER BY ORDERS");
     }
     catch (Exception ex) { this.danger(ex.Message); }
     return(View());
 }
Exemplo n.º 5
0
        public int UploadBase(string DataSource, string strResult = null, List <string> fileUpload = null, string Extension = ".dbf")
        {
            try
            {
                int uploadedCount = 0;
                if (Request.Files.Count > 0)
                {
                    FileManagerController.InsertDirectory(DataSource, false);
                    if (fileUpload == null)
                    {
                        fileUpload = new List <string>();
                    }
                    var fileSavePath = new List <string>();
                    //Delete old File
                    //TM.IO.Delete(obj.DataSource, TM.IO.Files(obj.DataSource));

                    for (int i = 0; i < Request.Files.Count; i++)
                    {
                        var file = Request.Files[i];
                        if (!file.FileName.IsExtension(Extension))
                        {
                            return((int)Common.Objects.ResultCode._extension);
                        }

                        if (file.ContentLength > 0)
                        {
                            if (fileUpload.Count < 1)
                            {
                                fileUpload.Add(file.FileName.ToLower());//System.IO.Path.GetFileName(
                            }
                            fileSavePath.Add(DataSource + fileUpload[i]);
                            file.SaveAs(System.IO.Path.Combine(fileSavePath[i]));
                            uploadedCount++;
                            FileManagerController.InsertFile(DataSource + fileUpload[i], false);
                        }
                    }
                    var rs = "Tải lên thành công </br>";
                    foreach (var item in fileUpload)
                    {
                        rs += item + "<br/>";
                    }
                    strResult = rs;
                    return((int)Common.Objects.ResultCode._success);
                }
                else
                {
                    return((int)Common.Objects.ResultCode._length);
                }
            }
            catch (Exception) { throw; }
        }
Exemplo n.º 6
0
        public JsonResult RemoveDuplicate(ObjAdditionalTools obj)
        {
            try
            {
                TM.IO.FileDirectory.CreateDirectory(TM.Common.Directories.orther);
                var file = TM.IO.FileDirectory.Upload(Request.Files, TM.Common.Directories.orther, false, new[] { ".dbf" });
                if (file.UploadError().Count > 0)
                {
                    return(Json(new { danger = "Vui lòng chọn file DBF trước khi thực hiện!" }));
                }
                var fileName     = file.UploadFileString();
                var fileNameFull = TM.Common.Directories.orther + fileName;
                TM.OleDBF.DataSource = fileNameFull;
                //
                var ExtraValueList = new List <string>();
                var ExtraValueStr  = "";
                var ExtraValueStr2 = "";
                var ExtraValueStr3 = "";
                if (obj.ExtraValue != null)
                {
                    ExtraValueStr = obj.ExtraValue.Trim().Trim(',');
                    ExtraValueList.AddRange(ExtraValueStr.Split(',').Trim());
                    foreach (var i in ExtraValueList)
                    {
                        ExtraValueStr2 += $"o.{i}=oc.{i} AND ";
                        ExtraValueStr3 += $"o.{i},";
                    }
                    ExtraValueStr2 = ExtraValueStr2.Substring(0, ExtraValueStr2.Length - 5);
                    ExtraValueStr3 = ExtraValueStr3.Trim(',');
                }
                else
                {
                    obj.IsExtraValue = false;
                }
                //
                string sql = $"ALTER table {fileName} ADD COLUMN app_id n(10)";
                try
                {
                    TM.OleDBF.Execute(sql);
                }
                catch (Exception) { }
                sql = $"ALTER table {fileName} ADD COLUMN dupe_flag n(2)";
                try
                {
                    TM.OleDBF.Execute(sql);
                }
                catch (Exception) { }
                sql = $"UPDATE {fileName} SET app_id=RECNO()";
                TM.OleDBF.Execute(sql);
                sql = $"UPDATE {fileName} SET dupe_flag=0";
                TM.OleDBF.Execute(sql);

                if (obj.IsExtraValue)
                {
                    sql = $"UPDATE {fileName} SET dupe_flag=1 WHERE app_id in(SELECT app_id FROM {fileName} o INNER JOIN (SELECT {obj.PrimeryKey},{ExtraValueStr},COUNT(*) AS dupeCount FROM {fileName} GROUP BY {obj.PrimeryKey},{ExtraValueStr} HAVING COUNT(*) > 1) oc ON o.{obj.PrimeryKey}=oc.{obj.PrimeryKey} WHERE {ExtraValueStr2})";
                }
                else
                {
                    sql = $"UPDATE {fileName} SET dupe_flag=1 WHERE app_id in(SELECT app_id FROM {fileName} o INNER JOIN (SELECT {obj.PrimeryKey},COUNT(*) AS dupeCount FROM {fileName} GROUP BY {obj.PrimeryKey} HAVING COUNT(*) > 1) oc ON o.{obj.PrimeryKey}=oc.{obj.PrimeryKey})";
                }
                TM.OleDBF.Execute(sql);

                if (obj.IsExtraValue)
                {
                    sql = $"UPDATE {fileName} SET dupe_flag=2 WHERE app_id IN(SELECT MAX(app_id) FROM {fileName} o INNER JOIN (SELECT {obj.PrimeryKey},{obj.ExtraValue},COUNT(*) AS dupeCount FROM {fileName} GROUP BY {obj.PrimeryKey},{obj.ExtraValue} HAVING COUNT(*) > 1) oc ON o.{obj.PrimeryKey}=oc.{obj.PrimeryKey} WHERE {ExtraValueStr2} GROUP BY {ExtraValueStr3})";
                }
                //sql = $"UPDATE {fileName} SET dupe_flag=2 WHERE app_id IN(SELECT MAX(app_id) FROM {fileName} o INNER JOIN (SELECT {obj.PrimeryKey},{ExtraValueStr},COUNT(*) AS dupeCount FROM {fileName} GROUP BY {obj.PrimeryKey},{ExtraValueStr} HAVING COUNT(*) > 1) oc ON o.{obj.PrimeryKey}=oc.{obj.PrimeryKey} WHERE {ExtraValueStr2})";
                else
                {
                    sql = $"UPDATE {fileName} SET dupe_flag=2 WHERE app_id IN(SELECT MAX(app_id) FROM {fileName} o INNER JOIN (SELECT {obj.PrimeryKey},COUNT(*) AS dupeCount FROM {fileName} GROUP BY {obj.PrimeryKey} HAVING COUNT(*) > 1) oc ON o.{obj.PrimeryKey}=oc.{obj.PrimeryKey} GROUP BY o.{obj.PrimeryKey})";
                }
                TM.OleDBF.Execute(sql);

                sql = $"DELETE FROM {fileName} WHERE dupe_flag=1";
                TM.OleDBF.Execute(sql);
                sql = $"PACK {fileName}";
                TM.OleDBF.Execute(sql);
                FileManagerController.InsertDirectory(TM.Common.Directories.orther);
                FileManagerController.InsertFile(TM.OleDBF.DataSource);
                return(Json(new { success = "Xử lý Thành công!", url = UrlDownloadFiles(TM.OleDBF.DataSource, $"{fileName.ToLower().Replace(".dbf", "")}_RemoveDuplicate.dbf") }, JsonRequestBehavior.AllowGet));
                // return DownloadFiles(TM.OleDBF.DataSource, fileName.ToLower().Replace(".dbf", "") + "_RemoveDuplicate.dbf");
            }
            catch (Exception ex) { return(Json(new { danger = ex.Message }, JsonRequestBehavior.AllowGet)); }
        }
Exemplo n.º 7
0
        public JsonResult ExportExportCustom(Common.DefaultObj obj)
        {
            var OWNER  = "TTKD_BKN";
            var Oracle = new TM.Connection.Oracle(OWNER);
            var index  = 0;

            obj.DataSource = Common.Directories.HDData;
            obj            = getDefaultObj(obj);
            FileManagerController.InsertDirectory(obj.DataSource, false);
            var FoxPro = new TM.Connection.OleDBF(obj.DataSource);

            try
            {
                var qry           = $"SELECT * FROM EXPORT_CUSTOM WHERE ID='{obj.file}'";
                var EXPORT_CUSTOM = Oracle.Connection.QueryFirstOrDefault <Models.EXPORT_CUSTOM>(qry);
                if (EXPORT_CUSTOM == null)
                {
                    return(Json(new { success = TM.Common.Language.msgUpdateSucsess }, JsonRequestBehavior.AllowGet));
                }
                if (obj.data_value == Common.Objects.EXPORT_CUSTOM.DEFAULT.ToString())
                {
                    var rs = _ExportExportCustom(Oracle, FoxPro, obj, EXPORT_CUSTOM);
                    if (!rs)
                    {
                        return(Json(new { danger = "Lỗi kết xuất, vui lòng thử lại" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else if (obj.data_value == Common.Objects.EXPORT_CUSTOM.MODULES.ToString())
                {
                    var tableList = EXPORT_CUSTOM.TABLE_LIST.Trim(',').Split(',');
                    if (tableList.Length < 1)
                    {
                        return(Json(new { warning = "Chưa có kết xuất!" }, JsonRequestBehavior.AllowGet));
                    }
                    foreach (var item in tableList)
                    {
                        if (string.IsNullOrEmpty(item))
                        {
                            continue;
                        }
                        qry = $"SELECT * FROM EXPORT_CUSTOM WHERE NAME='{item}' AND TYPE_NAME='{Common.Objects.EXPORT_CUSTOM.DEFAULT}'";
                        var _export = Oracle.Connection.QueryFirstOrDefault <Models.EXPORT_CUSTOM>(qry);
                        var rs      = _ExportExportCustom(Oracle, FoxPro, obj, _export);

                        //
                        if (!string.IsNullOrEmpty(EXPORT_CUSTOM.QUERY_CREATE))
                        {
                            _ExportQueryExportCustom(FoxPro, EXPORT_CUSTOM.TABLE_NAME, EXPORT_CUSTOM.QUERY_CREATE);
                        }
                        if (!string.IsNullOrEmpty(EXPORT_CUSTOM.QUERY_END))
                        {
                            _ExportQueryExportCustom(FoxPro, EXPORT_CUSTOM.TABLE_NAME, EXPORT_CUSTOM.QUERY_END);
                        }

                        if (!rs)
                        {
                            return(Json(new { danger = "Lỗi kết suất, vui lòng thử lại" }, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                // FileManagerController.ReExtensionToLower($"{Common.Directories.HDData}{obj.time}");
                var fileExport = $"{Common.Directories.HDData}{obj.time}\\{EXPORT_CUSTOM.TABLE_NAME}.dbf";
                var fileName   = $"{EXPORT_CUSTOM.TABLE_NAME}{obj.datetime.ToString("yyyyMM")}.dbf";
                if (new System.IO.FileInfo(Server.MapPath($"~/{fileExport}")).Exists)
                {
                    return(Json(new { success = "Kết xuất thành công!", url = UrlDownloadFiles(fileExport, fileName) }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { success = "Kết xuất thành công!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex) { return(Json(new { danger = ex.Message }, JsonRequestBehavior.AllowGet)); }
            finally { Oracle.Connection.Close(); FoxPro.Connection.Close(); }
        }
Exemplo n.º 8
0
        public ActionResult UploadFiles(FormCollection collection)
        {
            try
            {
                var ckhMerginMonth = collection["ckhMerginMonth"] != null ? true : false;
                var time           = collection["time"].ToString();
                //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
                //DataSource = Server.MapPath("~/Uploads/Data/");
                //TM.IO.FileDirectory.CreateDirectory(DataSource);
                var DataSource = TM.Common.Directories.HDData;
                FileManagerController.InsertDirectory(DataSource);
                var fileNameSource = new List <string>();
                var fileName       = new List <string>();
                var fileSavePath   = new List <string>();
                var dtMergin       = new System.Data.DataTable();
                int uploadedCount  = 0;
                if (Request.Files.Count > 0)
                {
                    string CurrentMonthYear = System.IO.Path.GetFileName(Request.Files[0].FileName).ToLower().Replace(".dbf", "").RemoveWord();
                    fileNameSource.Add(hdcd + ".dbf");
                    fileNameSource.Add(hddd + ".dbf");
                    fileNameSource.Add(hdnet + ".dbf");
                    fileNameSource.Add(hdtv + ".dbf");
                    DataSource          += time + "/";
                    TM.OleDBF.DataSource = DataSource;
                    //TM.IO.FileDirectory.CreateDirectory(DataSource);
                    FileManagerController.InsertDirectory(DataSource);
                    //Delete old File
                    //TM.IO.Delete(DataSource, TM.IO.Files(DataSource));

                    for (int i = 0; i < Request.Files.Count; i++)
                    {
                        var file = Request.Files[i];
                        if (!file.FileName.IsExtension(".dbf"))
                        {
                            this.danger("Tệp phải định dạng .dbf");
                            return(RedirectToAction("Index"));
                        }

                        if (!fileNameSource.Contains(System.IO.Path.GetFileName(file.FileName).ToLower()))
                        {
                            this.danger("Sai tên tệp");
                            //return RedirectToAction("Index");
                        }

                        if (file.ContentLength > 0)
                        {
                            fileName.Add(System.IO.Path.GetFileName(file.FileName).ToLower());
                            fileSavePath.Add(TM.IO.FileDirectory.MapPath(DataSource) + fileName[i]);
                            file.SaveAs(fileSavePath[i]);
                            uploadedCount++;
                            FileManagerController.InsertFile(DataSource + fileName[i]);
                        }
                    }
                    var rs = "Tải lên thành công </br>";
                    foreach (var item in fileName)
                    {
                        rs += item + "<br/>";
                    }
                    this.success(rs);
                }
                else
                {
                    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 !");
                }
            }
            catch (Exception ex)
            {
                this.danger(ex.Message);
            }
            return(RedirectToAction("Index"));
        }