Esempio n. 1
0
        public async Task <int> SendEmail(V_CSCOAR vCSCOAR)
        {
            if (string.IsNullOrEmpty(vCSCOAR.Email))
            {
                return(0);
            }


            string html = RenderViewToString(ControllerContext, "~/views/VCSCOAR/Reminder.cshtml", vCSCOAR, true);

            //string filename = @"c:\temp\email.html";
            //var sw = new System.IO.StreamWriter(filename, true);
            //sw.WriteLine(html);
            //sw.Close();

            EmailFormModel model = new WebApplication1.EmailFormModel();

            model.Message   = html;
            model.FromEmail = "*****@*****.**";
            model.FromName  = "ASI Secretary";

            var body    = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            var message = new MailMessage();

            message.To.Add(new MailAddress(vCSCOAR.Email)); //replace with valid value
            message.Subject    = "Annual Return Reminder";
            message.Body       = string.Format(body, model.FromName, model.FromEmail, model.Message);
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {
                await smtp.SendMailAsync(message);
            }
            return(1);
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(string id)
        {
            V_CSCOAR v_CSCOAR = db.V_CSCOAR.Find(id);

            db.V_CSCOAR.Remove(v_CSCOAR);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public async Task <ActionResult> Email(string id)
        {
            string   sid     = MyHtmlHelpers.ConvertByteStrToId(id);
            V_CSCOAR vCSCOAR = getReminder(sid);
            int      cnt     = await SendEmail(vCSCOAR);

            return(RedirectToAction("Sent", "Home", new { cnt = cnt }));
        }
Esempio n. 4
0
        public IQueryable <V_CSCOAR> CurrentSelection()
        {
            string   pSearchCode    = "";
            string   pSearchName    = "";
            string   pSearchStaff   = "";
            DateTime pSearchARDate  = DateTime.Parse("01/01/0001");
            DateTime pSearchEndDate = DateTime.Parse("01/01/0001");

            if (Session["SearchVCSCOARRec"] != null)
            {
                V_CSCOAR searchRec = (V_CSCOAR)(Session["SearchVCSCOARRec"]);
                pSearchCode    = searchRec.COREGNO ?? "";
                pSearchName    = searchRec.CONAME ?? "";
                pSearchStaff   = searchRec.STAFFCODE ?? "";
                pSearchARDate  = searchRec.LASTAR ?? DateTime.Parse("01/01/0001");
                pSearchEndDate = pSearchARDate.AddMonths(1).AddDays(-1);
            }
            else
            {
                pSearchARDate  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                pSearchEndDate = pSearchARDate.AddMonths(1).AddDays(-1);
            }


            IQueryable <V_CSCOAR> cSCOAR = db.V_CSCOAR;
            int pSearchMonth             = pSearchARDate.Month;

            if (pSearchCode != "")
            {
                cSCOAR = cSCOAR.Where(x => x.COREGNO.Contains(pSearchCode.ToUpper()));
            }
            ;
            if (pSearchName != "")
            {
                cSCOAR = cSCOAR.Where(x => x.CONAME.Contains(pSearchName.ToUpper()));
            }
            ;
            if (pSearchStaff != "")
            {
                cSCOAR = cSCOAR.Where(x => x.STAFFCODE == pSearchStaff);
            }
            ;
            if (pSearchARDate != DateTime.Parse("01/01/0001"))
            {
                cSCOAR = cSCOAR.Where(x => (x.REMINDER2 == "Y" && (x.REMINDER1.Value.Month == pSearchMonth)) || (x.REMINDER1 >= pSearchARDate && x.REMINDER1 <= pSearchEndDate));
            }
            ;

            foreach (V_CSCOAR rec in cSCOAR)
            {
                rec.ReminderMonth = pSearchARDate.Month;
                rec.ReminderYear  = pSearchARDate.Year;
                rec.REMINDERTYPE  = rec.CReminderType;
            }
            ViewBag.ReportTitle = "AR Reminder Listing By " + (string)Session["SearchVCSCOARSort"] + " Dated " + pSearchARDate.ToString("dd/MM/yyyy");
            return(cSCOAR);
        }
Esempio n. 5
0
 public ActionResult Edit([Bind(Include = "CONAME,CONO,ARNO,LASTAR,ARTOFILE,FILEDAR,REMINDER1,REM,STAMP,SUBMITAR,REMINDER2")] V_CSCOAR v_CSCOAR)
 {
     if (ModelState.IsValid)
     {
         db.Entry(v_CSCOAR).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(v_CSCOAR));
 }
Esempio n. 6
0
        public PartialViewResult Search()
        {
            V_CSCOAR searchRec = null;

            ;
            if (Session["SearchVCSCOARRec"] != null)
            {
                searchRec = (V_CSCOAR)Session["SearchVCSCOARRec"];
            }
            else
            {
                searchRec        = new V_CSCOAR();
                searchRec.LASTAR = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            }
            if (Session["SearchVCSCOARSort"] == null)
            {
                Session["SearchVCSCOARSort"] = "CONAME";
            }
            ;

            List <SelectListItem> listItems = new List <SelectListItem>();

            listItems.Add(new SelectListItem
            {
                Text     = "Company Name",
                Value    = "CONAME",
                Selected = (string)Session["SearchVCSCOARSort"] == "CONAME"
            });

            listItems.Add(new SelectListItem
            {
                Text     = "Company #",
                Value    = "CONO",
                Selected = (string)Session["SearchVCSCOARSort"] == "CONO"
            });

            listItems.Add(new SelectListItem
            {
                Text     = "Staff",
                Value    = "STAFFCODE",
                Selected = (string)Session["SearchVCSCOARSort"] == "STAFFCODE"
            });

            listItems.Add(new SelectListItem
            {
                Text     = "Reminder Type",
                Value    = "TYPE",
                Selected = (string)Session["SearchVCSCOARSort"] == "TYPE"
            });

            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC");
            ViewBag.SORTBY    = listItems;
            return(PartialView("Partial/Search", searchRec));
        }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "CONAME,CONO,ARNO,LASTAR,ARTOFILE,FILEDAR,REMINDER1,REM,STAMP,SUBMITAR,REMINDER2")] V_CSCOAR v_CSCOAR)
        {
            if (ModelState.IsValid)
            {
                db.V_CSCOAR.Add(v_CSCOAR);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(v_CSCOAR));
        }
Esempio n. 8
0
        // GET: VCSCOAR/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            V_CSCOAR v_CSCOAR = db.V_CSCOAR.Find(id);

            if (v_CSCOAR == null)
            {
                return(HttpNotFound());
            }
            return(View(v_CSCOAR));
        }
Esempio n. 9
0
        public async Task <ActionResult> Emails()
        {
            var cSCOARList = CurrentSelection();

            int cnt = 0;

            foreach (V_CSCOAR item in cSCOARList)
            {
                if (!string.IsNullOrEmpty(item.Email))
                {
                    V_CSCOAR vCSCOAR = getReminder(item.CONO);
                    cnt += await SendEmail(vCSCOAR);
                }
            }
            return(RedirectToAction("Sent", "Home", new { cnt = cnt }));
        }
Esempio n. 10
0
        public V_CSCOAR getReminder(string sid) // Should use a ViewModel rather than using ViewBag
        {
            if (sid == null)
            {
                return(null);
            }
            V_CSCOAR v_CSCOAR = db.V_CSCOAR.Find(sid);
            CSCOADDR cSCOADDR = db.CSCOADDRs.Where(x => x.CONO == sid && x.MAILADDR == "Y").FirstOrDefault();

            if (cSCOADDR == null)
            {
                cSCOADDR = db.CSCOADDRs.Where(x => x.CONO == sid).FirstOrDefault();
            }

            if (cSCOADDR != null)
            {
                ViewBag.Addr1 = cSCOADDR.ADDR1;
                ViewBag.Addr2 = cSCOADDR.ADDR2;
                ViewBag.Addr3 = cSCOADDR.ADDR3;
                ViewBag.Addr4 = cSCOADDR.POSTAL;
                if (cSCOADDR.HKCITY != null)
                {
                    ViewBag.Addr4 = ViewBag.Addr4 + " " + cSCOADDR.HKCITY.CITYDESC;
                }
                else
                {
                    ViewBag.Addr4 = ViewBag.Addr4 + " " + cSCOADDR.CITYCODE;
                }
            }
            else
            {
                ViewBag.Addr1 = "";
                ViewBag.Addr2 = "";
                ViewBag.Addr3 = "";
                ViewBag.Addr4 = "";
            }

            string   pSearchCode    = "";
            string   pSearchName    = "";
            string   pSearchStaff   = "";
            DateTime pSearchARDate  = DateTime.Parse("01/01/0001");
            DateTime pSearchEndDate = DateTime.Parse("01/01/0001");

            if (Session["SearchVCSCOARRec"] != null)
            {
                V_CSCOAR searchRec = (V_CSCOAR)(Session["SearchVCSCOARRec"]);
                pSearchCode    = searchRec.CONO ?? "";
                pSearchName    = searchRec.CONAME ?? "";
                pSearchStaff   = searchRec.STAFFCODE ?? "";
                pSearchARDate  = searchRec.LASTAR ?? DateTime.Parse("01/01/0001");
                pSearchEndDate = pSearchARDate.AddMonths(1).AddDays(-1);
            }
            else
            {
                pSearchARDate  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                pSearchEndDate = pSearchARDate.AddMonths(1).AddDays(-1);
            }


            SACOMP profileRec = db.SACOMPs.FirstOrDefault();

            ViewBag.Company = profileRec.CONAME.ToUpper() + " (" + profileRec.COREGNO + ") ";
            ViewBag.Address = profileRec.COADDR1 + " " + profileRec.COADDR2 + " " + profileRec.COADDR3 + " " + profileRec.COADDR4;
            ViewBag.Contact = "Tel: " + profileRec.COPHONE1 + " Fax: " + profileRec.COFAX1 + " E-Mail: " + profileRec.COWEB;


            v_CSCOAR.ReminderMonth = pSearchARDate.Month;
            v_CSCOAR.ReminderYear  = pSearchARDate.Year;
            ViewBag.ReminderDate   = v_CSCOAR.ReminderDate?.ToString("dd MMM yyyy");

            if (v_CSCOAR.ARTOFILE.HasValue)
            {
                ViewBag.AR = v_CSCOAR.ARTOFILE.Value.ToString("dd MMM yyyy");
                DateTime Deadline = v_CSCOAR.ARTOFILE.Value.AddDays(30);
                ViewBag.Deadline = Deadline.ToString("dd MMM yyyy");
            }

            int      c      = 0;
            DateTime lastar = DateTime.Parse("01/01/0001");

            if (v_CSCOAR.CReminderType == "Special")
            {
                MvcHtmlString       s      = MvcHtmlString.Create("");// MvcHtmlString.Create(ViewBag.AR);
                MvcHtmlString       t      = MvcHtmlString.Create("");
                IQueryable <CSCOAR> cSCOAR = db.CSCOARs.Where(x => x.CONO == v_CSCOAR.CONO && x.FILEDAR == null).OrderBy(y => y.ARNO);
                foreach (CSCOAR rec in cSCOAR)
                {
                    if (rec.ARTOFILE != null)
                    {
                        if (c == 0)
                        {
                            s = MvcHtmlString.Create(s + rec.ARTOFILE?.ToString("dd MMM yyyy"));
                            t = MvcHtmlString.Create(t + rec.ARTOFILE.Value.AddDays(30).ToString("dd MMM yyyy"));
                        }
                        else
                        {
                            s = MvcHtmlString.Create(s + " <br /> " + rec.ARTOFILE?.ToString("dd MMM yyyy"));
                            t = MvcHtmlString.Create(t + " <br /> " + rec.ARTOFILE.Value.AddDays(30).ToString("dd MMM yyyy"));
                        }
                        c++;

                        lastar = rec.ARTOFILE ?? DateTime.Parse("01/01/0001");
                    }
                }

                if (lastar.Year != 1) // this is to stop processing if there is no AR records
                {
                    lastar = lastar.AddYears(1);
                    while (lastar.Year <= pSearchARDate.Year)
                    {
                        if (c == 0)
                        {
                            s = MvcHtmlString.Create(s + lastar.ToString("dd MMM yyyy"));
                            t = MvcHtmlString.Create(t + lastar.AddDays(30).ToString("dd MMM yyyy"));
                        }
                        else
                        {
                            s = MvcHtmlString.Create(s + " <br /> " + lastar.ToString("dd MMM yyyy"));
                            t = MvcHtmlString.Create(t + " <br /> " + lastar.AddDays(30).ToString("dd MMM yyyy"));
                        }
                        c++;
                        if (lastar.Year >= pSearchARDate.Year)
                        {
                            break;
                        }
                        lastar = lastar.AddYears(1);
                    }
                }
                ViewBag.AR       = s;
                ViewBag.Deadline = t;
            }
            return(v_CSCOAR);
        }
Esempio n. 11
0
 public ActionResult SearchPost(V_CSCOAR cSCOAR)
 {
     Session["SearchVCSCOARRec"]  = cSCOAR;
     Session["SearchVCSCOARSort"] = Request.Params["SORTBY"] ?? "CONAME";
     return(Index(1));
 }