예제 #1
0
        public async Task <IActionResult> UploadFile(IFormFile FileToUpload, int fileGroupID)
        {
            if (FileToUpload == null || FileToUpload.Length == 0)
            {
                //return RedirectToAction("Manage", "LineItemGroups", new { id = fileGroupID });
                return(Json("\"error\" : \"No file uploaded\""));
            }
            string fileName = Path.GetFileName(FileToUpload.FileName);

            try {
                // 1. Save the FileAttachment record
                FileAttachment fileAttachment = new FileAttachment()
                {
                    FileDate    = DateTime.Now,
                    FileName    = fileName, //file name gets changed in next step below; done in two steps so we have the ID
                    DisplayName = fileName,
                    GroupID     = fileGroupID
                };
                _context.FileAttachments.Add(fileAttachment);
                _context.SaveChanges();

                // 2. Update the FileName to include the Attachment ID
                // This is to make the filename in the UserFiles directory unique
                // This will prevent overwrites by files with the same name
                // The DisplayName will remain identical to what the user uploaded, so it can duplicate without conflict
                fileAttachment.FileName = fileAttachment.AttachmentID + "_" + fileAttachment.FileName;
                _context.FileAttachments.Update(fileAttachment);
                _context.SaveChanges();

                // 3. Save the file to the UserFiles directory, using the FileName, not the DisplayName
                string filePath = AppSettingsJson.UserFilesPhysicalPath() + fileAttachment.FileName;
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await FileToUpload.CopyToAsync(stream);
                }
                // Assert: DisplayName = Filename.pdf, FileName = 123_Filename.pdf, file is stored in /UserFiles/123_Filename.pdf
                string displayPath = AppSettingsJson.UserFilesPhysicalPath() + fileAttachment.DisplayName;
                ViewData["FilePath"]    = filePath;
                ViewData["DisplayPath"] = displayPath;

                // Add to ViewBag a list of all files associated with this encumbrance request
                List <FileAttachment> files = _context.FileAttachments.Where(f => f.GroupID == fileGroupID).ToList();
                ViewBag.Files = files;
                //return RedirectToAction("Manage", "LineItemGroups", new { id = fileGroupID });
                string returnString = "{\"fileID\" : \"" + fileAttachment.AttachmentID + "\", \"fileName\" : \"" + fileAttachment.DisplayName + "\", \"fileURL\" : \"\\\\UserFiles\\\\" + fileAttachment.FileName + "\"}";
                return(Json(returnString));
            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                //TODO: If the file wasn't deleted, restore the FileAttachment record
                //return Json("{'error': 'true', 'message' : 'The attachment was not saved.' }");
                //return RedirectToAction("Manage", "LineItemGroups", new { id = fileGroupID });
                return(Json("\"error\" : \"Could not upload file.\""));
            }
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "MSAlias,WSAlias,ChineseName,EnglishName,DateofBirth,Major,OnBoardDate,OM,Group,Lob,Product")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "ID,Name,Type,Level,ParentID")] Skill skill)
        {
            if (ModelState.IsValid)
            {
                db.Skills.Add(skill);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(skill));
        }
예제 #4
0
        public IActionResult DeleteConfirmed(int id)
        {
            List <UserRole> roles = _context.UserRoles.Where(r => r.UserID == id).ToList();

            if (roles != null)
            {
                roles.ForEach(r => r.EndDate = DateTime.Now);
                _context.SaveChanges();
            }
            var user = _context.Users.SingleOrDefault(m => m.UserID == id);

            user.IsDisabled = 1;
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult Add(string lineItemGroupStatus)
        {
            LineItemGroupStatus newStatus = null;

            try
            {
                newStatus = JsonConvert.DeserializeObject <LineItemGroupStatus>(lineItemGroupStatus);
                newStatus.SubmittalDate = DateTime.Now;
                _context.LineItemGroupStatuses.Add(newStatus);
                _context.SaveChanges();

                int id = newStatus.StatusID;
                newStatus = _context.LineItemGroupStatuses
                            .AsNoTracking()
                            .SingleOrDefault(s => s.StatusID == id);
                // Not sure why .Include(s => s.User) leaves newStatus.User as null
                // This extra query is the workaround.
                User user = _context.Users
                            .AsNoTracking()
                            .SingleOrDefault(u => u.UserID == newStatus.UserID);
                newStatus.User = user;
            }
            catch (Exception e)
            {
                _logger.LogError("LineItemGroupStatusesController.Add Error:" + e.GetBaseException());
                Log.Error("LineItemGroupStatusesController.Add Error:" + e.GetBaseException() + "\n" + e.StackTrace);
            }
            return(Json(newStatus));
        }
예제 #6
0
        public static UseResponse UseCode(string code)
        {
            UseResponse useResp = new UseResponse();

            if (string.IsNullOrWhiteSpace(code))
            {
                useResp.Notification  = "Missing CardCode";
                useResp.UseCodeStatus = Protocol.UseCodeEnum.Error;
                return(useResp);
            }

            using (var context = new EPSContext())
            {
                CardCode cardCode = GetCardCode(context, code);
                if (cardCode != null && string.IsNullOrWhiteSpace(cardCode.Used))
                {
                    cardCode.Used = DateTime.Now.ToString();
                    context.SaveChanges();
                    useResp.UseCodeStatus = Protocol.UseCodeEnum.Used;
                }
                else if (!string.IsNullOrWhiteSpace(cardCode.Used))
                {
                    useResp.Notification  = $"Card code:{code.ToUpper()} alredy used";
                    useResp.UseCodeStatus = Protocol.UseCodeEnum.AlreadyUsed;
                }
                else
                {
                    useResp.Notification  = $"No such code:{code.ToUpper()}";
                    useResp.UseCodeStatus = Protocol.UseCodeEnum.NoCode;
                }

                return(useResp);
            }
        }
예제 #7
0
        public static GenerateResponse GenerateCodes(int coudeAmmount, int length)
        {
            using (var context = new EPSContext())
            {
                GenerateResponse resp = new GenerateResponse();
                try
                {
                    List <CardCode> cardCodes = new List <CardCode>();
                    for (int i = 0; i < coudeAmmount; i++)
                    {
                        var cardCode = UniqueCode(context, length);
                        cardCodes.Add(new CardCode()
                        {
                            Code = cardCode
                        });
                    }

                    context.CardCodes.AddRange(cardCodes);
                    context.SaveChanges();
                    resp.GenerateStatus = Protocol.CodeGenerateEnum.Generated;
                    return(resp);
                }
                catch (Exception e)
                {
                    resp.Notification   = "Error generating Codes";
                    resp.GenerateStatus = Protocol.CodeGenerateEnum.Error;
                    return(resp);
                }
            }
        }
예제 #8
0
        public IActionResult Create(int contractID, int groupID)
        {
            //string userLogin = GetLogin();
            PopulateViewBag(contractID);
            if (groupID > 0)
            {
                try
                {
                    // id is the LineItemGroup.GroupID
                    var group = _context.LineItemGroups.Where(lig => lig.GroupID == groupID).SingleOrDefault();
                    if (group == null)
                    {
                        // if it is zero or does not exist, create a new LineItemGroup and set id = its GroupID
                        LineItemGroup newGroup = new LineItemGroup(ViewBag.Contract, ViewBag.CurrentUser)
                        {
                            CurrentStatus    = ConstantStrings.Draft,
                            LastEditedUserID = ViewBag.CurrentUser.UserID,
                            OriginatorUserID = ViewBag.CurrentUser.UserID
                        };
                        _context.LineItemGroups.Add(newGroup);
                        _context.SaveChanges();

                        group = newGroup;
                    }
                    ViewBag.lineItemGroup = group;
                    ViewBag.contractID    = ViewBag.Contract.ContractID;

                    // also the View does not use this to populate a selection list yet.
                    //ViewData["FlairLineIDs"] = GetAmendmentsList(contractID);
                }
                catch (Exception e)
                {
                    _logger.LogError("LineItemsController.Create Error:" + e.GetBaseException());
                    Log.Error("LineItemsController.Create Error:" + e.GetBaseException() + "\n" + e.StackTrace);
                }
            }
            ViewBag.LineItemTypes     = ConstantStrings.GetLineItemTypeList();
            ViewBag.currentFiscalYear = PermissionsUtils.GetCurrentFiscalYear();
            ViewData["Categories"]    = _context.Categories.OrderBy(v => v.CategoryCode);
            ViewData["StatePrograms"] = _context.StatePrograms.OrderBy(v => v.ProgramCode);
            return(View());
        }
예제 #9
0
 public JsonResult AddNewVendor(Vendor vendor)
 {
     if (!String.IsNullOrWhiteSpace(vendor.VendorCode) && !String.IsNullOrWhiteSpace(vendor.VendorName))
     {
         if (VendorExists(vendor.VendorCode))
         {
             vendor = _context.Vendors.SingleOrDefault(v => v.VendorCode == vendor.VendorCode);
         }
         else
         {
             vendor.VendorName = vendor.VendorName.ToUpper();
             vendor.VendorCode = vendor.VendorCode.ToUpper();
             _context.Vendors.Add(vendor);
             _context.SaveChanges();
         }
     }
     else
     {
         throw new Exception("Missing vendor code or name");
     }
     return(Json(vendor));
 }
예제 #10
0
        public ActionResult Create(vEPSUSER_Manage VUM)
        {
            //初始化系統參數
            Configer.Init();

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();

            SL.UId           = Session["UserID"].ToString();
            SL.Controller    = "Account";
            SL.Action        = "Create";
            SL.TotalCount    = 1;
            SL.StartDateTime = DateTime.Now;

            string        MailServer     = Configer.MailServer;
            int           MailServerPort = Configer.MailServerPort;
            string        MailSender     = Configer.MailSender;
            List <string> MailReceiver   = Configer.MailReceiver;

            try
            {
                if (ModelState.IsValid)
                {
                    EPSUSER U = new EPSUSER();
                    U.UId           = VUM.UId;
                    U.UserName      = VUM.UserName;
                    U.UserPwd       = VUM.UserPwd;
                    U.UserEmail     = VUM.UserEmail;
                    U.RId           = VUM.RId;
                    U.CreateAccount = Session["UserID"].ToString().Trim();
                    U.CreateTime    = DateTime.Now;
                    U.UpadteAccount = Session["UserID"].ToString().Trim();
                    U.UpdateTime    = DateTime.Now;

                    context.EPSUSERS.Add(U);
                    context.SaveChanges();

                    SL.SuccessCount = 1;
                    SL.FailCount    = 0;
                    SL.Result       = true;
                    SL.Msg          = "建立使用者作業成功";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                    //TempData["CreateMsg"] = "<script>alert('新增成功');</script>";

                    return(RedirectToAction("Index", "Account"));
                }
                else
                {
                    TempData["CreateMsg"] = "<script>alert('新增失敗');</script>";

                    return(RedirectToAction("Create", "Account"));
                }
            }
            catch (Exception ex)
            {
                SL.EndDateTime  = DateTime.Now;
                SL.TotalCount   = 1;
                SL.SuccessCount = 0;
                SL.FailCount    = 1;
                SL.Result       = false;
                SL.Msg          = "建立使用者作業失敗," + "錯誤訊息[" + ex.ToString() + "]";
                SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                TempData["CreateMsg"] = "<script>alert('發生異常');</script>";

                return(RedirectToAction("Create", "Account"));
            }
        }
예제 #11
0
        public ActionResult Create(vEPSROLE_Manage VRM)
        {
            //初始化系統參數
            Configer.Init();

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();

            SL.UId           = Session["UserID"].ToString();
            SL.Controller    = "Role";
            SL.Action        = "Create";
            SL.TotalCount    = 1;
            SL.StartDateTime = DateTime.Now;

            string        MailServer     = Configer.MailServer;
            int           MailServerPort = Configer.MailServerPort;
            string        MailSender     = Configer.MailSender;
            List <string> MailReceiver   = Configer.MailReceiver;

            try
            {
                if (ModelState.IsValid)
                {
                    EPSROLE R = new EPSROLE();
                    R.RoleName      = VRM.RoleName;
                    R.CreateAccount = Session["UserID"].ToString().Trim();
                    R.CreateTime    = DateTime.Now;
                    R.UpadteAccount = Session["UserID"].ToString().Trim();
                    R.UpdateTime    = DateTime.Now;

                    context.EPSROLES.Add(R);
                    context.SaveChanges();

                    foreach (var item in VRM.FuncList)
                    {
                        ROLEFUNCMAPPING RM = new ROLEFUNCMAPPING();
                        RM.RId           = R.RId;
                        RM.FId           = item;
                        RM.CreateAccount = Session["UserID"].ToString().Trim();
                        RM.CreateTime    = DateTime.Now;
                        RM.UpadteAccount = Session["UserID"].ToString().Trim();
                        RM.UpdateTime    = DateTime.Now;

                        context.ROLEFUNCMAPPINGS.Add(RM);
                        context.SaveChanges();
                    }
                    SL.EndDateTime  = DateTime.Now;
                    SL.SuccessCount = 1;
                    SL.FailCount    = 0;
                    SL.Result       = true;
                    SL.Msg          = "建立使用者作業成功";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                    //TempData["CreateMsg"] = "<script>alert('新增成功');</script>";

                    return(RedirectToAction("Index", "Role"));
                }
                else
                {
                    TempData["CreateMsg"] = "<script>alert('新增失敗');</script>";

                    return(RedirectToAction("Create", "Role"));
                }
            }
            catch (Exception ex)
            {
                SL.EndDateTime  = DateTime.Now;
                SL.TotalCount   = 1;
                SL.SuccessCount = 0;
                SL.FailCount    = 1;
                SL.Result       = false;
                SL.Msg          = "建立角色作業失敗," + "錯誤訊息[" + ex.ToString() + "]";
                SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                TempData["CreateMsg"] = "<script>alert('發生異常');</script>";

                return(RedirectToAction("Create", "Role"));
            }
        }
예제 #12
0
        /// <summary>
        /// 產生CHECKPROCESS資料
        /// </summary>
        /// <param name="CheckSNList">檢核編號清單</param>
        /// <param name="CheckDate">檢核日期</param>
        /// <returns></returns>
        private bool GenCheckProcess(List <string> CheckSNList, string CheckDate)
        {
            //初始化系統參數
            Configer.Init();

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();

            SL.UId           = "System";
            SL.Controller    = "Process";
            SL.Action        = "GenCheckProcess";
            SL.StartDateTime = DateTime.Now;

            string        MailServer     = Configer.MailServer;
            int           MailServerPort = Configer.MailServerPort;
            string        MailSender     = Configer.MailSender;
            List <string> MailReceiver   = Configer.MailReceiver;

            bool Result = true;

            try
            {
                var CT = context.CHECKTITLES.ToList();

                if (CheckSNList != null)
                {
                    //產生CHECKPROCESS
                    int i = 0;
                    foreach (var item in CT)
                    {
                        CHECKPROCESS newCP = new CHECKPROCESS();
                        newCP.CheckSN       = CheckSNList[i];
                        newCP.CheckID       = item.CheckID;
                        newCP.CheckDate     = CheckDate;
                        newCP.CloseStutus   = "檢查中";
                        newCP.CreateAccount = "System";
                        newCP.CreateTime    = DateTime.Now;
                        newCP.UpadteAccount = "System";
                        newCP.UpdateTime    = DateTime.Now;
                        newCP.CheckDate     = CheckDate;
                        context.CHECKPROCESSES.Add(newCP);
                        context.SaveChanges();

                        i++;
                    }
                    SL.EndDateTime  = DateTime.Now;
                    SL.TotalCount   = CheckSNList.Count();
                    SL.SuccessCount = CheckSNList.Count();
                    SL.FailCount    = 0;
                    SL.Result       = true;
                    SL.Msg          = "建立[" + CheckDate + "]檢核流程作業成功";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                    return(Result);
                }
                else
                {
                    SL.EndDateTime  = DateTime.Now;
                    SL.TotalCount   = 0;
                    SL.SuccessCount = 0;
                    SL.FailCount    = 0;
                    SL.Result       = false;
                    SL.Msg          = "建立[" + CheckDate + "]檢核流程作業失敗," + "錯誤訊息[無檢核編號]";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                    Result = false;

                    return(Result);
                }
            }
            catch (Exception ex)
            {
                SL.EndDateTime  = DateTime.Now;
                SL.TotalCount   = 0;
                SL.SuccessCount = 0;
                SL.FailCount    = 0;
                SL.Result       = false;
                SL.Msg          = "建立[" + CheckDate + "]檢核流程作業失敗," + "錯誤訊息[" + ex.ToString() + "]";
                SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                Result = false;

                return(Result);
            }
        }
예제 #13
0
        public ActionResult Create(vFUNC_Manage VFM)
        {
            //初始化系統參數
            Configer.Init();

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();

            SL.UId           = Session["UserID"].ToString();
            SL.Controller    = "Fun";
            SL.Action        = "Create";
            SL.TotalCount    = 1;
            SL.StartDateTime = DateTime.Now;

            string        MailServer     = Configer.MailServer;
            int           MailServerPort = Configer.MailServerPort;
            string        MailSender     = Configer.MailSender;
            List <string> MailReceiver   = Configer.MailReceiver;

            try
            {
                if (ModelState.IsValid)
                {
                    FUNC F = new FUNC();
                    F.FId           = VFM.FId;
                    F.FuncName      = VFM.FuncName;
                    F.Controller    = VFM.Controller;
                    F.Action        = VFM.Action;
                    F.Url           = VFM.Url;
                    F.PId           = VFM.PId;
                    F.ShowOrder     = VFM.ShowOrder;
                    F.IsEnable      = VFM.IsEnable;
                    F.CreateAccount = Session["UserID"].ToString().Trim();
                    F.CreateTime    = DateTime.Now;
                    F.UpadteAccount = Session["UserID"].ToString().Trim();
                    F.UpdateTime    = DateTime.Now;

                    context.FUNCS.Add(F);
                    context.SaveChanges();

                    SL.EndDateTime  = DateTime.Now;
                    SL.SuccessCount = 1;
                    SL.FailCount    = 0;
                    SL.Result       = true;
                    SL.Msg          = "建立功能作業成功";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                    //TempData["CreateMsg"] = "<script>alert('新增成功');</script>";

                    return(RedirectToAction("Index", "Fun"));
                }
                else
                {
                    TempData["CreateMsg"] = "<script>alert('新增失敗');</script>";

                    return(RedirectToAction("Create", "Fun"));
                }
            }
            catch (Exception ex)
            {
                SL.EndDateTime  = DateTime.Now;
                SL.TotalCount   = 1;
                SL.SuccessCount = 0;
                SL.FailCount    = 1;
                SL.Result       = false;
                SL.Msg          = "建立功能作業失敗," + "錯誤訊息[" + ex.ToString() + "]";
                SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                TempData["CreateMsg"] = "<script>alert('發生異常');</script>";

                return(RedirectToAction("Create", "Fun"));
            }
        }
예제 #14
0
        public int AddMessage(string updateType, LineItemGroup encumbrance, string comments, List <int> otherRecipients, List <int> ccIDs)
        {
            encumbrance = _context.GetDeepEncumbrance(encumbrance.GroupID);
            int        msgID            = 0;
            List <int> recipientIDs     = null; // list of IDs of email recipients
            decimal    encumbranceTotal = 0.0M;
            //string contractViewURL = _serverpath + "/Contracts/View/" + encumbrance.ContractID + "/enc_" + encumbrance.GroupID;
            string contractViewURL = _serverpath + "/LineItemGroups/Manage/" + encumbrance.GroupID;

            encumbranceTotal = GetEncumbranceTotal(encumbrance);
            Contract contract  = _context.Contracts.SingleOrDefault(c => c.ContractID == encumbrance.ContractID);
            User     submitter = _context.Users.SingleOrDefault(u => u.UserID == encumbrance.LastEditedUserID);
            Message  msg       = new Message
            {
                FromUserID  = encumbrance.LastEditedUserID,
                MessageDate = DateTime.Now
            };

            if (!updateType.Equals(ConstantStrings.NoChange))
            {
                switch (updateType)
                {
                case ConstantStrings.DraftToFinance:
                    msg.Subject = "Encumbrance Request# " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been submitted for Finance Review";
                    msg.Body    = "<p>Please process the following encumbrance request: ID " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " in the amount of " + Utils.FormatCurrency(encumbranceTotal) + ".</p>\n";
                    if (comments != null && comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    if (encumbrance.FileAttachments != null && encumbrance.FileAttachments.Count > 0)
                    {
                        msg.Body += "File Attachments:<br/><ul>";
                        foreach (FileAttachment fileAtt in encumbrance.FileAttachments)
                        {
                            var fileUrl = _serverpath + "\\" + FileAttachment.UserFilesPath + "\\" + fileAtt.FileName;
                            msg.Body += "<li><a href='" + fileUrl + "'>" + fileAtt.DisplayName + "</a></li>";
                        }
                        msg.Body += "</ul>";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = getFinanceRecipients();
                    break;

                case ConstantStrings.DraftToCFM:
                    msg.Subject = "Encumbrance Request# " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " for " + encumbrance.LineItemType;
                    msg.Body    = "<p>Please input the following encumbrance into CFM: request ID " + encumbrance.GroupID + " for contract " + contract.ContractNumber + ".</p>\n";
                    //msg.Body += "in the amount of " + Utils.FormatCurrency(encumbranceTotal)  + " applied to Amendment " + encumbrance.FlairAmendmentID + " Line " + encumbrance.LineID6S + ".";
                    if (encumbrance.LineItems != null && encumbrance.LineItems.Count > 0)
                    {
                        string tblText = "<table><tr><th>Contract</th><th>Amendment</th><th>Line (6s)</th><th>Amount</th></tr>";
                        foreach (LineItem item in encumbrance.LineItems)
                        {
                            tblText += "<tr><td>" + contract.ContractNumber + "</td><td>" + item.FlairAmendmentID + "</td><td>" + item.LineID6S + "</td><td>" + Utils.FormatCurrency(item.Amount) + "</td></tr>";
                        }
                        tblText  += "</table> <br/>";
                        msg.Body += tblText;
                    }
                    if (comments != null && comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>View this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.FinanceToDraft:
                case ConstantStrings.CFMToDraft:
                case ConstantStrings.CompleteToDraft:
                    msg.Subject = "Encumbrance Request#" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned to the Originator";
                    msg.Body    = "<p>Encumbrance ID " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned for the following reason:</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    recipientIDs = new List <int> {
                        encumbrance.OriginatorUserID
                    };
                    break;

                case ConstantStrings.FinanceToWP:
                    msg.Subject = "Please review encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " for Work Program Evaluation";
                    msg.Body    = "<p>" + submitter.FullName + " has completed a Finance Review for encumbrance request #" + encumbrance.GroupID + " under contract " + contract.ContractNumber + ".</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    recipientIDs = otherRecipients;     //(List<int>)_context.UserRoles.Where(u => u.Role.Equals(ConstantStrings.WPReviewer)).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.FinanceToCFM:
                case ConstantStrings.FinanceToComplete:
                    // No notification required. Exit without sending message
                    return(0);

                case ConstantStrings.WPToFinance:
                    msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned by Work Program";
                    msg.Body    = "<p>" + submitter.FullName + " has completed a Work Program review for encumbrance request #" + encumbrance.GroupID + " under contract " + contract.ContractNumber + ".</p>\n";
                    msg.Body   += "<p>This encumbrance request is returned to Finance with the following comment:</p>";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.WPToCFM:
                    msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " is ready for CFM Input";
                    msg.Body    = "<p>" + submitter.FullName + " has completed a Work Program review for encumbrance request #" + encumbrance.GroupID + " in Work Program review under contract " + contract.ContractNumber + ".</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.CFMToFinance:
                    msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned to Finance";
                    msg.Body    = "<p>" + submitter.FullName + " has returned to Encumbranc request #" + encumbrance.GroupID + " to Finance with the following comment:</p>";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.CFMToWP:
                    msg.Subject = "Please review encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " requires additional Work Program Review";
                    msg.Body    = "<p>" + submitter.FullName + " has returned encumbrance request #" + encumbrance.GroupID + " from CFM for additional Work Program review for contract " + contract.ContractNumber + ".</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    recipientIDs = otherRecipients;;
                    break;

                case ConstantStrings.CFMToComplete:
                    //msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been input into CFM";
                    //msg.Body = "<p>" + submitter.FullName + " has input encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " into CFM.</p>\n";
                    //if (comments.Length > 0)
                    //{ msg.Body += "<p>Comments: " + comments + "</p>\n"; }
                    //msg.Body += "<p>No further action is required. You may view this encumbrance request in the <a href='" + contractViewURL + "'>" +
                    //    "EPS Application</a>.</p>";
                    //// Send only to TPK Encumbrance mailbox
                    //recipientIDs = new List<int> { submitter.UserID };
                    // No notification needed per Lorna 7/9/2019
                    return(0);

                case ConstantStrings.CloseContract:
                    msg.Subject = "Request to Close Contract #" + contract.ContractNumber;
                    msg.Body    = "<p>" + submitter.FullName + " requests closure of the contract " + contract.ContractNumber + ", closure type " + encumbrance.LineItemType + " </p>";
                    //msg.Body += "<p>Review this closure request in the <a href='" + contractViewURL + "'>" + "EPS Application</a>.</p>";
                    recipientIDs = (List <int>)_context.UserRoles.Where(u => u.Role.Equals(ConstantStrings.Closer)).Select(u => u.UserID).ToList();
                    ccIDs        = (List <int>)_context.UserRoles.Where(u => u.Role.Equals(ConstantStrings.CloserCC)).Select(u => u.UserID).ToList();
                    break;

                default:
                    // if no message then exit
                    return(0);
                }
                // Save the message to the database

                try
                {
                    _context.Messages.Add(msg);
                    _context.SaveChanges();
                    msgID = msg.MessageID;
                    if (otherRecipients != null && otherRecipients.Count > 0)
                    {
                        AddRecipients(msgID, otherRecipients);
                    }
                    else
                    {
                        AddRecipients(msgID, recipientIDs);
                    }
                    if (ccIDs != null && ccIDs.Count > 0)
                    {
                        AddCCs(msgID, ccIDs);
                    }
                }catch (Exception e)
                {
                    Log.Error("MessageService.AddMessage Error:" + e.GetBaseException() + "\n" + e.StackTrace);
                    return(-1);
                }
            }
            return(msgID);
        }
예제 #15
0
        /// <summary>
        /// 簽核
        /// </summary>
        /// <param name="CheckSNs"></param>
        /// <param name="CheckDates"></param>
        /// <param name="SignedData"></param>
        /// <returns></returns>
        public string Confirm(List <string> CheckSNs, List <string> CheckDates, string SignedData)
        {
            //初始化系統參數
            Configer.Init();

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();

            SL.UId           = Session["UserID"].ToString();
            SL.Controller    = "Review";
            SL.Action        = "Confirm";
            SL.StartDateTime = DateTime.Now;

            string UId = Session["UserID"].ToString();

            string        MailServer     = Configer.MailServer;
            int           MailServerPort = Configer.MailServerPort;
            string        MailSender     = Configer.MailSender;
            List <string> MailReceiver   = Configer.MailReceiver;

            int  TotalCount   = 0;
            int  SuccessCount = 0;
            int  FailCount    = 0;
            bool ReviewOK     = true;

            try
            {
                string CloseStutus = "";
                TotalCount = CheckSNs.Count();
                foreach (var item in CheckSNs)
                {
                    CHECKPROCESS CP = context.CHECKPROCESSES.Find(item);

                    if (CP != null)
                    {
                        //update CHECKPROCESSES
                        EPSUSER U    = context.EPSUSERS.Find(UId);
                        int     Role = U.RId;// int.Parse(UId);

                        switch (Role)
                        {
                        //機房領班
                        case 3:
                            CP.ShiftTop     = U.UserName;
                            CP.ShiftTopSign = SignedData;
                            CP.CloseStutus  = "領班覆核完畢";
                            CloseStutus     = "領班覆核完畢";
                            break;

                        //主管
                        case 4:
                            CP.ManageOne     = U.UserName;
                            CP.ManageOneSign = SignedData;
                            CP.CloseStutus   = "主管覆核完畢";
                            CloseStutus      = "主管覆核完畢";
                            break;

                        //系統部主管
                        case 5:
                            CP.ManageTop     = U.UserName;
                            CP.ManageTopSign = SignedData;
                            CP.CloseStutus   = "已結案";
                            CloseStutus      = "已結案";
                            break;
                        }

                        CP.UpadteAccount        = UId;
                        CP.UpdateTime           = DateTime.Now;
                        context.Entry(CP).State = EntityState.Modified;
                        context.SaveChanges();
                        SuccessCount += 1;

                        SL.EndDateTime  = DateTime.Now;
                        SL.TotalCount   = 1;
                        SL.SuccessCount = 1;
                        SL.FailCount    = 0;
                        SL.Result       = false;
                        SL.Msg          = "覆核[" + item + "]作業成功";
                        SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                    }
                    else
                    {
                        FailCount      += 1;
                        ReviewOK        = false;
                        SL.EndDateTime  = DateTime.Now;
                        SL.TotalCount   = 1;
                        SL.SuccessCount = 0;
                        SL.FailCount    = 1;
                        SL.Result       = false;
                        SL.Msg          = "覆核[" + item + "]作業失敗,查無檢核流程資料";
                        SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                    }
                }

                if (ReviewOK)
                {
                    //通知下一位負責人,已結案則通知機房領班、機房主管、系統部主管
                    if (CloseStutus == "已結案")
                    {
                        SF.emailNotify2ClosebyDate(CloseStutus, UId,
                                                   CheckDates[0].ToString(), CloseStutus);
                    }
                    else
                    {
                        SF.emailNotify2ReviewbyDate(CloseStutus, UId,
                                                    CheckDates[0].ToString(), "覆核");
                    }
                    SL.EndDateTime  = DateTime.Now;
                    SL.TotalCount   = TotalCount;
                    SL.SuccessCount = SuccessCount;
                    SL.FailCount    = 0;
                    SL.Result       = false;
                    SL.Msg          = "[" + CheckDates[0].ToString() + "]覆核作業成功";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                    return("全部覆核成功");
                }
                else
                {
                    SL.EndDateTime  = DateTime.Now;
                    SL.TotalCount   = TotalCount;
                    SL.SuccessCount = SuccessCount;
                    SL.FailCount    = 0;
                    SL.Result       = false;
                    SL.Msg          = "[" + CheckDates[0].ToString() + "]覆核作業失敗";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                    return("有" + FailCount.ToString() + "筆資料覆核失敗");
                }
            }
            catch (Exception ex)
            {
                ReviewOK        = false;
                SL.EndDateTime  = DateTime.Now;
                SL.TotalCount   = CheckSNs.Count();
                SL.SuccessCount = 0;
                SL.FailCount    = CheckSNs.Count();
                SL.Result       = false;
                SL.Msg          = "覆核作業失敗," + "錯誤訊息[" + ex.ToString() + "]";
                SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                return("覆核發生異常");
            }
        }
예제 #16
0
        public ActionResult Create(vDOCUMENT_Manage VDM)
        {
            //初始化系統參數
            Configer.Init();

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();

            SL.UId           = Session["UserID"].ToString();
            SL.Controller    = "Document";
            SL.Action        = "Create";
            SL.TotalCount    = 1;
            SL.StartDateTime = DateTime.Now;

            string        MailServer     = Configer.MailServer;
            int           MailServerPort = Configer.MailServerPort;
            string        MailSender     = Configer.MailSender;
            List <string> MailReceiver   = Configer.MailReceiver;

            try
            {
                if (ModelState.IsValid)
                {
                    CHECKTITLE CT = new CHECKTITLE();
                    CT.Title         = VDM.Title;
                    CT.Definition    = VDM.Definition;
                    CT.Attachment    = VDM.Attachment;
                    CT.CreateAccount = Session["UserID"].ToString().Trim();
                    CT.CreateTime    = DateTime.Now;
                    CT.UpadteAccount = Session["UserID"].ToString().Trim();
                    CT.UpdateTime    = DateTime.Now;

                    context.CHECKTITLES.Add(CT);
                    context.SaveChanges();

                    SL.EndDateTime  = DateTime.Now;
                    SL.SuccessCount = 1;
                    SL.FailCount    = 0;
                    SL.Result       = true;
                    SL.Msg          = "建立文件作業成功";
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                    //TempData["CreateMsg"] = "<script>alert('新增成功');</script>";

                    return(RedirectToAction("AddItem", "Document", new { CheckID = CT.CheckID, CheckTitle = CT.Title }));
                }
                else
                {
                    TempData["CreateMsg"] = "<script>alert('新增失敗');</script>";

                    return(RedirectToAction("Create", "Document"));
                }
            }
            catch (Exception ex)
            {
                SL.EndDateTime  = DateTime.Now;
                SL.TotalCount   = 1;
                SL.SuccessCount = 0;
                SL.FailCount    = 1;
                SL.Result       = false;
                SL.Msg          = "建立文件作業失敗," + "錯誤訊息[" + ex.ToString() + "]";
                SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);

                TempData["CreateMsg"] = "<script>alert('發生異常');</script>";

                return(RedirectToAction("Create", "Document"));
            }
        }