コード例 #1
0
        public ActionResult Index()
        {
            //check login
            if (!IsLogged())
            {
                return(BackToLogin());
            }
            DanhmucServices       service            = new DanhmucServices();
            PhongBanModels        parampb            = new PhongBanModels();
            List <PhongBanModels> lstResult_phongban = service.SelectRowsBCTC(parampb);
            StringBuilder         sbphongban         = new StringBuilder();
            string pb        = "";
            string thudientu = Session["thudientu"].ToString().Trim();

            if (Session["loginid"].ToString().Trim().ToLower() == "admin" || Session["grouptk"].ToString().Trim() == "1")
            {
                //var lstpban = lstResult_phongban.Where(p => p.maphongban == maphongban).ToList();
                //if (lstpban.Count() > 0)
                //    pb = "<option value=" + lstpban[0].maphongban + ">" + lstpban[0].tenphongban + "</option>";
                //pb = pb + "<option value=0>Chọn phòng ban</option>";
                foreach (var item in lstResult_phongban)
                {
                    pb = pb + "<option value=" + item.maphongban + "> " + item.tenphongban + " </option>";
                }
            }
            else
            {
                foreach (var item in lstResult_phongban.Where(p => p.email == thudientu || p.sodienthoai == thudientu || p.ghichu == thudientu ||
                                                              p.ghichu1 == thudientu || p.ghichu2 == thudientu ||
                                                              p.cv_thietbi == thudientu || p.gs_thietbi == thudientu ||
                                                              p.cv_hsse == thudientu || p.gs_hsse == thudientu ||
                                                              p.cv_qaqc == thudientu || p.gs_qaqc == thudientu ||
                                                              p.cv_mep == thudientu || p.gs_mep == thudientu))
                {
                    pb = pb + "<option value=" + item.maphongban + "> " + item.tenphongban + " </option>";
                }
            }
            ViewBag.sbphongban = pb.ToString();


            //foreach (var item in lstResult_phongban.Where(p=>p.phongban_congtruong=="0"))
            //{
            //    sbphongban.Append(string.Format("<option value='{0}'>{1}</option>", item.maphongban, item.tenphongban));
            //}
            // ViewBag.sbphongban = sbphongban.ToString();
            return(View());
        }
コード例 #2
0
        public JsonResult SelectRows_WeedMeeting(WeedMeetingModels model, int curentPage)
        {
            WeedMeetingModels param           = new WeedMeetingModels();
            DaotaoServices    service         = new DaotaoServices();
            DanhmucServices   service_danhmuc = new DanhmucServices();

            //param.nguoitao = int.Parse(Session["userid"].ToString());
            param.maphongban = model.maphongban;
            param.loaibaocao = model.loaibaocao;
            //if (Session["loginid"].ToString().Trim().ToLower() == "admin" || Session["grouptk"].ToString().Trim() == "1")
            //{
            param.nguoitao = 0;
            //}
            string thudientu = Session["thudientu"].ToString().Trim();



            List <PhongBanModels> y = null;
            var lstcaptrentt        = y;

            PhongBanModels        parampb            = new PhongBanModels();
            List <PhongBanModels> lstResult_phongban = service_danhmuc.SelectRowsBCTC(parampb);

            lstcaptrentt = lstResult_phongban.Where(p => p.maphongban == model.maphongban).ToList();

            //StringBuilder sbloaibaocao = new StringBuilder();
            //sbloaibaocao.Append(string.Format("<option value={0}>{1}</option>", "1", "Báo cáo tuần CHT/TPB"));
            if (lstcaptrentt[0].email == thudientu || lstcaptrentt[0].ghichu == thudientu || lstcaptrentt[0].sodienthoai == thudientu ||
                lstcaptrentt[0].ghichu1 == thudientu || lstcaptrentt[0].ghichu2 == thudientu || Session["loginid"].ToString().Trim().ToLower() == "admin" || Session["grouptk"].ToString().Trim() == "1")
            {
                param.loaibaocao = param.loaibaocao;
            }
            else if (model.loaibaocao == 2 && (lstcaptrentt[0].cv_thietbi == thudientu || lstcaptrentt[0].gs_thietbi == thudientu))
            {
                param.loaibaocao = 2;
            }
            else if (model.loaibaocao == 3 && (lstcaptrentt[0].cv_hsse == thudientu || lstcaptrentt[0].gs_hsse == thudientu))
            {
                param.loaibaocao = 3;
            }

            else if (model.loaibaocao == 4 && (lstcaptrentt[0].cv_qaqc == thudientu || lstcaptrentt[0].gs_qaqc == thudientu))
            {
                param.loaibaocao = 4;
            }

            else if (model.loaibaocao == 5 && (lstcaptrentt[0].cv_mep == thudientu || lstcaptrentt[0].gs_mep == thudientu))
            {
                param.loaibaocao = 5;
            }
            else
            {
                param.loaibaocao = 6;
            }

            int tongsodong = service.CountRows_WeedMeeting2(param);
            int sotrang    = 1;

            if (tongsodong > 20)
            {
                if (tongsodong % 20 > 0)
                {
                    sotrang = (tongsodong / 20) + 1;
                }
                else
                {
                    sotrang = (tongsodong / 20);
                }
            }

            int trangbd = 1; int trangkt = 20;

            if (curentPage != 1 && curentPage <= sotrang)
            {
                trangbd = (trangkt * (curentPage - 1)) + 1;
                trangkt = trangkt * curentPage;
            }

            List <WeedMeetingModels> lstResult = new List <WeedMeetingModels>();

            if (curentPage <= sotrang)
            {
                lstResult = service.SelectRows_WeedMeetingBCTC(param, trangbd, trangkt);
            }
            else if (curentPage != 1 && curentPage > sotrang)
            {
                curentPage = curentPage - 1;
            }


            StringBuilder sbResult             = new StringBuilder();
            StringBuilder sbRows               = new StringBuilder();
            int           tongdong             = 0;

            if (lstResult.Count > 0)
            {
                string strSTT = "";
                int    i      = trangbd;
                foreach (var item in lstResult)
                {
                    strSTT = i.ToString();
                    if (item.loaicuochop == "1")
                    {
                        item.tenloaicuochop = "Họp tuần phòng";
                    }
                    else if (item.loaicuochop == "2")
                    {
                        item.tenloaicuochop = "Họp tuần BGĐ";
                    }
                    else if (item.loaicuochop == "3")
                    {
                        item.tenloaicuochop = "Họp khác";
                    }
                    else
                    {
                        item.tenloaicuochop = "";
                    }

                    if (item.phonghop == "1")
                    {
                        item.tenphonghop = "Tầng 3 - Phòng họp 1";
                    }
                    else if (item.phonghop == "2")
                    {
                        item.tenphonghop = "Tầng 3 - Phòng họp 2";
                    }
                    else if (item.phonghop == "3")
                    {
                        item.tenphonghop = "Tầng 3 - Phòng họp lớn";
                    }
                    else if (item.phonghop == "4")
                    {
                        item.tenphonghop = "Tầng 3A - Phòng họp nhỏ";
                    }
                    else if (item.phonghop == "5")
                    {
                        item.tenphonghop = "Tầng 3A - Phòng họp lớn";
                    }
                    else if (item.phonghop == "6")
                    {
                        item.tenphonghop = "Khác";
                    }
                    else
                    {
                        item.tenphonghop = "";
                    }

                    sbRows.Append(PrepareDataJson_WeedMeeting(item, strSTT));
                    i++;
                }
                tongdong = i - 1;
                if (sbRows.Length > 0)
                {
                    sbRows.Remove(sbRows.Length - 1, 1);
                }
            }
            if (tongsodong == 0)
            {
                sotrang = 0;
            }
            sbResult.Append("{");
            sbResult.Append("\"isHeader\":\"" + "111" + "\",");

            sbResult.Append("\"tongdong\":\"" + "" + tongsodong + "" + "\",");

            sbResult.Append("\"Pages\":\"" + "" + sotrang + "" + "\",");
            sbResult.Append("\"SubRow\":\"" + "false" + "\",");

            sbResult.Append("\"data\":[" + sbRows.ToString() + "]");
            sbResult.Append("}");

            return(Json(sbResult.ToString(), JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public void MailLich(string NoiDung, string path, string filename, string maphongban, int phongban_congtruong)
        {
            string sMailGui = System.Configuration.ConfigurationManager.AppSettings["MailSend"];
            string sPass    = System.Configuration.ConfigurationManager.AppSettings["MailPass"];
            string sHost    = System.Configuration.ConfigurationManager.AppSettings["MailHost"];
            string sPort    = System.Configuration.ConfigurationManager.AppSettings["MailPort"];
            string sTieuDe  = System.Configuration.ConfigurationManager.AppSettings["ScheduleSubject"];
            string sMailTo  = System.Configuration.ConfigurationManager.AppSettings["schedulerman"];

            // gui mail

            var fromAddress = new MailAddress(sMailGui);

            string fromPassword = sPass;
            string subject      = sTieuDe;
            string body         = NoiDung;

            DanhmucServices service = new DanhmucServices();
            PhongBanModels  parampb = new PhongBanModels();

            List <PhongBanModels> lstResult_phongban;
            List <PhongBanModels> y = null;
            var lstcaptrentt        = y;

            if (phongban_congtruong == 0)
            {
                lstResult_phongban = service.SelectRows(parampb);
                lstcaptrentt       = lstResult_phongban.Where(p => p.maphongban == maphongban).ToList();
                if (lstcaptrentt[0].email.ToString().Trim() == null)
                {
                    sMailTo = "*****@*****.**";
                }
                else
                {
                    sMailTo = lstcaptrentt[0].email;
                }
            }
            else if (phongban_congtruong == 1)
            {
                lstResult_phongban = service.SelectRows2(parampb);
                lstcaptrentt       = lstResult_phongban.Where(p => p.maphongban == maphongban).ToList();
                if (lstcaptrentt[0].email.ToString().Trim() == null)
                {
                    sMailTo = "*****@*****.**";
                }
                else
                {
                    sMailTo = lstcaptrentt[0].email;
                }
            }
            else if (phongban_congtruong == 2)
            {
                lstResult_phongban = service.SelectRowsGDDA(parampb);
                lstcaptrentt       = lstResult_phongban.Where(p => p.maphongban == maphongban).ToList();
                if (lstcaptrentt[0].email.ToString().Trim() == null)
                {
                    sMailTo = "*****@*****.**";
                }
                else
                {
                    sMailTo = lstcaptrentt[0].email;
                }
            }
            else if (phongban_congtruong == 3)
            {
                lstResult_phongban = service.SelectRowsBCTC(parampb);
                lstcaptrentt       = lstResult_phongban.Where(p => p.maphongban == maphongban).ToList();
                if (lstcaptrentt[0].email.ToString().Trim() == null)
                {
                    sMailTo = "*****@*****.**";
                }
                else
                {
                    sMailTo = lstcaptrentt[0].email;
                }
            }

            var toAddress = new MailAddress(sMailTo);

            var smtp = new SmtpClient
            {
                Host                  = sHost,
                Port                  = int.Parse(sPort),
                EnableSsl             = false,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
            };

            //var smtp = new SmtpClient();

            subject = "NEWTECONS PROJECT REPORT: " + lstcaptrentt[0].tenphongban;
            body    = "<p>Kính gửi anh chị,</p><p>Đính kèm là báo cáo tuần gửi từ hệ thống của: " + lstcaptrentt[0].tenphongban + "</p>" + "<p>Trân trọng,</p>";

            using (var message = new MailMessage(fromAddress, toAddress)
            {
                IsBodyHtml = true,
                Subject = subject,
                Body = body
            })
            {
                try
                {
                    Attachment data = new Attachment(path, MediaTypeNames.Application.Octet);
                    message.Attachments.Add(data);
                    if (!string.IsNullOrEmpty(lstcaptrentt[0].sodienthoai))
                    {
                        message.CC.Add(lstcaptrentt[0].sodienthoai);
                    }

                    if (!string.IsNullOrEmpty(lstcaptrentt[0].ghichu))
                    {
                        message.CC.Add(lstcaptrentt[0].ghichu);
                    }

                    if (!string.IsNullOrEmpty(lstcaptrentt[0].ghichu1))
                    {
                        message.CC.Add(lstcaptrentt[0].ghichu1);
                    }

                    if (!string.IsNullOrEmpty(lstcaptrentt[0].ghichu2))
                    {
                        message.CC.Add(lstcaptrentt[0].ghichu2);
                    }

                    smtp.Send(message);
                    smtp.Dispose();
                }
                catch (SmtpFailedRecipientsException ex)
                {
                    for (int i = 0; i < ex.InnerExceptions.Length; i++)
                    {
                        SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
                        if (status == SmtpStatusCode.MailboxBusy || status == SmtpStatusCode.MailboxUnavailable)
                        {
                            // Console.WriteLine("Delivery failed - retrying in 5 seconds.");
                            System.Threading.Thread.Sleep(5000);
                            smtp.Send(message);
                        }
                        else
                        {
                            //  Console.WriteLine("Failed to deliver message to {0}", ex.InnerExceptions[i].FailedRecipient);
                            throw ex;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //  Console.WriteLine("Exception caught in RetryIfBusy(): {0}",ex.ToString());
                    throw ex;
                }
                finally
                {
                    smtp.Dispose();
                }
            }
        }