protected void btnSave_Click(object sender, EventArgs e) { //try //{ if (txtCompanyName.Value == string.Empty) { Alert.Show("Please enter the company name."); txtCompanyName.Focus(); return; } Company newCompany = new Company(); newCompany.CompanyName = txtCompanyName.Value; newCompany.Address = txtAddress.Value; newCompany.Phone = txtPhoneNo.Value; newCompany.Email = txtEmail.Value; newCompany.Web = txtWeb.Value; newCompany.LogoPath = txtLogoPath.Value; // newCompany.UpdateBy = user.UserId; newCompany.UpdateBy = _user.UserId; newCompany.UpdateDate = DateTime.Now; newCompany.IsActive = chkIsActive.Checked; Addresses address = new Addresses(); address.SourceType = "Company"; address.SourceId = _user.CompanyId; address.AddressType = "Main Address"; address.AddressLine1 = txtAddressLine1.Value; address.AddressLine2 = txtAddressLine2.Value; address.CountryId = countryDropDownList.SelectedIndex; address.City = txtCity.Value; address.ZipCode = txtZipCode.Value; address.Phone = txtPhoneNo.Value; address.Mobile = txtPhoneNo.Value; address.Email = txtEmail.Value; address.Web = txtWeb.Value; address.CompanyId = _user.CompanyId; int success = newCompany.InsertCompany(); //address.InsertAddresses(); if (success > 0) { Alert.Show("Saved Company Information Successfully!"); this.LoadAllCompany(); this.Clear(); this.LoadCompanyTable(); } else { Alert.Show("Error occured !"); } //} //catch (Exception ex) //{ // Alert.Show(ex.Message); //} }
protected void btnSave_Click(object sender, EventArgs e) { try { if (txtCompanyName.Value == string.Empty) { Alert.Show("Please enter the company name."); txtCompanyName.Focus(); return; } Company newCompany = new Company(); newCompany.CompanyName = txtCompanyName.Value; newCompany.Address = ""; newCompany.Phone = ""; newCompany.Email = ""; newCompany.Web = ""; newCompany.LogoPath = txtLogoPath.Value; // newCompany.UpdateBy = user.UserId; newCompany.UpdateBy = _user.UserId; newCompany.UpdateDate = DateTime.Now; newCompany.IsActive = chkIsActive.Checked; Addresses address = new Addresses(); address.SourceType = "Company"; address.AddressType = "Main Address"; address.AddressLine1 = txtAddressLine1.Value; address.AddressLine2 = txtAddressLine2.Value; address.CountryId = countryDropDownList.SelectedIndex; address.City = txtCity.Value; address.ZipCode = txtZipCode.Value; address.Phone = txtPhoneNo.Value; address.Mobile = txtPhoneNo.Value; address.Email = txtEmail.Value; address.Web = txtWeb.Value; address.CompanyId = _user.CompanyId; if (lblId.Text == "" || lblId.Text == "0") { newCompany.CompanyId = new Company().GetMaxCompanyId() + 1; address.SourceId = newCompany.CompanyId; address.AddressId = new Addresses().GetMaxAddressId() + 1; int success = newCompany.InsertCompany(); address.InsertAddresses(); if (success > 0) { Alert.Show("Saved Company Information Successfully!"); this.LoadAllCompany(); this.Clear(); } else { Alert.Show("Error occured !"); } } else { newCompany.CompanyId = int.Parse(lblId.Text); address.SourceId = newCompany.CompanyId; address.AddressId = long.Parse(addlblId.Text); int chk1 = newCompany.UpdateCompany(); int chk2 = address.UpdateAddresses(); if (chk1 > 0||chk2>0) { Response.Redirect("CompanyList.aspx", true); } } } catch (Exception ex) { Alert.Show(ex.Message); } }