Exemple #1
0
        private void GetCompanyByIdAfter(string id)
        {
            var biz = new BLL.DataCenterBiz();
            var ls  = biz.GetCompanyCodeById(id);

            if (ls != null)
            {
                ListItem listItem = new ListItem();
                listItem.Value = ls.Id;
                listItem.Text  = ls.Name;

                txtCompanyAfterReg.Text = ls.Name;
            }
            else
            {
                txtCompanyAfterReg.Text = "-";
            }
        }
Exemple #2
0
        public void SendExcel(string address, DataTable table, Dictionary <string, string> columns, DTO.UserProfile UserProfile)
        {
            Dictionary <string, string> Select = new Dictionary <string, string>();

            Select.Add("รหัสสอบ", "TESTING_NO");
            Select.Add("เลขที่นั่งสอบ", "APPLICANT_CODE");
            Select.Add("วันที่สมัครสอบ", "APPLY_DATE");
            Select.Add("รหัสบริษัทที่สังกัด", "INSUR_COMP_CODE");
            Select.Add("เลขบัตรประชาชน", "ID_CARD_NO");
            Select.Add("คำนำหน้า", "NAME");
            Select.Add("ชื่อ", "FIRSTNAME");
            Select.Add("นามสกุล", "LASTNAME");
            Select.Add("วันเดือนปีเกิด", "BIRTH_DATE");
            Select.Add("E-mail", "EMAIL");
            Select.Add("เบอร์โทรศัพท์", "TELEPHONE");

            columns = Select;

            try
            {
                BLL.DataCenterBiz biz          = new BLL.DataCenterBiz();
                string            comname      = biz.GetCompanyCodeById(UserProfile.CompCode).Name;
                string            emailSubject = "ระบบลงทะเบียนระบบช่องทางการบริหารตัวแทนหรือนายหน้าประกันภัย";
                StringBuilder     emailBody    = new StringBuilder();
                //emailBody.AppendLine("<div style='font-family: Verdana;font-size: 12px;'>");
                emailBody.AppendLine(String.Format("บริษัท {0} ขอจัดส่งข้อมูลรายชื่อผู้สมัครสอบ ระบบลงทะเบียนระบบช่องทางการบริหารตัวแทนหรือนายหน้าประกันภัย", comname));
                emailBody.AppendLine("ตามเอกสารแนบ");
                emailBody.AppendLine(string.Format("ชื่อผู้นำส่งข้อมูล {0} {1} email {2} ", UserProfile.Name, UserProfile.LastName, UserProfile.LoginName));
                emailBody.AppendLine(string.Format("นำส่งข้อมูลเมื่อวันที่ {0} ", DateTime.Now.ToLongDateString()));
                emailBody.AppendLine(string.Format("ด้วยความเคารพ บริษัท {0} ", comname));
                // emailBody.AppendLine("</div>");
                string fromemail = "*****@*****.**";
                _mailMessage = new MailMessage(fromemail, address)
                {
                    IsBodyHtml = true,
                    Subject    = emailSubject,
                    Body       = emailBody.ToString()
                };
                byte[] file = new byte[1024];

                DataTable tbExport = new DataTable();
                foreach (var item in columns)
                {
                    tbExport.Columns.Add(item.Key, typeof(string));
                }

                foreach (DataRow rows in table.Rows)
                {
                    DataRow row = tbExport.NewRow();
                    foreach (var item in columns)
                    {
                        if (item.Key.Contains("เบอร์โทรศัพท์"))
                        {
                            row[item.Key] = rows[item.Value].ToString().Replace("#", " ต่อ ");
                        }
                        else if (item.Key.Contains("วันเดือนปีเกิด") || item.Key.Contains("วันที่สมัครสอบ"))
                        {
                            row[item.Key] = rows[item.Value].ToString().Replace(" 0:00:00", "");
                        }
                        else if (item.Key.Contains("สถานะ"))
                        {
                            if (rows[item.Value].ToString() == "N")
                            {
                                row[item.Key] = Resources.errorExportBiz_001;
                            }
                            else if (rows[item.Value].ToString() == "Y")
                            {
                                row[item.Key] = Resources.errorExportBiz_002;
                            }
                            else if (rows[item.Value].ToString() == "W")
                            {
                                row[item.Key] = Resources.errorExportBiz_003;
                            }
                            else
                            {
                                row[item.Key] = rows[item.Value].ToString();
                            }
                        }
                        else
                        {
                            row[item.Key] = rows[item.Value].ToString();
                        }
                    }
                    tbExport.Rows.Add(row);
                }

                using (var package = new ExcelPackage())
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("FileExport");
                    worksheet.Cells["A1"].LoadFromDataTable(tbExport, true);
                    worksheet.DefaultColWidth = 25;
                    file = package.GetAsByteArray();
                }

                Stream     stream     = new MemoryStream(file);
                Attachment attachment = new Attachment(stream, UserProfile.CompCode + "_" + DateTime.Now.ToLongDateString() + ".xlsx");

                //AttachStream attachFile = new AttachStream() { FileName = "ExelFile", FileStream = stream };
                //IList<AttachStream> listattach = new List<AttachStream>();
                //listattach.Add(attachFile);
                //EmailServiceFactory.GetEmailService().SendMail(fromemail, address, "ระบบลงทะเบียนระบบช่องทางการบริหารตัวแทนหรือนายหน้าประกันภัย", emailBody.ToString(), listattach);


                _mailMessage.Attachments.Add(attachment);
                using (SmtpClient SmtpServer = new SmtpClient())
                {
                    if (_mailMessage != null)
                    {
                        SmtpServer.Send(_mailMessage);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }