Beispiel #1
0
        /// <summary>
        /// 判斷是否中獎
        /// </summary>
        public Dictionary <string, List <EinvoiceDataModel> > ConfirmWhetherToWinThePrize(string invoYm)
        {
            Dictionary <string, List <C0401H> >            invoices   = GetAllEinvoice(invoYm);
            Dictionary <string, List <EinvoiceDataModel> > resultData = new Dictionary <string, List <EinvoiceDataModel> >();

            foreach (var inv in invoices)
            {
                EinvoiceWinningNumberResultModel winningModel = GetEinvoiceWinningNumbers(inv.Key);
                if (winningModel.code != "200")
                {
                    continue;
                }
                resultData[inv.Key] = CompareNumbers(winningModel, inv.Value);
            }

            Dictionary <string, List <EinvoiceDataModel> > filterData = FilterWinning(resultData);

            GetDeatilsInfo(ref filterData);

            return(filterData);
        }
        public EinvoiceWinningNumberResultModel GetEinvoiceWinningNumbers(string invTerm)
        {
            EinvoiceWinningNumberSendModel send = new EinvoiceWinningNumberSendModel()
            {
                action = "QryWinningList", invTerm = invTerm
            };

            string     resultStr  = string.Empty;
            WebRequest webRequest = null;
            string     sendData   = this.Repository.ConvertObjectToQueryString(send);

            byte[] bytes = Encoding.UTF8.GetBytes(sendData);
            //Request
            try
            {
                webRequest = this.Repository.CreateWebRequest(ConnectionStringModel.EinvoiceSearchApiConnectionStr);
                webRequest.ContentLength = bytes.Length;
                this.Repository.SendWebRequest(webRequest, bytes);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //Get Response
            try
            {
                resultStr = this.Repository.GetResponse(webRequest);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            EinvoiceWinningNumberResultModel result = JsonConvert.DeserializeObject <EinvoiceWinningNumberResultModel>(resultStr);

            return(result);
        }
Beispiel #3
0
        public HttpResponseMessage GetEinvoiceWinningNumber([FromUri] string invTerm)
        {
            EinvoiceWinningNumberResultModel result = this.Repository.GetEinvoiceWinningNumbers(invTerm);

            return(RinnaiPortalOpenApi.Repositories.APIRepository.CreateDataResponse(Request, System.Net.HttpStatusCode.OK, result));;
        }
Beispiel #4
0
        public void SandMailHandler()
        {
            DateTime today        = DateTime.UtcNow.AddHours(8);
            string   currentYear  = (today.Year - 1911).ToString();
            string   currentMonth = (today.AddMonths(-1).Month).ToString().PadLeft(2, '0');
            string   invTerm      = Api.ConfirmEinvoicePeriodByDate(string.Concat(currentYear, currentMonth));
            Dictionary <string, List <EinvoiceDataModel> > result = new Dictionary <string, List <EinvoiceDataModel> >();

            try
            {
                string        subject = (ProcessUntity.CurrentProcessMode == ProcessModeEnum.DEBUG) ? string.Format("[系統部測試]:電子發票 {0}月份中獎名單", invTerm) : string.Format("[通知]:電子發票 {0}月份中獎名單", invTerm);
                List <string> cc      = new List <string>()
                {
                    PublicRepository.AdminEmail
                };

                var info = new MailInfo()
                {
                    Subject = subject,
                    CC      = cc,
                };

                StringBuilder mailBody = new StringBuilder();

                EinvoiceWinningNumberResultModel invTermData = Api.GetEinvoiceWinningNumbers(invTerm);

                if (invTermData.code != "200")
                {
                    mailBody.Append(string.Format("統一發票 期別:{0} API回傳代碼:{1} API回傳訊息:{2}", invTerm, invTermData.code, invTermData.msg));
                    info.To = new List <string>()
                    {
                        PublicRepository.AdminEmail
                    };
                    info.Body = mailBody;
                    //寄信
                    Mailer mailer = new Mailer(info);
                    mailer.SendMail();
                }
                else
                {
                    result = Api.ConfirmWhetherToWinThePrize(invTermData.invoYm);

                    StringBuilder adminMailBody = new StringBuilder();
                    foreach (var r in result)
                    {
                        mailBody.AppendLine(@"<p><strong>以下為各單位本期<span style=""color: #ff0000;"">中獎發票號碼</span>清單,請將發票列印出後五天內以雙掛號寄給消費者,謝謝。</strong></p>");
                        mailBody.AppendLine(@"<table style=""width: 100%;border: 1px solid #666;border-spacing: initial;margin: 10px 0;"">");
                        mailBody.AppendLine(@"<thead>");
                        mailBody.AppendLine(@"<tr>");
                        mailBody.AppendLine(@"<th></th>");
                        mailBody.AppendLine(@"<th>開立單位</th>");
                        mailBody.AppendLine(@"<th>訂單號碼</th>");
                        mailBody.AppendLine(@"<th>發票號碼</th>");
                        mailBody.AppendLine(@"<th>中獎期數</th>");
                        mailBody.AppendLine(@"<th>中獎號碼</th>");
                        //mailBody.AppendLine(@"<th>中獎獎別</th>");
                        mailBody.AppendLine(@"</tr>");
                        mailBody.AppendLine(@"</thead>");

                        mailBody.AppendLine(@"<tbody>");
                        foreach (var inv in r.Value as List <EinvoiceDataModel> )
                        {
                            int index = r.Value.IndexOf(inv) + 1;
                            mailBody.AppendLine(@"<tr>");

                            mailBody.AppendLine(@"<td style=""border: 1px solid #ccc;"">");
                            mailBody.AppendLine(index.ToString());
                            mailBody.AppendLine(@"</td>");

                            mailBody.AppendLine(@"<td style=""border: 1px solid #ccc;"">");
                            mailBody.AppendLine(inv.Detalis.DepartmentName);
                            mailBody.AppendLine(@"</td>");

                            mailBody.AppendLine(@"<td style=""border: 1px solid #ccc;"">");
                            mailBody.AppendLine(inv.Detalis.OrderNo);
                            mailBody.AppendLine(@"</td>");

                            mailBody.AppendLine(@"<td style=""border: 1px solid #ccc;"">");
                            mailBody.AppendLine(inv.Data.MInvoiceNumber);
                            mailBody.AppendLine(@"</td>");

                            mailBody.AppendLine(@"<td style=""border: 1px solid #ccc;"">");
                            mailBody.AppendLine(invTerm);
                            mailBody.AppendLine(@"</td>");

                            mailBody.AppendLine(@"<td style=""border: 1px solid #ccc;"">");
                            mailBody.AppendLine(inv.WinningNumber);
                            mailBody.AppendLine(@"</td>");

                            //mailBody.AppendLine(@"<td style=""border: 1px solid #ccc;"">");
                            //mailBody.AppendLine(inv.WinningType.ToString());
                            //mailBody.AppendLine(@"</td>");

                            mailBody.AppendLine(@"</tr>");
                        }
                        mailBody.AppendLine(@"</tbody>");
                        mailBody.AppendLine(@"</table>");
                        info.Body = mailBody;
                        adminMailBody.AppendLine(mailBody.ToString());

                        #region Mail 通知各單位

                        List <string> mailTo = new List <string>();
                        if (ProcessUntity.CurrentProcessMode == ProcessModeEnum.RELEASE)
                        {
                            int defaultIntoCount = r.Value.First().Detalis.MailToObject.Count;
                            if (defaultIntoCount == 0)
                            {
                                mailTo = Api.GetMailToObjectGroupByDepartmentID(r.Key);
                            }
                            else
                            {
                                mailTo = r.Value.First().Detalis.MailToObject;
                            }
                            info.To = mailTo;
                        }
                        else
                        {
                            info.To = new List <string>()
                            {
                                PublicRepository.AdminEmail
                            }
                        };
                        //寄信
                        Mailer mailer        = new Mailer(info);
                        var    isSuccessSend = mailer.SendMail();

                        #region 寫入寄信Log檔

                        Api.WriteContactEmailLog(invTerm, r, info.To, isSuccessSend);

                        #endregion 寫入寄信Log檔

                        #endregion Mail 通知各單位

                        mailBody.Clear();
                    }

                    #region 傳送全部資料至資訊課人員

                    List <string> adminGroup = Api.GetMailToObjectGroupByDepartmentID(PublicRepository.AdminDepartmentCode);
                    var           adminInfo  = new MailInfo()
                    {
                        Subject = subject,
                        To      = ProcessUntity.CurrentProcessMode == ProcessModeEnum.RELEASE ? adminGroup : new List <string>()
                        {
                            PublicRepository.AdminEmail
                        },
                        CC   = cc,
                        Body = adminMailBody
                    };
                    var isSuccessAdminSend = new Mailer(adminInfo).SendMail();

                    #region 寫入寄信Log檔

                    result.All(a => { Api.WriteContactEmailLog(invTerm, a, adminInfo.To, isSuccessAdminSend, true); return(true); });

                    #endregion 寫入寄信Log檔

                    #endregion 傳送全部資料至資訊課人員
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Exception Occured! {0}", ex.Message));
                Console.ReadKey();
            }
        }
Beispiel #5
0
        public EinvoiceWinningNumberResultModel GetEinvoiceWinningNumber([FromUri] string invTerm)
        {
            EinvoiceWinningNumberResultModel result = this.Repository.GetEinvoiceWinningNumbers(invTerm);

            return(result);
        }
Beispiel #6
0
        private List <EinvoiceDataModel> CompareNumbers(EinvoiceWinningNumberResultModel winningModel, List <C0401H> invs)
        {
            List <EinvoiceDataModel> invoies = new List <EinvoiceDataModel>();

            foreach (var inv in invs)
            {
                EinvoiceDataModel temp = new EinvoiceDataModel()
                {
                    Data = inv
                };
                invoies.Add(temp);
            }

            foreach (var inv in invoies)
            {
                string invNum = inv.Data.MInvoiceNumber.Substring(2, inv.Data.MInvoiceNumber.Length - 2);

                #region 千萬獎

                if (winningModel.superPrizeNo.Equals(invNum))
                {
                    inv.WinningType   = API.Enums.WinningTypeEnum.SUPER;
                    inv.WinningNumber = winningModel.superPrizeNo;
                    continue;
                }

                #endregion 千萬獎

                #region 特獎

                if (winningModel.spcPrizeNo.Equals(invNum) ||
                    winningModel.spcPrizeNo2.Equals(invNum) ||
                    winningModel.spcPrizeNo3.Equals(invNum))
                {
                    inv.WinningType   = API.Enums.WinningTypeEnum.SPECIAL;
                    inv.WinningNumber =
                        winningModel.spcPrizeNo.Equals(invNum) ?
                        winningModel.spcPrizeNo : winningModel.spcPrizeNo2.Equals(invNum) ?
                        winningModel.spcPrizeNo2 : winningModel.spcPrizeNo3.Equals(invNum) ?
                        winningModel.spcPrizeNo3 : string.Empty;
                    continue;
                }

                #endregion 特獎

                #region 頭獎(一路比對到六獎)

                CompareFirstPrizeNumber(winningModel.firstPrizeNo1, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo2, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo3, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo4, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo5, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo6, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo7, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo8, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo9, invNum, inv);
                CompareFirstPrizeNumber(winningModel.firstPrizeNo10, invNum, inv);

                #endregion 頭獎(一路比對到六獎)

                #region 六獎(含加開)

                CompareSixthPrizeNumber(winningModel.sixthPrizeNo1, invNum, inv);
                CompareSixthPrizeNumber(winningModel.sixthPrizeNo2, invNum, inv);
                CompareSixthPrizeNumber(winningModel.sixthPrizeNo3, invNum, inv);
                CompareSixthPrizeNumber(winningModel.sixthPrizeNo4, invNum, inv);
                CompareSixthPrizeNumber(winningModel.sixthPrizeNo5, invNum, inv);
                CompareSixthPrizeNumber(winningModel.sixthPrizeNo6, invNum, inv);

                #endregion 六獎(含加開)
            }
            return(invoies);
        }