示例#1
0
    protected void CallbackControl_Callback(object sender, CallbackEventArgs e)
    {
        var args = e.Parameter.Split('|');

        if (args[0] == "Edit" && args.Length == 2)
        {
            int id;
            if (!int.TryParse(args[1], out id))
            {
                e.Result = "NotFound";
                return;
            }
            ContactsBL bl       = new ContactsBL();
            var        Contacts = bl.GetAllContacts("");
            var        contact  = Contacts.FirstOrDefault(c => c.ID == id);
            if (contact == null)
            {
                e.Result = "NotFound";
                return;
            }
            var dict = new Dictionary <string, object>();
            dict["Name"]     = contact.Name;
            dict["Email"]    = contact.Email;
            dict["Address"]  = contact.Address;
            dict["City"]     = contact.City;
            dict["Country"]  = contact.Country;
            dict["Phone"]    = contact.Phone;
            dict["ImageUrl"] = Utils.GetContactPhotoUrl(contact.PhotoUrl);

            CallbackControl.JSProperties["cpContact"] = dict;
            e.Result = "Edit";
        }
    }
示例#2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                string errMsg = ValidateForm();

                if (errMsg != string.Empty)
                {
                    MessageBox.Show(errMsg);
                }
                else
                {
                    ContactsBL contactsBL = new ContactsBL();
                    populateContact();

                    if (contactsBL.UpdateContact(contact) == true)
                    {
                        PopulateDGV();
                        MessageBox.Show("Contact update successful");
                    }
                    else
                    {
                        MessageBox.Show("Contact update failed");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
 protected void MailGrid_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
 {
     if (e.Column.FieldName == "Subject" && (bool)e.GetFieldValue("IsReply"))
     {
         e.DisplayText = "Re: " + HttpUtility.HtmlEncode(e.Value);
     }
     if (e.Column.FieldName == "To")
     {
         var list = new List <string>();
         foreach (var item in e.Value.ToString().Split(','))
         {
             var        email    = item.Trim();
             ContactsBL bl       = new ContactsBL();
             var        Contacts = bl.GetAllContacts(User.Identity.Name);
             var        contact  = Contacts.FirstOrDefault(c => c.Email == email);
             list.Add(contact != null ? contact.Name : email);
         }
         e.DisplayText = string.Join(", ", list);
     }
     if (e.Column.FieldName == "From")
     {
         var        from     = e.Value.ToString();
         ContactsBL bl       = new ContactsBL();
         var        Contacts = bl.GetAllContacts(User.Identity.Name);
         var        contact  = Contacts.FirstOrDefault(c => c.Email == from);
         e.DisplayText = contact != null ? contact.Name : from;
     }
     if (!string.IsNullOrEmpty(SearchText) && (e.Column.FieldName == "From" || e.Column.FieldName == "To" || e.Column.FieldName == "Subject"))
     {
         string text = string.IsNullOrEmpty(e.DisplayText) ? e.Value.ToString() : e.DisplayText;
         e.DisplayText = new Regex(SearchText, RegexOptions.IgnoreCase).Replace(text, "<span class='hgl'>$0</span>");
     }
 }
示例#4
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                ContactsBL contactsBL = new ContactsBL();
                int        id         = int.Parse(ddlContacts.SelectedValue);
                if (contactsBL.DeleteContact(id) == true)
                {
                    PopulateDDL();
                    ClearForm();
                    lblMessage.Text = "Contact deletion successful";
                }
                else
                {
                    lblMessage.Text = "Contact deletion failed";

                    foreach (ValidationError ve in contactsBL.ValidationErrors)
                    {
                        lblMessage.Text = ve.Description.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
示例#5
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                string errMsg = ValidateForm();

                if (errMsg != string.Empty)
                {
                    lblMessage.Text = errMsg;
                }
                else
                {
                    ContactsBL contactsBL = new ContactsBL();
                    populateContact();
                    if (contactsBL.CreateContact(contact) == true)
                    {
                        PopulateDDL();
                        lblMessage.Text = "Contact creation successful";
                    }
                    else
                    {
                        lblMessage.Text = "Contact creation failed";

                        foreach (ValidationError ve in contactsBL.ValidationErrors)
                        {
                            lblMessage.Text = ve.Description.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
示例#6
0
    protected void ContactCountryEditor_Load(object sender, EventArgs e)
    {
        if (ContactFormPanel.IsCallback || IsPostBack && !IsCallback)
        {
            var        combo = (ASPxComboBox)sender;
            ContactsBL BL    = new ContactsBL();
            combo.DataSource = BL.GetCountries();
            combo.DataBindItems();
        }

        ContactDataView.ContentStyle.Border.BorderWidth = 0;
    }
示例#7
0
    protected void ContactCityEditor_Callback(object sender, CallbackEventArgsBase e)
    {
        if (string.IsNullOrEmpty(e.Parameter))
        {
            return;
        }
        var        combo = (ASPxComboBox)sender;
        ContactsBL bl    = new ContactsBL();

        combo.DataSource = bl.GetCities(e.Parameter);
        combo.DataBindItems();
    }
示例#8
0
 private void PopulateDGV()
 {
     try
     {
         ContactsBL contactsBL = new ContactsBL();
         dataGridView1.DataSource = contactsBL.GetListOfContacts();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#9
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         ContactsBL contactsBL = new ContactsBL();
         int        rowindex   = dataGridView1.CurrentCell.RowIndex;
         int        id         = int.Parse(dataGridView1.Rows[rowindex].Cells["ContactID"].Value.ToString());
         contact = contactsBL.GetContact(id);
         populateForm();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#10
0
 protected void ddlContacts_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         ContactsBL contactsBL = new ContactsBL();
         int        id         = int.Parse(ddlContacts.SelectedValue);
         contact = contactsBL.GetContact(id);
         populateForm();
         lblMessage.Text = "";
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
     }
 }
示例#11
0
 private void PopulateDDL()
 {
     try
     {
         ContactsBL contactsBL = new ContactsBL();
         ddlContacts.DataSource     = contactsBL.GetListOfContacts();
         ddlContacts.DataValueField = "ContactID";
         ddlContacts.DataTextField  = "FirstName";
         ddlContacts.DataBind();
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
     }
 }
示例#12
0
    protected IEnumerable GetContacts()
    {
        ContactsBL bl       = new ContactsBL();
        var        contacts = bl.GetAllContacts("").AsEnumerable();

        if (!ShowAllContacts)
        {
            var showOnlyPersonal = ShowOnlyPersonalAddresses;
            contacts = contacts.Where(c => !object.Equals(c.Collected, showOnlyPersonal));
        }
        return(contacts.Select(c => new {
            PhotoUrl = "~/" + Utils.GetContactPhotoUrl(c.PhotoUrl),
            Name = c.Name,
            Email = c.Email,
            Address = Utils.GetAddressString(c),
            Phone = c.Phone
        }));
    }
示例#13
0
    protected void ContactDataView_CustomCallback(object sender, CallbackEventArgsBase e)
    {
        if (string.IsNullOrEmpty(e.Parameter))
        {
            return;
        }
        var args = e.Parameter.Split('|');

        if (args[0] == "Delete" && args.Length == 2)
        {
            int id;
            if (!int.TryParse(args[1], out id))
            {
                return;
            }
            ContactsBL bl = new ContactsBL();
            bl.DeleteContact(id);
            BindDataView();
        }
        if (args[0] == "SaveContact")
        {
            var name     = ContactNameEditor.Text;
            var email    = ContactEmailEditor.Text;
            var address  = ContactAddressEditor.Text;
            var country  = ContactCountryEditor.Text;
            var city     = ContactCityEditor.Text;
            var phone    = ContactPhoneEditor.Text;
            var photoUrl = Utils.GetUploadedPhotoUrl(args[2]);
            int id;
            if (args.Length == 4 && args[1] == "Edit" && int.TryParse(args[3], out id))
            {
                ContactsBL bl = new ContactsBL();
                bl.UpdateContact(id, name, email, address, country, city, phone, photoUrl);
            }
            else if (args.Length == 3 && args[1] == "New")
            {
                ContactsBL bl = new ContactsBL();
                bl.AddContact(name, email, address, country, city, photoUrl, photoUrl);
            }

            BindDataView();
        }
    }
示例#14
0
    List <Contact> SelectContacts()
    {
        ContactsBL bl       = new ContactsBL();
        var        Contacts = bl.GetAllContacts("");
        var        result   = Contacts.AsQueryable();
        var        showCollectedAdresses = Convert.ToInt32(FindAddressBookList().Value) == 1;

        result = result.Where(c => object.Equals(c.Collected, showCollectedAdresses));

        if (!string.IsNullOrEmpty(SearchText))
        {
            var text = SearchText.ToLower();
            result = result.Where(c => c.Name.ToLower().Contains(text) || Utils.GetAddressString(c).ToLower().Contains(text));
        }
        var sortedFieldName = FindSortByCombo().Value.ToString();
        var isDescending    = Convert.ToInt32(FindSortDirectionCombo().Value) == 1;

        result = Utils.MakeContactsOrderBy(result, sortedFieldName, isDescending);
        return(result.ToList());
    }
示例#15
0
    protected void Page_Load(object s, EventArgs e)
    {
        if (ShouldBindGrid())
        {
            BindGrid();
        }
        if (MailFormPanel.IsCallback || IsPostBack && !IsCallback)
        {
            ContactsBL bl       = new ContactsBL();
            var        Contacts = bl.GetAllContacts(User.Identity.Name);
            AddressesList.DataSource = Contacts.Select(c => new {
                Text     = c.Name,
                Value    = c.Email,
                ImageUrl = Utils.GetContactPhotoUrl(c.PhotoUrl)
            });
            AddressesList.DataBind();
        }

        MailGrid.DataColumns["To"].Visible   = ShowToColumn();
        MailGrid.DataColumns["From"].Visible = !ShowToColumn();
    }
示例#16
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                string errMsg = ValidateForm();

                if (errMsg != string.Empty)
                {
                    lblMessage.Text = errMsg;
                }
                else
                {
                    ContactsBL contactsBL = new ContactsBL();
                    populateContact();
                    if (Session["Timestamp"] != null)
                    {
                        contact.TimeStamp = (byte[])Session["Timestamp"];
                    }

                    if (contactsBL.UpdateContact(contact) == true)
                    {
                        PopulateDDL();
                        lblMessage.Text = "Contact update successful";
                    }
                    else
                    {
                        lblMessage.Text = "Contact update failed";

                        foreach (ValidationError ve in contactsBL.ValidationErrors)
                        {
                            lblMessage.Text = ve.Description.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
示例#17
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         ContactsBL contactsBL = new ContactsBL();
         int        id         = int.Parse(txtContactID.Text);
         if (contactsBL.DeleteContact(id) == true)
         {
             PopulateDGV();
             ClearForm();
             MessageBox.Show("Contact deletion successful");
         }
         else
         {
             MessageBox.Show("Contact deletion failed");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }