public ActionResult shrink()
        {
            string iduser = Session.getIdUser();
            var    tsql   = new List <string> {
                local.getTsqlInsertHistory("shrink Data", iduser, "shrink Data")
            };

            using (var db = local.getDataObject()) { tsql.Add($"DBCC SHRINKDATABASE ([{db.Connection.Database}], TRUNCATEONLY)"); }
            var arg = new itemScheduler("shrink Data", iduser, ListFile: string.Join("\ngo\n", tsql), iRequest: Request.toRequestString(), iData: tsql);

            return(Content(arg.callTaskScheduler()));
        }
        public ActionResult Backup()
        {
            string iduser = Session.getIdUser();
            string name   = $"db_{DateTime.Now:ddMMyy_HHmmss}.bak";
            var    tsql   = new List <string> {
                local.getTsqlInsertHistory("Backup Data", iduser, "Backup Data")
            };

            using (var db = local.getDataObject()) { tsql.Add($"BACKUP DATABASE [{db.Connection.Database}] TO  DISK = N'{Folders.Backup}\\{name}' WITH NOFORMAT, NOINIT,  NAME = N'Full Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10 "); }
            var arg = new itemScheduler("Backup Data", iduser, ListFile: string.Join("\ngo\n", tsql), iRequest: Request.toRequestString(), iData: tsql);

            return(Content(arg.callTaskScheduler()));
        }
Пример #3
0
        public ActionResult accdb()
        {
            var args = new itemScheduler();

            args.action           = actionName;
            args.packetSize       = int.Parse(Request.getValue("packetsize"));
            args.request          = Request.toRequestString();
            args.listFile         = Request.getValue("table");
            args.idUser           = Session.getIdUser();
            args.data             = (Action)(() => bwDoWork(args));
            Session[keyS.Message] = args.callTaskScheduler();
            return(RedirectToAction("index"));
        }
Пример #4
0
        /// <summary>
        /// ID: Mã bảo hiểm cấp huyện; f: Tên tập tin xử lý; Mode = 1: Xóa tập tin, ngược lại cập nhật danh sách tst; listfile: danh sách tập tin cần xử lý
        /// </summary>
        /// <returns></returns>
        public ActionResult import()
        {
            string folder   = Folders.temp + "\\test";
            string filename = "";

            /* Check Exits File, Kiểm tra tham số */
            try
            {
                if (Request.getValue("mode") == "1")
                {
                    /* Xóa tập tin */
                    if (Request["f"] != null)
                    {
                        var f = new FileInfo(folder + "\\" + Request.getValue("f"));
                        if (f.Exists)
                        {
                            f.Delete();
                        }
                    }
                    else
                    {
                        foreach (var v in Request.Form.GetValues("listfile"))
                        {
                            var f = new FileInfo(folder + "\\" + v);
                            if (f.Exists)
                            {
                                f.Delete();
                            }
                        }
                    }
                    Session[keyS.Message] = messageKey.actionSuccess;
                    return(RedirectToAction("index"));
                }
                string id = Request.getValue("f");
                if (string.IsNullOrEmpty(id) == false)
                {
                    var f = new FileInfo(folder + "\\" + id);
                    if (f.Exists == false)
                    {
                        throw new Exception(messageKey.notFoundFile(f.FullName));
                    }
                    filename = f.FullName;
                }
                else
                {
                    if (Request["listfile"] == null)
                    {
                        throw new Exception(messageKey.thamSoKhongDung);
                    }
                }
            }
            catch (Exception ex)
            {
                Session[keyS.Error] = ex.saveMessage();
                return(RedirectToAction("index"));
            }
            /* */
            try
            {
                var args = new itemScheduler
                {
                    function    = keyFunction.importExcel,
                    idObject    = "",
                    idUser      = Session.getIdUser(),
                    action      = actionName,
                    packetSize  = 10000,
                    listFile    = filename,
                    typeProcess = "",
                    times       = DateTime.Now,
                    request     = Request.toRequestString()
                };
                if (string.IsNullOrEmpty(filename))
                {
                    /* Excel */
                    var ls   = new List <string>();
                    var vals = Request.Form.GetValues("listfile");
                    foreach (var v in vals)
                    {
                        ls.Add(folder + "\\" + v);
                    }
                    args.listFile = string.Join(",", ls);
                }
                else
                {
                    throw new Exception("Chưa chọn tập tin import");
                }
                Session[keyS.Message] = args.callTaskScheduler();
            }
            catch (Exception ex) { Session.saveError(ex.saveMessage()); }
            return(RedirectToAction("index"));
        }
Пример #5
0
        public void bwDoWork(itemScheduler args)
        {
            Progressbar p = new Progressbar(actionName);

            p.name = "Xuất dữ liệu";
            if (local.taskList[actionName] == null)
            {
                local.taskList.Add(p);
            }
            local.taskList.Modify(actionName, $"{args.idUser} Kiểm tra dữ liệu ..");
            var    db        = local.getDataObject();
            var    v         = new List <string>();
            var    msgError  = new List <string>();
            var    actions   = new List <Action>();
            string pathaccdb = "";

            if (args.typeProcess == "")
            {
                /* Access */
                actions.Add(() =>
                {
                    pathaccdb = Folders.temp;
                    if (Directory.Exists(pathaccdb) == false)
                    {
                        Directory.CreateDirectory(pathaccdb);
                    }
                    if (Directory.Exists(pathExport) == false)
                    {
                        Directory.CreateDirectory(pathExport);
                    }
                    pathaccdb = pathExport + $"\\data_{DateTime.Now:yyyyMMdd_HHmmss}.accdb";
                    var f     = new FileInfo(pathsource);
                    f.CopyTo(pathaccdb);
                });
                foreach (var table in args.listFile.Split(','))
                {
                    actions.Add(() =>
                    {
                        if (table == "")
                        {
                            return;
                        }
                        var values = new List <string>();
                        local.taskList.Modify(actionName, $"{args.idUser} {table}: Xuất dữ liệu ..");
                        int processed = 0;
                        db.toAccess(table, pathaccdb, ref processed);
                    });
                }
            }
            if (actions.Count > 0)
            {
                int index = 0;
                local.taskList.setValueMax(actionName, actions.Count);
                /* Lưu quá trình tiến trình */
                local.setHistoryTaskList(local.taskList[actionName], args.idUser, requeststring: args.request);
                foreach (var action in actions)
                {
                    try { action(); index++; local.taskList.Modify(actionName, "", index); }
                    catch (Exception ex) { msgError.Add(ex.saveMessage($"Index: {index} - {local.taskList[actionName].message}")); }
                }
                /* Lưu kết quả tiến trình */
                var t = DateTime.Now - p.timeStart;
                local.setHistoryTaskList(local.taskList[actionName], args.idUser, $"{t.Hours}:{t.Minutes}:{t.Seconds} {string.Join("; ", msgError)}");
            }
            db.Dispose();
            local.taskList.Remove(p);
        }