protected void btnDelete_Click(object sender, EventArgs e) { { int client = int.Parse(hdnSelectedClientID.Value.Trim()); if (client > 0) { try { using (TransactionScope ts = new TransactionScope()) { JobNameBO objJobName = new JobNameBO(this.ObjContext); objJobName.ID = client; objJobName.GetObject(); objJobName.Delete(); this.ObjContext.SaveChanges(); ts.Complete(); } this.PopulateDataGrid(); } catch (Exception ex) { throw ex; } } } }
private int ProcessForm() { int client = 0; try { using (TransactionScope ts = new TransactionScope()) { JobNameBO objJobName = new JobNameBO(this.ObjContext); if (QueryID > 0) { objJobName.ID = QueryID; objJobName.GetObject(); } else { objJobName.Creator = this.LoggedUser.ID; objJobName.CreatedDate = DateTime.Now; } objJobName.Client = int.Parse(this.ddlClient.SelectedValue); objJobName.Name = this.txtName.Text; objJobName.Address = this.txtAddress1.Text; objJobName.City = this.txtCity.Text; objJobName.State = this.txtState.Text; objJobName.PostalCode = this.txtPostalCode.Text; if (ddlCountry.SelectedIndex > 0) { objJobName.Country = this.ddlCountry.SelectedItem.Text; //int.Parse(this.ddlCountry.SelectedValue); } objJobName.Phone = this.txtPhoneNo1.Text; objJobName.Email = this.txtEmailAddress.Text; objJobName.Modifier = this.LoggedUser.ID; objJobName.ModifiedDate = DateTime.Now; this.ObjContext.SaveChanges(); ts.Complete(); client = objJobName.ID; } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while saving clients", ex); } return(client); }
/// <summary> /// Populate the controls. /// </summary> private void PopulateControls() { ViewState["isPopulate"] = false; //Header Text this.litHeaderText.Text = ((this.QueryID > 0) ? "Edit " : "New ") + this.ActivePage.Heading; // Popup Header Text this.lblPopupHeaderText.Text = "New Client Type"; // Populate IsDestributors //this.ddlCompany.Items.Add(new ListItem("Select Distributor", "0")); //CompanyBO objCompany = new CompanyBO(); //objCompany.IsDistributor = true; //List<CompanyBO> lstCompany = new List<CompanyBO>(); //lstCompany = (from o in objCompany.SearchObjects().OrderBy(m => m.Name).AsQueryable().ToList<CompanyBO>() // where o.IsDistributor == true // select o).ToList(); //foreach (CompanyBO company in lstCompany) //{ // this.ddlCompany.Items.Add(new ListItem(company.Name, company.ID.ToString())); //} //Populate Clients this.ddlClient.Items.Add(new ListItem("Select Client", "0")); ClientBO objClient = new ClientBO(); if (LoggedUser.IsDirectSalesPerson) { objClient.Distributor = DistributorID; } else if (LoggedUserRoleName == UserRole.DistributorAdministrator || LoggedUserRoleName == UserRole.DistributorCoordinator) { objClient.Distributor = LoggedCompany.ID; } List <ClientBO> lstClient = (from o in objClient.SearchObjects().OrderBy(m => m.Name).AsQueryable().ToList <ClientBO>() select o).ToList(); foreach (ClientBO client in lstClient) { this.ddlClient.Items.Add(new ListItem(client.Name, client.ID.ToString())); } // Populate CountryBO this.ddlCountry.Items.Add(new ListItem("Select Your Country")); List <CountryBO> lstCountry = (new CountryBO()).GetAllObject().AsQueryable().OrderBy("ShortName").ToList(); foreach (CountryBO country in lstCountry) { this.ddlCountry.Items.Add(new ListItem(country.ShortName, country.ID.ToString())); } // If QueryId is grater than zero, edit mode. if (this.QueryID > 0) { JobNameBO objJobName = new JobNameBO(this.ObjContext); objJobName.ID = this.QueryID; objJobName.GetObject(); this.ddlClient.SelectedValue = objJobName.Client.ToString(); this.txtName.Text = objJobName.Name; this.txtAddress1.Text = objJobName.Address; this.txtCity.Text = objJobName.City; this.txtState.Text = objJobName.State; this.txtPostalCode.Text = objJobName.PostalCode; if (!string.IsNullOrEmpty(objJobName.Country)) { this.ddlCountry.Items.FindByText(objJobName.Country).Selected = true; //.SelectedItem.Text = objJobName.Country; } this.txtPhoneNo1.Text = objJobName.Phone; this.txtEmailAddress.Text = objJobName.Email; } else { this.ddlCountry.Items.FindByValue("14").Selected = true; } }