protected void gridView_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e)
 {
     try
     {
         using (SendMailEntities db = new SendMailEntities())
         {
             if (ContactBusiness.checkContactIsExist(e.NewValues["Email"].ToString().Trim()))
             {
                 Contact contact = new Contact();
                 contact.Email = e.NewValues["Email"].ToString().Trim();
                 db.Contacts.Add(contact);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#2
0
        protected void btnImportList_Click(object sender, EventArgs e)
        {
            try
            {
                List <Contact> lst_contact = new List <Contact>();
                string         FolderPath  = ConfigurationManager.AppSettings["FolderPath"];
                string         FileName    = txtNameFileUpload.Text;
                string         Extension   = Path.GetExtension(FileName);
                string         FilePath    = Server.MapPath(FolderPath + FileName);

                DataTable dt = ImportExcel.ImportExcel2DataTable(FilePath, Extension);

                checkBoxListEmail.DataSource = dt;
                checkBoxListEmail.DataMember = "Email";
                checkBoxListEmail.TextField  = "Email";
                checkBoxListEmail.DataBind();
                checkBoxListEmail.SelectAll();

                //check save contact new
                SelectedValueCollection listEmail = checkBoxListEmail.SelectedValues;
                foreach (String email in listEmail)
                {
                    if (!ContactBusiness.checkContactIsExist(email) && email != "")
                    {
                        Contact contact = new Contact();
                        contact.Email = email;
                        lst_contact.Add(contact);
                    }
                }

                using (SendMailEntities db = new SendMailEntities())
                {
                    db.Contacts.AddRange(lst_contact);
                    db.SaveChanges();
                }
            }
            catch (Exception v_e)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + v_e + "');", true);
            }
        }
        protected void btnImportList_Click(object sender, EventArgs e)
        {
            try
            {
                //ListEditItem cmbEmailOwnselectedItem = cmbEmailOwn.SelectedItem;
                //ListEditItem cmbcmbCampaignselectedItem = cmbCampaign.SelectedItem;
                SendMailEntities     db          = new SendMailEntities();
                List <TempSendEmail> listTemp    = new List <TempSendEmail>();
                List <Contact>       lst_contact = new List <Contact>();

                string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
                string FileName   = txtNameFileUpload.Text;
                string Extension  = Path.GetExtension(FileName);
                string FilePath   = Server.MapPath(FolderPath + FileName);
                if (FileName != "")
                {
                    //delete data in table temporary
                    db.Database.ExecuteSqlCommand("Delete from TempSendEmails where IDUser = "******"STT"].ToString());
                        temp.Subject      = dr["Subject"].ToString();
                        temp.ContentEmail = dr["Content"].ToString();
                        temp.Email        = dr["Email"].ToString();
                        temp.IDUser       = mGlobal.UserID;
                        temp.TimeSend     = DateTime.Now;
                        //temp.IDEmailOwn = Int64.Parse(cmbEmailOwnselectedItem.GetValue("ID").ToString());
                        //if (cmbCampaign.SelectedIndex > 0)
                        //{
                        //       temp.IDCampaign = Int64.Parse(cmbcmbCampaignselectedItem.GetValue("CampaignID").ToString());
                        // }
                        listTemp.Add(temp);
                        //check contact, if is not exist then save to db
                        if (!ContactBusiness.checkContactIsExist(temp.Email))
                        {
                            Contact contact = new Contact();
                            contact.Email = temp.Email;
                            lst_contact.Add(contact);
                        }
                    }

                    db.TempSendEmails.AddRange(listTemp);
                    if (lst_contact.Count > 0)
                    {
                        db.Contacts.AddRange(lst_contact);
                    }
                    db.SaveChanges();
                    gridView.DataBind();
                }
                else
                {
                    String message = "Bạn chưa chọn file hoặc file này đang được mở!";
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + message + "');", true);
                }
            }
            catch (Exception v_e)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + v_e + "');", true);
                //Debugger.Log(1, "Send Mail", "Failed: " + v_e);
            }
        }
示例#4
0
        protected void btnImportList_Click(object sender, EventArgs e)
        {
            try
            {
                SendMailEntities db = new SendMailEntities();

                List <Contact> listContact = new List <Contact>();

                string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
                string FileName   = txtNameFileUpload.Text;
                string Extension  = Path.GetExtension(FileName);
                string FilePath   = Server.MapPath(FolderPath + FileName);
                if (FileName != "")
                {
                    DataTable dt = ImportExcel.ImportExcel2DataTable(FilePath, Extension);
                    foreach (DataRow dr in dt.Rows)
                    {
                        Contact contact;
                        if (!ContactBusiness.checkContactIsExist(dr["Email"].ToString().Trim()))
                        {
                            contact           = new Contact();
                            contact.Email     = dr["Email"].ToString().Trim();
                            contact.FirstName = dr["FirstName"].ToString();
                            contact.LastName  = dr["LastName"].ToString();
                            contact.FullName  = dr["FullName"].ToString();
                            contact.Phone     = dr["Phone"].ToString();
                            contact.Adress    = dr["Address"].ToString();
                            if (dr["Gender"].ToString().Trim().ToUpper().Equals("NỮ"))
                            {
                                contact.Gender = 0;
                            }
                            else
                            {
                                contact.Gender = 1;
                            }

                            contact.Birthday = DateTime.Parse(dr["Birthday"].ToString());
                            listContact.Add(contact);
                        }
                        else
                        {
                            contact           = db.Contacts.FirstOrDefault(x => x.Email == dr["Email"].ToString().Trim());
                            contact.Email     = dr["Email"].ToString().Trim();
                            contact.FirstName = dr["FirstName"].ToString();
                            contact.LastName  = dr["LastName"].ToString();
                            contact.FullName  = dr["FullName"].ToString();
                            contact.Phone     = dr["Phone"].ToString();
                            contact.Adress    = dr["Address"].ToString();
                            if (dr["Gender"].ToString().Trim().ToUpper().Equals("NỮ"))
                            {
                                contact.Gender = 0;
                            }
                            else
                            {
                                contact.Gender = 1;
                            }

                            contact.Birthday = DateTime.Parse(dr["Birthday"].ToString());
                        }
                    }
                    if (listContact.Count > 0)
                    {
                        db.Contacts.AddRange(listContact);
                    }

                    db.SaveChanges();
                    gridView.DataBind();
                }
                else
                {
                    String message = "Bạn chưa chọn file hoặc file này đang được mở!";
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + message + "');", true);
                }
            }
            catch (Exception v_e)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + HandleException.SqlExcforContact(v_e) + "');", true);
                Debugger.Log(1, "Send Mail", "Failed: " + v_e);
            }
        }