Example #1
0
        public JsonResult MailSendingHandler()
        {
            string email    = Request.Form["email"];
            string password = Request.Form["password"];
            string type     = Request.Form["mailType"];

            var        service = new HolidayTransferService();
            MailResult result  = new MailResult();

            switch (type)
            {
            case "annual":
                List <HolidayDetail> rlt = JsonConvert.DeserializeObject <List <HolidayDetail> >(Request.Form["staffList"]);

                Parallel.ForEach(rlt, (item, state) => {
                    if (item.PaidLeaveRemainingHours == 0 ||
                        item.HolidayStartDate > DateTime.Now ||
                        item.HolidayEndDate < DateTime.Now)
                    {
                        return;
                    }
                    string htmlData = string.Empty;
                    try
                    {
                        htmlData = service.HolidayDataConvert2Html(item);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(item.ChineseName);
                        result.FailureMsg.Add(ex.Message);
                        return;
                    }
                    try
                    {
                        service.MailSending(email, password, item.Email, htmlData, "annual");
                        result.SuccessList.Add(item.ChineseName);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(item.ChineseName);
                        result.FailureMsg.Add(ex.Message);
                    }
                });
                break;

            case "transfer":
                List <UserTransferList> lutl = JsonConvert.DeserializeObject <List <UserTransferList> >(Request.Form["staffList"]);
                foreach (UserTransferList ul in lutl)
                {
                    string htmlData = string.Empty;
                    var    details  = ul.UserTransferDetail.AsEnumerable().Where(r => r.TransferRemainingTime != 0);
                    if (details.Count() == 0)
                    {
                        continue;
                    }
                    try
                    {
                        htmlData = service.TransferDataConvert2Html(ul);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(ul.StaffName);
                        result.FailureMsg.Add(ex.Message);
                        continue;
                    }
                    try
                    {
                        service.MailSending(email, password, ul.StaffEmail, htmlData, "transfer");
                        result.SuccessList.Add(ul.StaffName);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(ul.StaffName);
                        result.FailureMsg.Add(ex.Message);
                    }
                }
                break;

            default:
                break;
            }
            return(Json(result));
        }
Example #2
0
        public JsonResult MailSendingHandler()
        {
            string mailType  = Request.Form["mailType"];
            string email     = Request.Form["email"];
            string password  = Request.Form["password"];
            string CCAddress = System.Configuration.ConfigurationManager.AppSettings["mailCCAddress"];

            var service = new HolidayTransferService();
            HolidayTransferMailResult result = new HolidayTransferMailResult();

            switch (mailType)
            {
            case "annual":
                List <UserHoliday> holidayList = JsonConvert.DeserializeObject <List <UserHoliday> >(Request.Form["staffList"]);

                Parallel.ForEach(holidayList, (item, state) =>
                {
                    if (item.TotalRemainingHours == 0 ||
                        item.PaidLeaveBeginDate > DateTime.Now ||
                        item.PaidLeaveEndDate < DateTime.Now)
                    {
                        //state.Stop();
                        return;
                    }
                    string htmlData = string.Empty;
                    try
                    {
                        htmlData = service.HolidayDataConvert2Html(item);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(item.StaffName);
                        result.FailureMsg.Add(ex.Message);
                        return;
                    }
                    try
                    {
                        service.MailSending(email, password, item.StaffEmail, htmlData, "annual", CCAddress);
                        result.SuccessList.Add(item.StaffName);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(item.StaffName);
                        result.FailureMsg.Add(ex.Message);
                    }
                });

                //foreach (UserHoliday ul in holidayList)
                //{
                //    if (ul.PaidLeaveRemainingHours == 0 ||
                //        ul.PaidLeaveBeginDate > DateTime.Now ||
                //        ul.PaidLeaveEndDate < DateTime.Now)
                //    {
                //        continue;
                //    }
                //    string htmlData = string.Empty;
                //    try
                //    {
                //        htmlData = service.HolidayDataConvert2Html(ul);
                //    }
                //    catch (Exception ex)
                //    {
                //        result.FailureList.Add(ul.StaffName);
                //        result.FailureMsg.Add(ex.Message);
                //        continue;
                //    }
                //    try
                //    {
                //        service.MailSending(email, password, ul.StaffEmail, htmlData, "annual", CCAddress);
                //        result.SuccessList.Add(ul.StaffName);
                //    }
                //    catch (Exception ex)
                //    {
                //        result.FailureList.Add(ul.StaffName);
                //        result.FailureMsg.Add(ex.Message);
                //    }
                //}
                break;

            case "transfer":
                List <UserTransferList> lutl = JsonConvert.DeserializeObject <List <UserTransferList> >(Request.Form["staffList"]);
                foreach (UserTransferList ul in lutl)
                {
                    string htmlData = string.Empty;
                    var    details  = ul.UserTransferDetail.AsEnumerable().Where(r => r.TransferRemainingTime != 0);
                    if (details.Count() == 0)
                    {
                        continue;
                    }
                    try
                    {
                        htmlData = service.TransferDataConvert2Html(ul);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(ul.StaffName);
                        result.FailureMsg.Add(ex.Message);
                        continue;
                    }
                    try
                    {
                        service.MailSending(email, password, ul.StaffEmail, htmlData, "transfer", CCAddress);
                        result.SuccessList.Add(ul.StaffName);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(ul.StaffName);
                        result.FailureMsg.Add(ex.Message);
                    }
                }
                break;

            case "radix":
                InsuranceRadix ir           = JsonConvert.DeserializeObject <InsuranceRadix>(Request.Form["staffList"]);
                string         upContent    = Request.Form["upCont"];
                string         downContent  = Request.Form["downCont"];
                var            radixService = new InsuranceService();
                foreach (var item in ir.InsuranceRadixDetails)
                {
                    string htmlData = string.Empty;
                    try
                    {
                        htmlData = radixService.RadixDataConvert2Html(item, ir.Year.ToString(), upContent, downContent);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(item.ChineseName);
                        result.FailureMsg.Add(ex.Message);
                        continue;
                    }
                    try
                    {
                        radixService.MailSending(email, password, item.Email, htmlData, (ir.Year + 1).ToString(), CCAddress);
                        result.SuccessList.Add(item.ChineseName);
                    }
                    catch (Exception ex)
                    {
                        result.FailureList.Add(item.ChineseName);
                        result.FailureMsg.Add(ex.Message);
                    }
                }
                break;

            default:
                result.FailureList.Add("系统错误");
                result.FailureMsg.Add("邮件类型错误,请返回重新上传文件");
                break;
            }
            return(Json(result));
        }