Ejemplo n.º 1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            OtaSalesReport otaSalesReport = await db.OtaSalesReport.FindAsync(id);

            db.OtaSalesReport.Remove(otaSalesReport);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit(OtaSalesReport otaSalesReport)
        {
            if (ModelState.IsValid)
            {
                db.Entry(otaSalesReport).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(otaSalesReport));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OtaSalesReport otaSalesReport = await db.OtaSalesReport.FindAsync(id);

            if (otaSalesReport == null)
            {
                return(HttpNotFound());
            }
            return(View(otaSalesReport));
        }
Ejemplo n.º 4
0
        public ActionResult Create(OtaSalesReport otaSalesReport)
        {
            if (ModelState.IsValid)
            {
                //自动根据时间读取拜访记录生成周报,有html的格式
                otaSalesReport.ReportContent = GenerateReport(otaSalesReport.UserName, otaSalesReport.StartDate.Value, otaSalesReport.EndDate.Value);
                db.OtaSalesReport.Add(otaSalesReport);
                db.SaveChanges();
                //生成周报的时候,要同时生成相应的报表统计图表存放到对应的id的文件夹里面
                SavePersonCompanyTicketChart(otaSalesReport.UserName, otaSalesReport.ID, otaSalesReport.StartDate.Value, otaSalesReport.EndDate.Value);

                return(RedirectToAction("Edit", new { id = otaSalesReport.ID }));
            }

            return(View(otaSalesReport));
        }
Ejemplo n.º 5
0
        public ActionResult Create()
        {
            var model = new OtaSalesReport();

            model.CreateTime = DateTime.Now;

            DateTime startWeek = DateTime.Now.AddDays(1 - Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d")));
            DateTime endWeek   = startWeek.AddDays(6);

            model.StartDate = startWeek;
            model.EndDate   = endWeek;

            model.ReportContent = "";

            var Db   = new ApplicationDbContext();
            var user = Db.Users.First(u => u.UserName == User.Identity.Name);

            model.SendToEmails = user.Email;
            model.ReportTitle  = "销售周报-" + user.TrueName + "-" + model.StartDate.Value.ToString("yyyyMMdd") + "-" + model.EndDate.Value.ToString("yyyyMMdd");

            model.UserName = User.Identity.Name;

            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult SendEmail(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OtaSalesReport otaSalesReport = db.OtaSalesReport.Find(id);

            if (otaSalesReport == null)
            {
                return(HttpNotFound());
            }
            //發送email
            #region 发送邮件
            //填写电子邮件地址,和显示名称
            System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("*****@*****.**", "ljy");
            //填写邮件的收件人地址和名称
            System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress(otaSalesReport.SendToEmails, otaSalesReport.UserName);
            //设置好发送地址,和接收地址,接收地址可以是多个

            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.Priority = MailPriority.Normal;
            mail.From     = from;
            mail.To.Add(to);
            mail.Subject         = otaSalesReport.ReportTitle;
            mail.SubjectEncoding = Encoding.GetEncoding(936); //这里非常重要,如果你的邮件标题包含中文,这里一定要指定,否则对方收到的极有可能是乱码。
            mail.IsBodyHtml      = true;                      //设置显示htmls
            mail.BodyEncoding    = Encoding.GetEncoding(936); //邮件正文的编码, 设置不正确, 接收者会收到乱码

            string htmlHead = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><style>body {font-size: 9pt;}table {border: 1px;padding: 0;border-collapse: collapse;border: none;}th {border: solid windowtext 1.0pt;background: #BFBFBF;padding: 3px;font-size: 10pt;font-weight: bold;margin:8px;}td {border: solid windowtext 1.0pt;border-top: none;font-size: 10pt;padding: 8px;}</style></head><body><div>";
            string htmlEnd  = "</div></body></html>";

            string Themessage = htmlHead;
            //Add Image,多张图片需要循环
            var      path     = "~/CompanyImages/Reports/" + id.ToString();
            var      imgpath  = Server.MapPath(path);
            string[] imgFiles = GetAllFileName(imgpath);
            foreach (string imgFile in imgFiles)
            {
                string imgHtml = "<img src='cid:" + imgFile.Replace(".jpg", "") + "' /><br><br>";
                Themessage += imgHtml;
            }
            Themessage += otaSalesReport.ReportContent + htmlEnd;

            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Themessage, null, "text/html");
            foreach (string imgFile in imgFiles)
            {
                LinkedResource theEmailImage = new LinkedResource(Path.Combine(imgpath, imgFile), MediaTypeNames.Image.Jpeg);
                theEmailImage.ContentId = imgFile.Replace(".jpg", "");
                htmlView.LinkedResources.Add(theEmailImage);
            }

            mail.AlternateViews.Add(htmlView);
            //设置好发送邮件服务地址
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.Host                  = "smtp.qq.com"; //这里发邮件用的是126,所以为"smtp.126.com"
            client.Port                  = 25;
            client.EnableSsl             = true;
            client.UseDefaultCredentials = true;

            //填写服务器地址相关的用户名和密码信息
            client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "cpkehayuptjibgbc");
            //发送邮件
            client.Send(mail);

            #endregion
            ViewBag.Message = "发送成功.";
            return(RedirectToAction("Index"));
        }