Example #1
0
        protected void btnEmail_Click(object sender, EventArgs e)
        {
            try
            {
                string checkedRequiredField = "";
                DataTable dt = new DataTable();
                string subject = "";
                string fileName = "";
                string body = "";
                Boolean isSubjectYM = false;
                Boolean isFileNameYM = false;
                errorList = new CustomList<ErrorList>();
                MailSetupManager manager = new MailSetupManager();
                CustomList<MailSetup> mailSetup = manager.GetAllMailSetup(Convert.ToInt32(Session["ReportID"]));
                MailSetup mS = mailSetup.Find(f => f.Subject.IsNotNullOrEmpty());
                if (mS.IsNull())
                {
                    return;
                }
                else
                {
                    subject = mS.Subject;
                    fileName = mS.FileName;
                    body = mS.Body;
                    isSubjectYM = mS.IsSubjectYM;
                    isFileNameYM = mS.IsFileNameYM;
                }
                #region
                if (isSubjectYM)
                {
                    FilterSets month = FilterSetList.Find(f => f.ColumnName == "MonthNo");
                    FilterSets year = FilterSetList.Find(f => f.ColumnName == "YearNo");
                    string monthYearName = "";
                    if (month.IsNotNull())
                        monthYearName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month.ColumnActualValue.ToInt()).Substring(0, 3) + "' " + year.ColumnActualValue.Substring(2, 2);

                    if (monthYearName == "")
                    {
                        FilterSets fromDate = FilterSetList.Find(f => f.ColumnName == "FromDate");
                        if (fromDate.IsNotNull())
                            monthYearName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(fromDate.ColumnValue.Substring(0, 2).ToInt()).Substring(0, 3) + "' " + fromDate.ColumnValue.Substring(8, 2);

                    }
                    if (monthYearName == "")
                    {
                        FilterSets workDate = FilterSetList.Find(f => f.ColumnName == "Workdate");
                        if (workDate.IsNotNull())
                            monthYearName = Convert.ToDateTime(workDate.ColumnValue).ToString("dd MMM yy");

                    }
                    subject = subject + "_" + monthYearName;
                }
                if (isFileNameYM)
                {
                    FilterSets month = FilterSetList.Find(f => f.ColumnName == "MonthNo");
                    FilterSets year = FilterSetList.Find(f => f.ColumnName == "YearNo");
                    string monthYearName = "";
                    if (month.IsNotNull())
                        monthYearName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month.ColumnActualValue.ToInt()).Substring(0, 3) + "' " + year.ColumnActualValue.Substring(2, 2);

                    if (monthYearName == "")
                    {
                        FilterSets fromDate = FilterSetList.Find(f => f.ColumnName == "FromDate");
                        if (fromDate.IsNotNull())
                            monthYearName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(fromDate.ColumnValue.Substring(0, 2).ToInt()).Substring(0, 3) + "' " + fromDate.ColumnValue.Substring(8, 2);

                    }
                    if (monthYearName == "")
                    {
                        FilterSets workDate = FilterSetList.Find(f => f.ColumnName == "Workdate");
                        if (workDate.IsNotNull())
                            monthYearName = Convert.ToDateTime(workDate.ColumnValue).ToString("dd MMM yy");

                    }
                    fileName = fileName + "_" + monthYearName;
                }
                string reportPath = Session["reportPath"].ToString();
                DataTable dt1 = new DataTable();
                if (!mS.IsIndividual)
                Report.LoadSourceDataSet(ref checkedRequiredField, ref dt1);
                FilterSets empCode = FilterSetList.Find(f => f.ColumnName == "EmpCode");
                if (empCode.ColumnActualValue.IsNotNullOrEmpty())
                {
                    mailSetup = mailSetup.FindAll(f => f.EmpKey.ToString() == empCode.ColumnActualValue);
                }
                #endregion
                foreach (MailSetup m in mailSetup)
                {
                    //if (mS.IsIndividual)
                    //    Report.LoadSourceDataSet(m.EmpKey.ToString(), ref dt1);

                    //SentEmail sm = new SentEmail();
                    //string message = sm.EmailUtil(m.EmailAddress, reportPath, dt1, "", subject, fileName, body);
                    //if (message.IsNotNullOrEmpty())
                    //{
                    //    ErrorList eL = new ErrorList();
                    //    eL.EmpName = m.EmpName.Trim();
                    //    eL.Error = message;
                    //    errorList.Add(eL);
                    //}
                }
                ((PageBase)this.Page).SuccessMessage = "Mail sent successfully!";
            }
            catch (Exception ex)
            {
                ((PageBase)this.Page).ErrorMessage = (ExceptionHelper.getExceptionMessage(ex));
            }
        }
Example #2
0
        private void CheckAllSupervisor()
        {
            try
            {
                String response = String.Empty;

                MailSetupManager manager = new MailSetupManager();
                CustomList<MailSetup> EmailList = (CustomList<MailSetup>)HttpContext.Current.Session["MailSetup_MailSetupList"];
                CustomList<MailSetup> SupervisorList = manager.GetAllSupervisor();
                String isSupervisor = HttpContext.Current.Request.QueryString["IsSupervisor"];
                EmailList.ForEach(s => s.IsChecked = false);
                if (isSupervisor == "true")
                {
                    foreach (MailSetup mS in EmailList)
                    {
                        MailSetup objMailSetup = SupervisorList.Find(f => f.EmpKey == mS.EmpKey);
                        if (mS.EmailAddress.Trim().IsNotNullOrEmpty() && objMailSetup.IsNotNull())
                        {
                            mS.IsChecked = true;
                        }
                    }
                }

                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "text/plain";
                HttpContext.Current.Response.Write(response);
                HttpContext.Current.Response.Flush();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }