using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.IO; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace infoExpediters.Admin { public partial class EditCompanyDetails : System.Web.UI.Page { AddCompany obj = new AddCompany(); protected void Page_Load(object sender, EventArgs e) { try { validatetxt.Visible = false; txtPriceListDate.Attributes.Add("readonly", "readonly"); if (Session["username"] == null) { Response.Redirect("AdminLogin.aspx"); } else { if (Session["username"].ToString() == "admin") { if (!IsPostBack) { GetStates(); GetRegions(); GetPaperStates(); GetPartStates(); GetTimeZone(); GetCompanyNames(); GetCompanyDetails(); } } else { Response.Redirect("AdminLogin.aspx"); } } } catch (Exception ex) { string strEx = ex.Message; } } //Get all company details for editing public void GetCompanyDetails() { try { DataSet ds = obj.fillvalues(Convert.ToInt32(Request.QueryString["id"].ToString())); txtCompanyName.Text = ds.Tables[0].Rows[0]["CompanyName"].ToString(); txtCompanyTag.Text = ds.Tables[0].Rows[0]["Tag"].ToString(); txtCity.Text = ds.Tables[0].Rows[0]["City"].ToString(); ddlState.SelectedValue = ds.Tables[0].Rows[0]["StateType"].ToString(); txtAddress1.Text = ds.Tables[0].Rows[0]["Address1"].ToString(); txtAddress2.Text = ds.Tables[0].Rows[0]["Address2"].ToString(); txtCustomerNo1.Text = ds.Tables[0].Rows[0]["CompanyCSPre"].ToString(); txtCustomerNo2.Text = ds.Tables[0].Rows[0]["CompanyCSArea"].ToString(); txtCustomerNo3.Text = ds.Tables[0].Rows[0]["CompanyCSSuffix"].ToString(); txtPaperAddress1.Text = ds.Tables[0].Rows[0]["PaperAddress1"].ToString(); txtPaperAddress2.Text = ds.Tables[0].Rows[0]["PaperAddress2"].ToString(); txtPaperCity.Text = ds.Tables[0].Rows[0]["PaperCity"].ToString(); txtPaperZip.Text = ds.Tables[0].Rows[0]["PaperZip"].ToString(); ddlPaperStateType.Text = ds.Tables[0].Rows[0]["PaperStateType"].ToString(); txtPartsAddress1.Text = ds.Tables[0].Rows[0]["PartsAddress1"].ToString(); txtPartsAddress2.Text = ds.Tables[0].Rows[0]["PartsAddress2"].ToString(); txtPartsCity.Text = ds.Tables[0].Rows[0]["PartsCity"].ToString(); txtPartsZip.Text = ds.Tables[0].Rows[0]["PartsZip"].ToString(); ddlPartsStateType.Text = ds.Tables[0].Rows[0]["PartsStateType"].ToString(); txtPh1.Text = ds.Tables[0].Rows[0]["CompanyPhonePre"].ToString(); txtPh2.Text = ds.Tables[0].Rows[0]["CompanyPhoneArea"].ToString(); txtPh3.Text = ds.Tables[0].Rows[0]["CompanyPhoneSuffix"].ToString(); txtPriceList.Text = ds.Tables[0].Rows[0]["PriceList"].ToString(); string date = ds.Tables[0].Rows[0]["Pricelistdate"].ToString(); if (date == "") { } else { txtPriceListDate.Text = String.Format("{0:dd-MMM-yyyy}", DateTime.Parse(date)); } txtShippingCutOffTime.Text = ds.Tables[0].Rows[0]["ShippingCutOffTime"].ToString(); txtFax1.Text = ds.Tables[0].Rows[0]["CompanyFaxPre"].ToString(); txtFax2.Text = ds.Tables[0].Rows[0]["CompanyFaxArea"].ToString(); txtFax3.Text = ds.Tables[0].Rows[0]["CompanyFaxSuffix"].ToString(); txtTechPh1.Text = ds.Tables[0].Rows[0]["CompanyTechPre"].ToString(); txtTechPh2.Text = ds.Tables[0].Rows[0]["CompanyTechArea"].ToString(); txtTechPh3.Text = ds.Tables[0].Rows[0]["CompanyTechSuffix"].ToString(); txttf1.Text = ds.Tables[0].Rows[0]["CompanyTollPre"].ToString(); txttf2.Text = ds.Tables[0].Rows[0]["CompanyTollArea"].ToString(); txttf3.Text = ds.Tables[0].Rows[0]["CompanyTollSuffix"].ToString(); txtWebsite.Text = ds.Tables[0].Rows[0]["WebSite"].ToString(); txtEmail.Text = ds.Tables[0].Rows[0]["EmailId"].ToString(); txtZip.Text = ds.Tables[0].Rows[0]["Zip"].ToString(); txtKeywords.Text = ds.Tables[0].Rows[0]["Keywords"].ToString(); ddlCompanyParent.SelectedValue = ds.Tables[0].Rows[0]["ParentCompanyId"].ToString(); ddlTimeZoneCode.SelectedValue = ds.Tables[0].Rows[0]["TimeZoneCode"].ToString(); string imageurl = ds.Tables[0].Rows[0]["LogoUrl"].ToString(); if (!String.IsNullOrEmpty(ds.Tables[0].Rows[0]["LogoUrl"].ToString())) { string Url = ds.Tables[0].Rows[0]["LogoUrl"].ToString(); ImageUrl.ImageUrl = "../CompanyLogos/" + Url; h1.Value = Url; imagetd.Visible = true; ImageUrl.Visible = true; } else { imagetd.Visible = false; ImageUrl.Visible = false; lbErrorMessage.Text = "No picture"; } for (int i = 0; i < ds.Tables[1].Rows.Count; i++) { Select1.Items.Add(ds.Tables[1].Rows[i]["CodeName"].ToString()); hdnRegions.Value += ds.Tables[1].Rows[i]["CodeValue"].ToString() + ","; } } catch (Exception ex) { String strEx1 = ex.Message; } } // get states to populate state drop down lists public void GetStates() { try { DataSet ds = obj.GetStates(); ddlState.DataSource = ds.Tables["Codes"]; ddlState.DataTextField = "CodeName"; ddlState.DataValueField = "CodeValue"; ddlState.DataBind(); int val; val = 0; ddlState.Items.Insert(0, "[Select State]"); ddlState.Items[0].Value = val.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } // get Regions to populate regions drop down lists public void GetRegions() { try { DataSet ds = obj.GetRegions(); ddlRegions.DataSource = ds.Tables["Codes"]; ddlRegions.DataTextField = "CodeName"; ddlRegions.DataValueField = "CodeValue"; ddlRegions.DataBind(); int val; val = 0; ddlRegions.Items.Insert(0, "[Select Region]"); ddlRegions.Items[0].Value = val.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } // get states to populate state drop down lists public void GetPartStates() { try { DataSet ds = obj.GetPartStates(); ddlPartsStateType.DataSource = ds.Tables["Codes"]; ddlPartsStateType.DataTextField = "CodeName"; ddlPartsStateType.DataValueField = "CodeValue"; ddlPartsStateType.DataBind(); int val; val = 0; ddlPartsStateType.Items.Insert(0, "[Select State]"); ddlPartsStateType.Items[0].Value = val.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } // get states to populate state drop down lists public void GetPaperStates() { try { DataSet ds = obj.GetPaperStates(); ddlPaperStateType.DataSource = ds.Tables["Codes"]; ddlPaperStateType.DataTextField = "CodeName"; ddlPaperStateType.DataValueField = "CodeValue"; ddlPaperStateType.DataBind(); int val; val = 0; ddlPaperStateType.Items.Insert(0, "[Select State]"); ddlPaperStateType.Items[0].Value = val.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } // get TimeZone to populate TimeZone drop down list public void GetTimeZone() { try { DataSet ds = obj.GetTimeZone(); ddlTimeZoneCode.DataSource = ds.Tables["Codes"]; ddlTimeZoneCode.DataTextField = "CodeName"; ddlTimeZoneCode.DataValueField = "CodeValue"; ddlTimeZoneCode.DataBind(); int val; val = 0; ddlTimeZoneCode.Items.Insert(0, "[Select TimeZone]"); ddlTimeZoneCode.Items[0].Value = val.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } // Get company names to populate parent company drop down list public void GetCompanyNames() { try { DataSet ds = obj.GetCompanyNames(); ddlCompanyParent.DataSource = ds.Tables["Company"]; ddlCompanyParent.DataTextField = "CompanyName"; ddlCompanyParent.DataValueField = "CompanyId"; ddlCompanyParent.DataBind(); int val; val = 0; ddlCompanyParent.Items.Insert(0, "[None]"); ddlCompanyParent.Items[0].Value = val.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } // save company details protected void btnSubmit_Click(object sender, EventArgs e) { try { Hashtable ht = new Hashtable(); ht.Add("@companyname", txtCompanyName.Text.Trim()); ht.Add("@tag", txtCompanyTag.Text.Trim()); ht.Add("@parentcompanyid", ddlCompanyParent.SelectedItem.Value.ToString()); ht.Add("@address1", txtAddress1.Text.Trim()); ht.Add("@address2", txtAddress2.Text.Trim()); ht.Add("@city", txtCity.Text.Trim()); ht.Add("@statetype", ddlState.SelectedItem.Value.ToString()); ht.Add("@zip", txtZip.Text.Trim()); ht.Add("@paperaddress1", txtPaperAddress1.Text.Trim()); ht.Add("@paperaddress2", txtPaperAddress2.Text.Trim()); ht.Add("@papercity", txtPaperCity.Text); ht.Add("@paperstatetype", ddlPaperStateType.SelectedItem.Value.ToString()); ht.Add("@paperzip", txtPaperZip.Text.Trim()); ht.Add("@partsaddress1", txtPartsAddress1.Text); ht.Add("@partsaddress2", txtPartsAddress2.Text.Trim()); ht.Add("@partscity", txtPartsCity.Text.Trim()); ht.Add("@partsstatetype", ddlPartsStateType.SelectedItem.Value.ToString()); ht.Add("@partszip", txtPartsZip.Text.Trim()); ht.Add("@shippingcutofftime", txtShippingCutOffTime.Text.Trim()); ht.Add("@timezonecode", ddlTimeZoneCode.SelectedItem.Value.ToString()); ht.Add("@companyphonearea", txtPh1.Text.Trim()); ht.Add("@companyphonepre", txtPh2.Text.Trim()); ht.Add("@companyphonesuffix", txtPh3.Text.Trim()); ht.Add("@companyfaxarea", txtFax1.Text.Trim()); ht.Add("@companyfaxpre", txtFax2.Text.Trim()); ht.Add("@companyfaxsuffix", txtFax3.Text.Trim()); ht.Add("@companyTollarea", txttf1.Text.Trim()); ht.Add("@companyTollpre", txttf2.Text.Trim()); ht.Add("@companyTollsuffix", txttf3.Text.Trim()); ht.Add("@companyTecharea", txtTechPh1.Text.Trim()); ht.Add("@companyTechpre", txtTechPh2.Text.Trim()); ht.Add("@companyTechsuffix", txtTechPh3.Text.Trim()); ht.Add("@companyCSarea", txtCustomerNo1.Text.Trim()); ht.Add("@companyCSpre", txtCustomerNo2.Text.Trim()); ht.Add("@companyCSsuffix", txtCustomerNo3.Text.Trim()); ht.Add("@webSite", txtWebsite.Text.Trim()); ht.Add("@emailId", txtEmail.Text.Trim()); ht.Add("@pricelist", txtPriceList.Text.Trim()); ht.Add("@keywords", txtKeywords.Text.Trim()); ht.Add("@pricelistdate", txtPriceListDate.Text.Trim()); ht.Add("@Status", "1"); int Id = Convert.ToInt32(Request.QueryString["id"].ToString()); ht.Add("@CompanyId", Id); if (chkSave.Checked == false) { if ((fu1.PostedFile.ContentLength == 0)) { string compurl = h1.Value + "_" + Id; ht.Add("@logoUrl", h1.Value); } } if (chkSave.Checked) { obj.Delete(Convert.ToInt32(Request.QueryString["id"].ToString())); string filepath = Request.PhysicalApplicationPath + "CompanyLogos"+"\\"+h1.Value; FileInfo file = new FileInfo(filepath); if (file.Exists) { file.Delete(); } } if (chkSave.Checked) { if ((fu1.PostedFile.ContentLength == 0)) { lbMessage.Text = "Select a image"; } } if ((fu1.PostedFile != null) && (fu1.PostedFile.ContentLength > 0)) { string compurl = System.IO.Path.GetFileNameWithoutExtension(fu1.PostedFile.FileName) + "_" + Id.ToString() + System.IO.Path.GetExtension(fu1.PostedFile.FileName); ht.Add("@logoUrl", compurl.ToString()); } string Reg = hdnRegions.Value; ht.Add("@string", Reg.ToString()); Hashtable ht1 = new Hashtable(); ht1 = obj.InsertData(ht); if (ht1["status"].ToString()!=null) { if ((fu1.PostedFile != null) && (fu1.PostedFile.ContentLength > 0)) { string filepath = Request.PhysicalApplicationPath + "CompanyLogos"; string strFileName = System.IO.Path.GetFileNameWithoutExtension(fu1.PostedFile.FileName) + "_" + Id.ToString() + System.IO.Path.GetExtension(fu1.PostedFile.FileName); fu1.PostedFile.SaveAs(filepath + ("\\" + strFileName)); } SecureQueryString qs = new SecureQueryString(); qs["action"] = "1"; Response.Redirect("AdminMessage.aspx?qs=" + qs.ToString()); } } catch (Exception ex) { string s = ex.Message; } } } }