using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class Prospect : System.Web.UI.Page { Page p = new Page(); protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { if (Session["Bulkmail"] == null) { Response.Redirect("BulkmailLogin.aspx"); } try { p = this.Page; ModCommon.CancelClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); enable(false); ModCommon.Fill_Combo("Select Category_Kid, Category_Name from BEM_Category", ddlCategory); fillcountry(); tr2.Visible = false; txtPinCode.Attributes.Add("onkeypress", "return CheckNumericValue(event);"); txtCountryMobile.Attributes.Add("onkeypress", "return CheckNumericValue(event);"); txtCountryPhone.Attributes.Add("onkeypress", "return CheckNumericValue(event);"); txtCityPhone.Attributes.Add("onkeypress", "return CheckNumericValue(event);"); txtPhoneNo.Attributes.Add("onkeypress", "return CheckNumericValue(event);"); txtMobileNo.Attributes.Add("onkeypress", "return CheckNumericValue(event);"); btnAdd.Focus(); btnDelete.Attributes.Add("onclick", "return FunctDelete();"); fillgrid(); } catch { } } lblMsg.Visible = false; } public void fillgrid() { try { DataTable dt = new DataTable(); dt = ModCommon.ReturnDataTable("SELECT City_Master.City_Name, State_Master.State_Name, Country_Master.Country_Name, BEM_Category.Category_Name, BEM_Prospect_Detail.prospect_KID, BEM_Prospect_Detail.ContactPerson, BEM_Prospect_Detail.CompanyName, BEM_Prospect_Detail.Address, BEM_Prospect_Detail.Pin, BEM_Prospect_Detail.Website, BEM_Prospect_Detail.Email, BEM_Prospect_Detail.AlternateEmail, BEM_Prospect_Detail.MobileNoCountrycode, BEM_Prospect_Detail.MobileNo, BEM_Prospect_Detail.PhoneNoCountryCode, BEM_Prospect_Detail.PhoneNoCityCode, BEM_Prospect_Detail.PhoneNo, BEM_Prospect_Detail.Products, BEM_Prospect_Detail.AdditionalInfo FROM BEM_Prospect_Detail LEFT OUTER JOIN BEM_Category ON BEM_Prospect_Detail.Categoryid = BEM_Category.Category_KId LEFT OUTER JOIN City_Master ON BEM_Prospect_Detail.CityID = City_Master.City_Kid LEFT OUTER JOIN State_Master ON BEM_Prospect_Detail.StateID = State_Master.State_Kid LEFT OUTER JOIN Country_Master ON BEM_Prospect_Detail.CountryID = Country_Master.Country_Kid"); GridView1.DataSource = dt; GridView1.DataBind(); dt.Clear(); } catch { } } protected void fillcountry() { try { ddlCountry.Items.Clear(); ModCommon.Fill_Combo("Select Country_Kid, Country_Name From Country_Master where Country_Isdeleted ='0'", ddlCountry); ddlCountry.Items.FindByText("India").Selected = true; ddlState.Items.Clear(); ModCommon.Fill_Combo("Select State_Kid, State_Name From State_Master where State_CountryID ='" + ddlCountry.SelectedItem.Value + "'and State_Isdeleted ='0'", ddlState); ddlCity.Items.Clear(); ddlCity.Items.Add("Select"); txtCountryPhone.Text = ModCommon.ReturnValue("Select Country_ISDCode from country_master where Country_Kid ='" + ddlCountry.SelectedItem.Value + "'"); txtCountryMobile.Text = ModCommon.ReturnValue("Select Country_ISDCode from country_master where Country_Kid ='" + ddlCountry.SelectedItem.Value + "'"); } catch { } } protected void Clear() { ddlCategory.ClearSelection(); fillcountry(); txtAccountInfo.Text = ""; txtAddress.Text = ""; txtAEmail.Text = ""; txtCompanyName.Text = ""; txtContactPerson.Text = ""; txtEmail.Text = ""; txtMobileNo.Text = ""; txtPhoneNo.Text = ""; txtPinCode.Text = ""; txtProducts.Text = ""; txtCityPhone.Text = ""; txtWebSite.Text = ""; } protected void enable(Boolean action) { ddlCategory.Enabled = action; ddlCity.Enabled = action; ddlCountry.Enabled = action; ddlState.Enabled = action; txtAccountInfo.Enabled = action; txtAddress.Enabled = action; txtAEmail.Enabled = action; txtCompanyName.Enabled = action; txtContactPerson.Enabled = action; txtEmail.Enabled = action; txtMobileNo.Enabled = action; txtPhoneNo.Enabled = action; txtPinCode.Enabled = action; txtProducts.Enabled = action; txtCountryPhone.Enabled = action; txtCountryMobile.Enabled = action; txtCityPhone.Enabled = action; txtWebSite.Enabled = action; } protected void btnAdd_Click(object sender, EventArgs e) { try { ddlCategory.Focus(); Clear(); enable(true); ModCommon.AddClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); } catch { } } protected void btnSave_Click(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "BEM_Prospect_Detail_Proc"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = con; cmd.Parameters.Add("Prospect_Kid", SqlDbType.NVarChar, 10).Value = ModCommon.NewPrimaryKey(p); cmd.Parameters.Add("Prospect_Code", SqlDbType.NVarChar, 25).Value = CommonData.Generate_Code("select count(*) from BEM_Prospect_Detail where Prospect_Code='", "BPC"); cmd.Parameters.Add("Categoryid", SqlDbType.NVarChar, 10).Value = ddlCategory.SelectedItem.Value; cmd.Parameters.Add("ContactPerson", SqlDbType.NVarChar, 150).Value = txtContactPerson.Text; cmd.Parameters.Add("CompanyName", SqlDbType.NVarChar, 150).Value = txtCompanyName.Text; cmd.Parameters.Add("Address", SqlDbType.NVarChar, 150).Value = txtAddress.Text; cmd.Parameters.Add("Pin", SqlDbType.NVarChar, 10).Value = txtPinCode.Text; cmd.Parameters.Add("CityID", SqlDbType.NVarChar, 10).Value = ddlCity.SelectedItem.Value; cmd.Parameters.Add("StateID", SqlDbType.NVarChar, 10).Value = ddlState.SelectedItem.Value; cmd.Parameters.Add("CountryID", SqlDbType.NVarChar, 10).Value = ddlCountry.SelectedItem.Value; cmd.Parameters.Add("Website", SqlDbType.NVarChar, 150).Value = txtWebSite.Text; cmd.Parameters.Add("Email", SqlDbType.NVarChar, 150).Value = txtEmail.Text; cmd.Parameters.Add("AlternateEmail", SqlDbType.NVarChar, 150).Value = txtAEmail.Text; cmd.Parameters.Add("MobileNoCountrycode", SqlDbType.NVarChar, 10).Value = txtCountryMobile.Text; cmd.Parameters.Add("MobileNo", SqlDbType.NVarChar, 10).Value = txtMobileNo.Text; cmd.Parameters.Add("PhoneNoCountryCode", SqlDbType.NVarChar, 10).Value = txtCountryPhone.Text; cmd.Parameters.Add("PhoneNoCityCode", SqlDbType.NVarChar, 10).Value = txtCityPhone.Text; cmd.Parameters.Add("PhoneNo", SqlDbType.NVarChar, 10).Value = txtPhoneNo.Text; cmd.Parameters.Add("Products", SqlDbType.NVarChar, 150).Value = txtProducts.Text; cmd.Parameters.Add("AdditionalInfo", SqlDbType.NVarChar, 150).Value = txtAccountInfo.Text; cmd.Parameters.Add("Mode", SqlDbType.NChar, 50).Value = "Insert"; if (con.State == ConnectionState.Open) { con.Close(); } con.Open(); cmd.ExecuteNonQuery(); con.Close(); ModCommon.showmessage("Record Is Saved Sucessfully.", lblMsg); fillgrid(); Clear(); enable(false); ModCommon.SaveClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); } catch { } } protected void btnUpdate_Click(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "BEM_Prospect_Detail_Proc"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = con; cmd.Parameters.Add("Prospect_Kid", SqlDbType.NVarChar, 10).Value = GridView1.SelectedDataKey.Value; cmd.Parameters.Add("Prospect_Code", SqlDbType.NVarChar, 25).Value = ModCommon.ReturnValue("Select Prospect_Code From BEM_Prospect_Detail Where Prospect_Kid ='" + ModCommon.RemoveLiterals(GridView1.SelectedDataKey.Value.ToString()) + "'"); cmd.Parameters.Add("Categoryid", SqlDbType.NVarChar, 10).Value = ddlCategory.SelectedItem.Value; cmd.Parameters.Add("ContactPerson", SqlDbType.NVarChar, 150).Value = txtContactPerson.Text; cmd.Parameters.Add("CompanyName", SqlDbType.NVarChar, 150).Value = txtCompanyName.Text; cmd.Parameters.Add("Address", SqlDbType.NVarChar, 150).Value = txtAddress.Text; cmd.Parameters.Add("Pin", SqlDbType.NVarChar, 10).Value = txtPinCode.Text; cmd.Parameters.Add("CityID", SqlDbType.NVarChar, 10).Value = ddlCity.SelectedItem.Value; cmd.Parameters.Add("StateID", SqlDbType.NVarChar, 10).Value = ddlState.SelectedItem.Value; cmd.Parameters.Add("CountryID", SqlDbType.NVarChar, 10).Value = ddlCountry.SelectedItem.Value; cmd.Parameters.Add("Website", SqlDbType.NVarChar, 150).Value = txtWebSite.Text; cmd.Parameters.Add("Email", SqlDbType.NVarChar, 150).Value = txtEmail.Text; cmd.Parameters.Add("AlternateEmail", SqlDbType.NVarChar, 150).Value = txtAEmail.Text; cmd.Parameters.Add("MobileNoCountrycode", SqlDbType.NVarChar, 10).Value = txtCountryMobile.Text; cmd.Parameters.Add("MobileNo", SqlDbType.NVarChar, 10).Value = txtMobileNo.Text; cmd.Parameters.Add("PhoneNoCountryCode", SqlDbType.NVarChar, 10).Value = txtCountryPhone.Text; cmd.Parameters.Add("PhoneNoCityCode", SqlDbType.NVarChar, 10).Value = txtCityPhone.Text; cmd.Parameters.Add("PhoneNo", SqlDbType.NVarChar, 10).Value = txtPhoneNo.Text; cmd.Parameters.Add("Products", SqlDbType.NVarChar, 150).Value = txtProducts.Text; cmd.Parameters.Add("AdditionalInfo", SqlDbType.NVarChar, 150).Value = txtAccountInfo.Text; cmd.Parameters.Add("Mode", SqlDbType.NChar, 50).Value = "Update"; if (con.State == ConnectionState.Open) { con.Close(); } con.Open(); cmd.ExecuteNonQuery(); con.Close(); fillgrid(); Clear(); ModCommon.showmessage("Record Is Updated Sucessfully.", lblMsg); enable(false); ModCommon.EditClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); } catch { } } protected void btnDelete_Click(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Delete From BEM_Prospect_Detail where Prospect_Kid ='" + GridView1.SelectedDataKey.Value + "'"; cmd.CommandType = CommandType.Text; cmd.Connection = con; if (con.State == ConnectionState.Open) { con.Close(); } con.Open(); cmd.ExecuteNonQuery(); con.Close(); fillgrid(); ModCommon.showmessage("Record Is Deleted Sucessfully.", lblMsg); Clear(); enable(false); ModCommon.DeleteClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); } catch { } } protected void btnCancel_Click(object sender, EventArgs e) { try { Clear(); enable(false); ModCommon.CancelClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); } catch { } } protected void btnSearch_Click(object sender, EventArgs e) { try { ModCommon.SearchClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); } catch { } } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { //string str; //str = GridView1.SelectedDataKey.Value.ToString(); try { DataTable dt = new DataTable(); dt = ModCommon.ReturnDataTable("Select * From BEM_Prospect_Detail where Prospect_KId ='" + GridView1.SelectedDataKey.Value.ToString() + "'"); if (dt.Rows.Count > 0) { ddlCategory.ClearSelection(); ddlCategory.Items.FindByValue(dt.Rows[0]["Categoryid"].ToString()).Selected = true; txtContactPerson.Text = dt.Rows[0]["ContactPerson"].ToString(); txtCompanyName.Text = dt.Rows[0]["CompanyName"].ToString(); txtAddress.Text = dt.Rows[0]["Address"].ToString(); txtPinCode.Text = dt.Rows[0]["Pin"].ToString(); ModCommon.Fill_Combo("Select Country_Kid, Country_Name from Country_Master where Country_Isdeleted = '0'", ddlCountry); ddlCountry.ClearSelection(); ddlCountry.Items.FindByValue(dt.Rows[0]["CountryID"].ToString()).Selected = true; ModCommon.Fill_Combo("Select State_Kid, State_Name From State_Master where State_CountryID ='" + ddlCountry.SelectedItem.Value + "'and State_Isdeleted='0'", ddlState); ddlState.ClearSelection(); ddlState.Items.FindByValue(dt.Rows[0]["StateID"].ToString()).Selected = true; ModCommon.Fill_Combo("Select City_Kid, City_Name from City_Master Where City_StateId ='" + ddlState.SelectedItem.Value + "'and City_Isdeleted ='0'", ddlCity); ddlCity.ClearSelection(); ddlCity.Items.FindByValue(dt.Rows[0]["CityID"].ToString()).Selected = true; txtWebSite.Text = dt.Rows[0]["WebSite"].ToString(); txtEmail.Text = dt.Rows[0]["Email"].ToString(); txtAEmail.Text = dt.Rows[0]["AlternateEmail"].ToString(); txtCountryMobile.Text = dt.Rows[0]["MobileNoCountryCode"].ToString(); txtMobileNo.Text = dt.Rows[0]["MobileNo"].ToString(); txtCountryPhone.Text = dt.Rows[0]["PhoneNoCountryCode"].ToString(); txtCityPhone.Text = dt.Rows[0]["PhoneNoCityCode"].ToString(); txtPhoneNo.Text = dt.Rows[0]["PhoneNo"].ToString(); txtProducts.Text = dt.Rows[0]["Products"].ToString(); txtAccountInfo.Text = dt.Rows[0]["AdditionalInfo"].ToString(); } dt.Clear(); enable(true); ModCommon.GridClick(ref p, ref btnAdd, ref btnSave, ref btnUpdate, ref btnDelete, ref btnCancel, ref btnSearch); } catch { } } protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e) { try { tr2.Visible = false; tr1.Visible = true; if (ddlCountry.SelectedIndex > 0) { ddlState.Items.Clear(); ModCommon.Fill_Combo("Select State_Kid, State_Name From State_Master where State_CountryID ='" + ddlCountry.SelectedItem.Value + "'and State_Isdeleted ='0'", ddlState); ddlCity.Items.Clear(); ddlCity.Items.Add("Select"); txtCountryPhone.Text = ModCommon.ReturnValue("Select Country_ISDCode from country_master where Country_Kid ='" + ddlCountry.SelectedItem.Value + "'"); txtCountryMobile.Text = ModCommon.ReturnValue("Select Country_ISDCode from country_master where Country_Kid ='" + ddlCountry.SelectedItem.Value + "'"); ddlState.Focus(); } else { ddlState.Items.Clear(); ddlState.Items.Add("Select"); ddlCity.Items.Clear(); ddlCity.Items.Add("Select"); txtCountryMobile.Text = ""; txtCountryPhone.Text = ""; ddlCountry.Focus(); } } catch { } } protected void ddlState_SelectedIndexChanged(object sender, EventArgs e) { try { if (ddlState.SelectedIndex > 0) { ddlCity.Items.Clear(); ModCommon.FillComboWithOthers("Select City_Kid, City_Name from City_Master where City_StateID ='" + ddlState.SelectedItem.Value + "'and City_Isdeleted ='0'", ddlCity); ddlCity.Focus(); } else { ddlCity.Items.Clear(); ddlCity.Items.Add("Select"); ddlState.Focus(); } } catch { } } protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e) { try { if (ddlCity.SelectedItem.Text == "Others") { tr1.Visible = false; tr2.Visible = true; txtAddCity.Focus(); } else { txtAddress.Focus(); } } catch { } } protected void btnAddCity_Click(object sender, EventArgs e) { } protected void btbCancelCity_Click(object sender, EventArgs e) { try { tr2.Visible = false; tr1.Visible = true; if (ddlState.SelectedIndex > 0) { ddlCity.Items.Clear(); ModCommon.FillComboWithOthers("Select City_Kid, City_Name from City_Master where City_StateID ='" + ddlState.SelectedItem.Value + "'and City_Isdeleted ='0'", ddlCity); } else { ddlCity.Items.Clear(); ddlCity.Items.Add("Select"); } } catch { } } }