Beispiel #1
0
        public void Update(ContactsBAL obj)
        {
            try
            {
                //Local

                con.Open();
                cmd.Connection  = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Contacts_Update";
                cmd.Parameters.Clear();

                cmd.Parameters.Add("@cnt_id", SqlDbType.Int).Value            = obj.cnt_id;
                cmd.Parameters.Add("@cnt_FirstName", SqlDbType.VarChar).Value = obj.cnt_FirstName;
                cmd.Parameters.Add("@cnt_LastName", SqlDbType.VarChar).Value  = obj.cnt_LastName;
                cmd.Parameters.Add("@cnt_Number", SqlDbType.VarChar).Value    = obj.cnt_Number;
                cmd.Parameters.Add("@status", SqlDbType.Bit).Value            = obj.status;
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (SqlException e1)
            {
                MessageBox.Show(e1.Message, "SQL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void FillGridViewContact()
        {
            ContactsBAL balContact = new ContactsBAL();
            DataTable   dtContact  = new DataTable();

            dtContact = balContact.SelectAll();
            if (dtContact != null && dtContact.Rows.Count > 0)
            {
                gvContactList.DataSource = dtContact;
                gvContactList.DataBind();
            }
        }
 protected void gvContactList_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandArgument != null)
     {
         ContactsBAL balContact = new ContactsBAL();
         if (balContact.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim())))
         {
             Response.Redirect("~/Adminpanel/Contact/ContactList.aspx");
             lblError.Text = "";
         }
         else
         {
             lblError.Text = balContact.Message;
         }
     }
 }
Beispiel #4
0
        public List <ContactsBAL> Search(ContactsBAL obj)
        {
            try
            {
                //Local

                SqlDataReader      dr;
                List <ContactsBAL> listt = new List <ContactsBAL>();
                con.Open();
                cmd.Connection  = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Contacts_Search";
                cmd.Parameters.Clear();

                cmd.Parameters.Add("@cnt_id", SqlDbType.Int).Value            = obj.cnt_id;
                cmd.Parameters.Add("@cnt_FirstName", SqlDbType.VarChar).Value = obj.cnt_FirstName;
                cmd.Parameters.Add("@cnt_LastName", SqlDbType.VarChar).Value  = obj.cnt_LastName;
                cmd.Parameters.Add("@cnt_Number", SqlDbType.VarChar).Value    = obj.cnt_Number;
                cmd.Parameters.Add("@status", SqlDbType.Bit).Value            = obj.status;
                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        ContactsBAL obj1 = new ContactsBAL();
                        float       x    = 0;                obj1.cnt_id = Convert.ToInt32(dr["cnt_id"].ToString());
                        obj1.cnt_FirstName = dr["cnt_FirstName"].ToString();
                        obj1.cnt_LastName  = dr["cnt_LastName"].ToString();
                        obj1.cnt_Number    = dr["cnt_Number"].ToString();
                        obj1.status        = (bool)dr["status"];
                        listt.Add(obj1);
                    }
                }
                dr.Close();
                con.Close();
                return(listt);
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.Message, "SQL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(null);
        }
Beispiel #5
0
 public void Save()
 {
     if (Validate_txt_firstname() && Validate_txt_LastName() && ValidatephoneNo())
     {
         ContactsBAL contact = new ContactsBAL();
         contact.cnt_id        = id;
         contact.cnt_FirstName = txt_firstname.Text;
         contact.cnt_LastName  = txt_LastName.Text;
         contact.cnt_Number    = txt_Number.Text;
         contact.status        = true;
         if (contact.cnt_id == 0)
         {
             db.Add(contact);
         }
         else
         {
             db.Update(contact);
         }
         LoadPhonebook();
         Clear();
     }
 }
Beispiel #6
0
        public List <ContactsBAL> LoadAll_SQLQuery(string query)
        {
            try
            {
                //Local

                SqlDataReader      dr;
                List <ContactsBAL> listt = new List <ContactsBAL>();
                con.Open();
                cmd.Connection  = con;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "query";


                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        ContactsBAL obj1 = new ContactsBAL();
                        float       x    = 0;                obj1.cnt_id = Convert.ToInt32(dr["cnt_id"].ToString());
                        obj1.cnt_FirstName = dr["cnt_FirstName"].ToString();
                        obj1.cnt_LastName  = dr["cnt_LastName"].ToString();
                        obj1.cnt_Number    = dr["cnt_Number"].ToString();
                        obj1.status        = (bool)dr["status"];
                        listt.Add(obj1);
                    }
                }
                dr.Close();
                con.Close();
                return(listt);
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.Message, "SQL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(null);
        }
Beispiel #7
0
        public ContactsBAL LoadbyId(int obj)
        {
            try
            {
                //Local

                SqlDataReader dr;
                con.Open();
                cmd.Connection  = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Contacts_LOADByID";
                cmd.Parameters.Clear();

                cmd.Parameters.Add("@cnt_id", SqlDbType.Int).Value = obj;
                dr = cmd.ExecuteReader();
                ContactsBAL obj1 = new ContactsBAL();                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        float x = 0;                obj1.cnt_id = Convert.ToInt32(dr["cnt_id"].ToString());
                        obj1.cnt_FirstName = dr["cnt_FirstName"].ToString();
                        obj1.cnt_LastName  = dr["cnt_LastName"].ToString();
                        obj1.cnt_Number    = dr["cnt_Number"].ToString();
                        obj1.status        = (bool)dr["status"];
                    }
                }
                dr.Close();
                con.Close();
                return(obj1);
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.Message, "SQL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(null);
        }
Beispiel #8
0
 public ContactController(IHostingEnvironment hostingEnvironment)
 {
     contactsBal = new ContactsBAL(hostingEnvironment);
 }
Beispiel #9
0
        private void fillControls(SqlInt32 ContactID)
        {
            ContactsENT entContact = new ContactsENT();
            ContactsBAL balContact = new ContactsBAL();

            entContact = balContact.SelectByPK(ContactID);
            if (entContact != null)
            {
                if (!entContact.PersonName.IsNull)
                {
                    txtPersonName.Text = entContact.PersonName.Value.ToString();
                }
                if (!entContact.Pincode.IsNull)
                {
                    txtPincode.Text = entContact.Pincode.Value.ToString();
                }
                if (!entContact.MobileNo.IsNull)
                {
                    txtMobileNo.Text = entContact.MobileNo.Value.ToString();
                }
                if (!entContact.Address.IsNull)
                {
                    txtAddress.Text = entContact.Address.Value.ToString();
                }
                if (!entContact.Email.IsNull)
                {
                    txtEmail.Text = entContact.Email.Value.ToString();
                }
                if (!entContact.PhoneNo.IsNull)
                {
                    txtPhoneNo.Text = entContact.PhoneNo.Value.ToString();
                }
                if (!entContact.Profession.IsNull)
                {
                    txtProfession.Text = entContact.Profession.Value.ToString();
                }
                if (!entContact.StateID.IsNull)
                {
                    ddlState.SelectedValue = entContact.StateID.Value.ToString();
                }
                if (!entContact.CityID.IsNull)
                {
                    ddlCity.SelectedValue = entContact.CityID.Value.ToString();
                }
                if (!entContact.CountryID.IsNull)
                {
                    ddlCountry.SelectedValue = entContact.CountryID.Value.ToString();
                }
                if (!entContact.ContactCategoryID.IsNull)
                {
                    ddlContactCategory.SelectedValue = entContact.ContactCategoryID.Value.ToString();
                }
                if (!entContact.BloodGroupID.IsNull)
                {
                    ddlBloodGroup.SelectedValue = entContact.BloodGroupID.Value.ToString();
                }
                if (!entContact.Gender.IsNull)
                {
                    ddlGender.SelectedValue = entContact.Gender.Value.ToString();
                }
                if (!entContact.BirthDate.IsNull)
                {
                    txtBirthDate.Text = DateTime.Parse(entContact.BirthDate.ToString()).ToString("yyyy-MM-dd");
                }
            }
            else
            {
                lblError.Text = balContact.Message;
            }
        }
Beispiel #10
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region Server Side Validation

            lblError.Text = "";
            if (txtPersonName.Text.Trim().ToUpper() == "")
            {
                lblError.Text += "Enter Contact Name <br/>";
            }

            if (txtMobileNo.Text.Trim() == "")
            {
                lblError.Text += "Enter Mobile No <br/>";
            }

            if (ddlBloodGroup.SelectedValue == "-1")
            {
                lblError.Text += "Please Select Bloodgroup <br/>";
            }

            if (ddlContactCategory.SelectedValue == "-1")
            {
                lblError.Text += "Please Select Contact Category <br/>";
            }


            if (lblError.Text != "")
            {
                return;
            }
            #endregion Server Side Validation

            #region Collecting Data
            ContactsENT entContact = new ContactsENT();
            if (ddlBloodGroup.SelectedValue != "-1" && ddlContactCategory.SelectedValue != "-1" && txtPersonName.Text.Trim().ToUpper() != "" && txtMobileNo.Text.Trim() != "")
            {
                entContact.PersonName        = txtPersonName.Text.Trim().ToUpper();
                entContact.MobileNo          = txtMobileNo.Text.Trim();
                entContact.BloodGroupID      = Convert.ToInt32(ddlBloodGroup.SelectedValue);
                entContact.ContactCategoryID = Convert.ToInt32(ddlContactCategory.SelectedValue);
            }
            #region Reading Remaining Data

            if (txtAddress.Text.Trim().ToUpper() != "")
            {
                entContact.Address = txtAddress.Text.Trim().ToUpper();
            }

            if (txtPincode.Text.Trim() != "")
            {
                entContact.Pincode = txtPincode.Text.Trim();
            }

            if (txtEmail.Text.Trim().ToLower() != "")
            {
                entContact.Email = txtEmail.Text.Trim().ToLower();
            }

            if (txtPhoneNo.Text.Trim() != "")
            {
                entContact.PhoneNo = txtPhoneNo.Text.Trim();
            }

            if (txtProfession.Text.Trim().ToUpper() != "")
            {
                entContact.Profession = txtProfession.Text.Trim().ToUpper();
            }

            if (txtBirthDate.Text.Trim() != "")
            {
                if (DateTime.Parse(txtBirthDate.Text.Trim()) <= DateTime.Now)
                {
                    entContact.BirthDate = SqlDateTime.Parse(txtBirthDate.Text.Trim());
                }
                else
                {
                    lblError.Text += "Invalid Birthdate";
                    return;
                }
            }

            if (!entContact.BirthDate.IsNull)
            {
                entContact.Age = (DateTime.Now.Subtract(DateTime.Parse(entContact.BirthDate.ToString())).Days / 365);
            }

            if (ddlCity.SelectedValue != "-1")
            {
                entContact.CityID = Convert.ToInt32(ddlCity.SelectedValue);
            }

            if (ddlState.SelectedValue != "-1")
            {
                entContact.StateID = Convert.ToInt32(ddlState.SelectedValue);
            }

            if (ddlCountry.SelectedValue != "-1")
            {
                entContact.CountryID = Convert.ToInt32(ddlCountry.SelectedValue);
            }

            if (ddlGender.SelectedValue != "-1")
            {
                entContact.Gender = ddlGender.SelectedValue;
            }


            #endregion Reading Remaining Data

            #endregion Collecting Data
            ContactsBAL balContact = new ContactsBAL();
            if (Request.QueryString["ContactID"] == null)
            {
                #region insertingData
                if (balContact.Insert(entContact))
                {
                    Response.Redirect("~/AdminPanel/Contact/ContactList.aspx");
                }
                else
                {
                    lblError.Text = balContact.Message;
                }
                #endregion insertingData
            }
            else
            {
                #region updatingData
                entContact.ContactID = Convert.ToInt32(Request.QueryString["ContactID"]);
                if (balContact.Update(entContact))
                {
                    Response.Redirect("~/AdminPanel/Contact/ContactList.aspx");
                }
                else
                {
                    lblError.Text = balContact.Message;
                }
                #endregion updatingData
            }
        }