/// <summary> /// Name:btnSubmit_Click /// Description:Here in below code update row and also insert row /// Author:Monal Shah /// Created Date:2010/10/4 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { int intIdValue = SessionMethod.CurrentSession.EmployeeID; try { if (intIdValue == 0) { objEmpTerritories.LName = TxtLname.Text; objEmpTerritories.FName = TxtFname.Text; objEmpTerritories.Title = TxtTitle.Text; if (DdlSalutation.SelectedIndex != 0) { objEmpTerritories.Salutation = DdlSalutation.SelectedItem.Value; } else { objEmpTerritories.Salutation = null; } objEmpTerritories.BirthDate = TxtBdate.Text; objEmpTerritories.HireDate = TxtHDate.Text; objEmpTerritories.Address = TxtAddress.Text; objEmpTerritories.City = TxtCity.Text; objEmpTerritories.Region = TxtRegion.Text; objEmpTerritories.PostalCode = TxtPostalCode.Text; objEmpTerritories.Country = TxtCountry.Text; objEmpTerritories.Homephone = TxtHomePhone.Text; objEmpTerritories.Extension = TxtExtension.Text; objEmpTerritories.Notes = TxtNotes.Text; if (TxtReportsTo.Text != "") { objEmpTerritories.ReportsTo = Convert.ToInt32(TxtReportsTo.Text); } else { objEmpTerritories.ReportsTo = Convert.ToInt32(null); } objEmpTerritories.InsertEmployeeTerritories().ToString(); for (int i = 0; i < LstListBox.Items.Count; i++)// in LstListBox.Items) { if (LstListBox.Items[i].Selected) { sbInsertValueEmployee = new StringBuilder(); sbInsertValueEmployee.Append("Select "); sbInsertValueEmployee.Append("TOP "); sbInsertValueEmployee.Append("1"); sbInsertValueEmployee.Append(" EmployeeID "); sbInsertValueEmployee.Append("From "); sbInsertValueEmployee.Append("Employees"); sbInsertValueEmployee.Append(" Order By"); sbInsertValueEmployee.Append(" EmployeeID "); sbInsertValueEmployee.Append("DESC "); objCl.GetSqlStmt = sbInsertValueEmployee.ToString(); objDTable = objCl.DataTables(); //string strquery = sbInsertValueEmployee.ToString(); //SqlDataAdapter adp = new SqlDataAdapter(strquery, Commonlogic.GetConnectionString); //adp.Fill(dt); if (objDTable.Rows.Count > 0) { objEmpTerritories.EmpID = Convert.ToInt32(objDTable.Rows[0]["EmployeeID"]); } else { LblErrorMessage.Text = objConstant.NoTableRecordFound;// "Datatable Does Not Contain Any Row"; } } } ListBoxValues(objEmpTerritories.EmpID); Response.Redirect("EmployeeTerritoriesGrid.aspx", false); } else { objEmpTerritories.EmpID = intIdValue; objEmpTerritories.LName = TxtLname.Text; objEmpTerritories.FName = TxtFname.Text; objEmpTerritories.Title = TxtTitle.Text; objEmpTerritories.Salutation = DdlSalutation.SelectedItem.Value; objEmpTerritories.HireDate = TxtHDate.Text; objEmpTerritories.Address = TxtAddress.Text; objEmpTerritories.City = TxtCity.Text; objEmpTerritories.Region = TxtRegion.Text; objEmpTerritories.PostalCode = TxtPostalCode.Text; objEmpTerritories.Country = TxtCountry.Text; objEmpTerritories.Homephone = TxtHomePhone.Text; objEmpTerritories.Extension = TxtExtension.Text; objEmpTerritories.Notes = TxtNotes.Text; objEmpTerritories.ReportsTo = Convert.ToInt32(TxtReportsTo.Text); sbDeleteValue = new StringBuilder(); sbDeleteValue.Append("DELETE "); sbDeleteValue.Append("FROM "); sbDeleteValue.Append("EmployeeTerritories "); sbDeleteValue.Append("WHERE "); sbDeleteValue.Append("EmployeeID"); sbDeleteValue.Append("="); sbDeleteValue.Append("'"); sbDeleteValue.Append(intIdValue); sbDeleteValue.Append("'"); objCl.GetSqlStmt = sbDeleteValue.ToString();//"Delete from EmployeeTerritories where EmployeeID='" + intIdValue + "'"; objCl.TransactionExecuteNonQuery(); ListBoxValues(intIdValue); objEmpTerritories.UpdateEmployeeTerritories().ToString(); Response.Redirect("EmployeeTerritoriesGrid.aspx", false); } } catch (Exception) { Response.Redirect("Error.aspx", false); } finally { objCl = null; sbInsertValue = null; sbInsertValueEmployee = null; aryLstBoxValue = null; objEmpTerritories = null; } }
/// <summary> /// Name:InsertEmployeeTerritories /// Description:in this method fire the insert query using stringbuilder /// Author:Monal shah /// created date:2010/10/01 /// </summary> /// <returns>bool</returns> public bool InsertEmployeeTerritories() { sbInsertValue = new StringBuilder(); sbInsertValue.Append("Insert "); sbInsertValue.Append("Into "); sbInsertValue.Append("Employees "); sbInsertValue.Append("values"); sbInsertValue.Append("("); sbInsertValue.Append("'"); sbInsertValue.Append(_strLName); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strFname); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strTitle); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strSalutation); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_Bdate); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_Hdate); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strAddress); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strCity); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strRegion); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strPostalCode); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strCountry); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strHomePhone); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strExtension); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strNotes); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append(_strReportsTo); sbInsertValue.Append("'"); sbInsertValue.Append(","); sbInsertValue.Append("'"); sbInsertValue.Append("'"); sbInsertValue.Append(")"); objcl.GetSqlStmt = sbInsertValue.ToString(); return(objcl.TransactionExecuteNonQuery());//call ExecuteNonQuery method }