private void UpdateRecord() { dbo_DimSalesTerritoryClass oclsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); oclsdbo_DimSalesTerritory.SalesTerritoryKey = System.Convert.ToInt32(Session["SalesTerritoryKey"]); oclsdbo_DimSalesTerritory = dbo_DimSalesTerritoryDataClass.Select_Record(oclsdbo_DimSalesTerritory); if (VerifyData() == true) { SetData(clsdbo_DimSalesTerritory); bool bSucess = false; bSucess = dbo_DimSalesTerritoryDataClass.Update(oclsdbo_DimSalesTerritory, clsdbo_DimSalesTerritory); if (bSucess == true) { pnlForm.Visible = false; pnlSave.Visible = false; pnlGrid.Visible = true; lblMode.InnerText = ""; Session.Remove("dvdbo_DimSalesTerritory"); LoadGriddbo_DimSalesTerritory(); } else { ec.ShowMessage(" Update failed. ", " Dbo. Dim Sales Territory "); } } }
public static bool Delete(dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string deleteStatement = "DELETE FROM " + " [dbo].[DimSalesTerritory] " + "WHERE " + " [SalesTerritoryKey] = @OldSalesTerritoryKey " + " AND ((@OldSalesTerritoryAlternateKey IS NULL AND [SalesTerritoryAlternateKey] IS NULL) OR [SalesTerritoryAlternateKey] = @OldSalesTerritoryAlternateKey) " + " AND [SalesTerritoryRegion] = @OldSalesTerritoryRegion " + " AND [SalesTerritoryCountry] = @OldSalesTerritoryCountry " + " AND ((@OldSalesTerritoryGroup IS NULL AND [SalesTerritoryGroup] IS NULL) OR [SalesTerritoryGroup] = @OldSalesTerritoryGroup) " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldSalesTerritoryKey", clsdbo_DimSalesTerritory.SalesTerritoryKey); if (clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey.HasValue == true) { deleteCommand.Parameters.AddWithValue("@OldSalesTerritoryAlternateKey", clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey); } else { deleteCommand.Parameters.AddWithValue("@OldSalesTerritoryAlternateKey", DBNull.Value); } deleteCommand.Parameters.AddWithValue("@OldSalesTerritoryRegion", clsdbo_DimSalesTerritory.SalesTerritoryRegion); deleteCommand.Parameters.AddWithValue("@OldSalesTerritoryCountry", clsdbo_DimSalesTerritory.SalesTerritoryCountry); if (clsdbo_DimSalesTerritory.SalesTerritoryGroup != null) { deleteCommand.Parameters.AddWithValue("@OldSalesTerritoryGroup", clsdbo_DimSalesTerritory.SalesTerritoryGroup); } else { deleteCommand.Parameters.AddWithValue("@OldSalesTerritoryGroup", DBNull.Value); } try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }
private void Edit() { try { dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); Label lblSalesTerritoryKey = (Label)grddbo_DimSalesTerritory.Rows[grddbo_DimSalesTerritory.EditIndex].FindControl("lblSalesTerritoryKey"); clsdbo_DimSalesTerritory.SalesTerritoryKey = System.Convert.ToInt32(lblSalesTerritoryKey.Text); clsdbo_DimSalesTerritory = dbo_DimSalesTerritoryDataClass.Select_Record(clsdbo_DimSalesTerritory); LoadGriddbo_DimSalesTerritory(); } catch { } }
private void UpdateRecord() { try { TextBox txtSalesTerritoryKey = (TextBox)grddbo_DimSalesTerritory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtSalesTerritoryKey"); TextBox txtSalesTerritoryAlternateKey = (TextBox)grddbo_DimSalesTerritory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtSalesTerritoryAlternateKey"); TextBox txtSalesTerritoryRegion = (TextBox)grddbo_DimSalesTerritory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtSalesTerritoryRegion"); TextBox txtSalesTerritoryCountry = (TextBox)grddbo_DimSalesTerritory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtSalesTerritoryCountry"); TextBox txtSalesTerritoryGroup = (TextBox)grddbo_DimSalesTerritory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtSalesTerritoryGroup"); dbo_DimSalesTerritoryClass oclsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); oclsdbo_DimSalesTerritory.SalesTerritoryKey = System.Convert.ToInt32(txtSalesTerritoryKey.Text); oclsdbo_DimSalesTerritory = dbo_DimSalesTerritoryDataClass.Select_Record(oclsdbo_DimSalesTerritory); if (VerifyData() == true) { if (string.IsNullOrEmpty(txtSalesTerritoryAlternateKey.Text)) { clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey = null; } else { clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey = System.Convert.ToInt32(txtSalesTerritoryAlternateKey.Text); } clsdbo_DimSalesTerritory.SalesTerritoryRegion = System.Convert.ToString(txtSalesTerritoryRegion.Text); clsdbo_DimSalesTerritory.SalesTerritoryCountry = System.Convert.ToString(txtSalesTerritoryCountry.Text); if (string.IsNullOrEmpty(txtSalesTerritoryGroup.Text)) { clsdbo_DimSalesTerritory.SalesTerritoryGroup = null; } else { clsdbo_DimSalesTerritory.SalesTerritoryGroup = txtSalesTerritoryGroup.Text; } bool bSucess = false; bSucess = dbo_DimSalesTerritoryDataClass.Update(oclsdbo_DimSalesTerritory, clsdbo_DimSalesTerritory); if (bSucess == true) { Session.Remove("dvdbo_DimSalesTerritory"); grddbo_DimSalesTerritory.EditIndex = -1; LoadGriddbo_DimSalesTerritory(); } else { ec.ShowMessage(" Update failed. ", " Dbo. Dim Sales Territory "); } } } catch { } }
public static dbo_DimSalesTerritoryClass Select_Record(dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritoryPara) { dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string selectStatement = "SELECT " + " [SalesTerritoryKey] " + " ,[SalesTerritoryAlternateKey] " + " ,[SalesTerritoryRegion] " + " ,[SalesTerritoryCountry] " + " ,[SalesTerritoryGroup] " + "FROM " + " [dbo].[DimSalesTerritory] " + "WHERE " + " [SalesTerritoryKey] = @SalesTerritoryKey " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@SalesTerritoryKey", clsdbo_DimSalesTerritoryPara.SalesTerritoryKey); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsdbo_DimSalesTerritory.SalesTerritoryKey = System.Convert.ToInt32(reader["SalesTerritoryKey"]); clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey = reader["SalesTerritoryAlternateKey"] is DBNull ? null : (Int32?)reader["SalesTerritoryAlternateKey"]; clsdbo_DimSalesTerritory.SalesTerritoryRegion = System.Convert.ToString(reader["SalesTerritoryRegion"]); clsdbo_DimSalesTerritory.SalesTerritoryCountry = System.Convert.ToString(reader["SalesTerritoryCountry"]); clsdbo_DimSalesTerritory.SalesTerritoryGroup = reader["SalesTerritoryGroup"] is DBNull ? null : reader["SalesTerritoryGroup"].ToString(); } else { clsdbo_DimSalesTerritory = null; } reader.Close(); } catch (SqlException) { return(clsdbo_DimSalesTerritory); } finally { connection.Close(); } return(clsdbo_DimSalesTerritory); }
private void InsertRecord() { try { TextBox txtNewSalesTerritoryAlternateKey = (TextBox)grddbo_DimSalesTerritory.FooterRow.FindControl("txtNewSalesTerritoryAlternateKey"); TextBox txtNewSalesTerritoryRegion = (TextBox)grddbo_DimSalesTerritory.FooterRow.FindControl("txtNewSalesTerritoryRegion"); TextBox txtNewSalesTerritoryCountry = (TextBox)grddbo_DimSalesTerritory.FooterRow.FindControl("txtNewSalesTerritoryCountry"); TextBox txtNewSalesTerritoryGroup = (TextBox)grddbo_DimSalesTerritory.FooterRow.FindControl("txtNewSalesTerritoryGroup"); dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); if (VerifyDataNew() == true) { if (string.IsNullOrEmpty(txtNewSalesTerritoryAlternateKey.Text)) { clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey = null; } else { clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey = System.Convert.ToInt32(txtNewSalesTerritoryAlternateKey.Text); } clsdbo_DimSalesTerritory.SalesTerritoryRegion = System.Convert.ToString(txtNewSalesTerritoryRegion.Text); clsdbo_DimSalesTerritory.SalesTerritoryCountry = System.Convert.ToString(txtNewSalesTerritoryCountry.Text); if (string.IsNullOrEmpty(txtNewSalesTerritoryGroup.Text)) { clsdbo_DimSalesTerritory.SalesTerritoryGroup = null; } else { clsdbo_DimSalesTerritory.SalesTerritoryGroup = txtNewSalesTerritoryGroup.Text; } bool bSucess = false; bSucess = dbo_DimSalesTerritoryDataClass.Add(clsdbo_DimSalesTerritory); if (bSucess == true) { Session.Remove("dvdbo_DimSalesTerritory"); LoadGriddbo_DimSalesTerritory(); } else { ec.ShowMessage(" Insert failed. ", " Dbo. Dim Sales Territory "); } } } catch { } }
private void DeleteRecord() { dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); Label lblSalesTerritoryKey = (Label)grddbo_DimSalesTerritory.Rows[Convert.ToInt32(Session["Row"])].FindControl("lblSalesTerritoryKey"); clsdbo_DimSalesTerritory.SalesTerritoryKey = System.Convert.ToInt32(lblSalesTerritoryKey.Text); clsdbo_DimSalesTerritory = dbo_DimSalesTerritoryDataClass.Select_Record(clsdbo_DimSalesTerritory); bool bSucess = false; bSucess = dbo_DimSalesTerritoryDataClass.Delete(clsdbo_DimSalesTerritory); if (bSucess == true) { Session.Remove("dvdbo_DimSalesTerritory"); LoadGriddbo_DimSalesTerritory(); } else { ec.ShowMessage(" Delete failed. ", " Dbo. Dim Sales Territory "); } }
private void SetData(dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory) { if (string.IsNullOrEmpty(txtSalesTerritoryAlternateKey.Text)) { clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey = null; } else { clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey = System.Convert.ToInt32(txtSalesTerritoryAlternateKey.Text); } clsdbo_DimSalesTerritory.SalesTerritoryRegion = System.Convert.ToString(txtSalesTerritoryRegion.Text); clsdbo_DimSalesTerritory.SalesTerritoryCountry = System.Convert.ToString(txtSalesTerritoryCountry.Text); if (string.IsNullOrEmpty(txtSalesTerritoryGroup.Text)) { clsdbo_DimSalesTerritory.SalesTerritoryGroup = null; } else { clsdbo_DimSalesTerritory.SalesTerritoryGroup = txtSalesTerritoryGroup.Text; } }
private void GetData() { ClearRecord(); dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); clsdbo_DimSalesTerritory.SalesTerritoryKey = System.Convert.ToInt32(Session["SalesTerritoryKey"]); clsdbo_DimSalesTerritory = dbo_DimSalesTerritoryDataClass.Select_Record(clsdbo_DimSalesTerritory); if ((clsdbo_DimSalesTerritory != null)) { try { txtSalesTerritoryKey.Text = System.Convert.ToString(clsdbo_DimSalesTerritory.SalesTerritoryKey); if (clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey == null) { txtSalesTerritoryAlternateKey.Text = default(string); } else { txtSalesTerritoryAlternateKey.Text = System.Convert.ToString(clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey); } txtSalesTerritoryRegion.Text = System.Convert.ToString(clsdbo_DimSalesTerritory.SalesTerritoryRegion); txtSalesTerritoryCountry.Text = System.Convert.ToString(clsdbo_DimSalesTerritory.SalesTerritoryCountry); if (clsdbo_DimSalesTerritory.SalesTerritoryGroup == null) { txtSalesTerritoryGroup.Text = default(string); } else { txtSalesTerritoryGroup.Text = System.Convert.ToString(clsdbo_DimSalesTerritory.SalesTerritoryGroup); } } catch (Exception ex) { ec.ShowMessage(ex.Message, " Dbo. Dim Sales Territory "); } } }
private void InsertRecord() { dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory = new dbo_DimSalesTerritoryClass(); if (VerifyData() == true) { SetData(clsdbo_DimSalesTerritory); bool bSucess = false; bSucess = dbo_DimSalesTerritoryDataClass.Add(clsdbo_DimSalesTerritory); if (bSucess == true) { pnlForm.Visible = false; pnlSave.Visible = false; pnlGrid.Visible = true; lblMode.InnerText = ""; Session.Remove("dvdbo_DimSalesTerritory"); LoadGriddbo_DimSalesTerritory(); } else { ec.ShowMessage(" Insert failed. ", " Dbo. Dim Sales Territory "); } } }
public static bool Update(dbo_DimSalesTerritoryClass olddbo_DimSalesTerritoryClass, dbo_DimSalesTerritoryClass newdbo_DimSalesTerritoryClass) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string updateStatement = "UPDATE " + " [dbo].[DimSalesTerritory] " + "SET " + " [SalesTerritoryAlternateKey] = @NewSalesTerritoryAlternateKey " + " ,[SalesTerritoryRegion] = @NewSalesTerritoryRegion " + " ,[SalesTerritoryCountry] = @NewSalesTerritoryCountry " + " ,[SalesTerritoryGroup] = @NewSalesTerritoryGroup " + "WHERE " + " [SalesTerritoryKey] = @OldSalesTerritoryKey " + " AND ((@OldSalesTerritoryAlternateKey IS NULL AND [SalesTerritoryAlternateKey] IS NULL) OR [SalesTerritoryAlternateKey] = @OldSalesTerritoryAlternateKey) " + " AND [SalesTerritoryRegion] = @OldSalesTerritoryRegion " + " AND [SalesTerritoryCountry] = @OldSalesTerritoryCountry " + " AND ((@OldSalesTerritoryGroup IS NULL AND [SalesTerritoryGroup] IS NULL) OR [SalesTerritoryGroup] = @OldSalesTerritoryGroup) " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; if (newdbo_DimSalesTerritoryClass.SalesTerritoryAlternateKey.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewSalesTerritoryAlternateKey", newdbo_DimSalesTerritoryClass.SalesTerritoryAlternateKey); } else { updateCommand.Parameters.AddWithValue("@NewSalesTerritoryAlternateKey", DBNull.Value); } updateCommand.Parameters.AddWithValue("@NewSalesTerritoryRegion", newdbo_DimSalesTerritoryClass.SalesTerritoryRegion); updateCommand.Parameters.AddWithValue("@NewSalesTerritoryCountry", newdbo_DimSalesTerritoryClass.SalesTerritoryCountry); if (newdbo_DimSalesTerritoryClass.SalesTerritoryGroup != null) { updateCommand.Parameters.AddWithValue("@NewSalesTerritoryGroup", newdbo_DimSalesTerritoryClass.SalesTerritoryGroup); } else { updateCommand.Parameters.AddWithValue("@NewSalesTerritoryGroup", DBNull.Value); } updateCommand.Parameters.AddWithValue("@OldSalesTerritoryKey", olddbo_DimSalesTerritoryClass.SalesTerritoryKey); if (olddbo_DimSalesTerritoryClass.SalesTerritoryAlternateKey.HasValue == true) { updateCommand.Parameters.AddWithValue("@OldSalesTerritoryAlternateKey", olddbo_DimSalesTerritoryClass.SalesTerritoryAlternateKey); } else { updateCommand.Parameters.AddWithValue("@OldSalesTerritoryAlternateKey", DBNull.Value); } updateCommand.Parameters.AddWithValue("@OldSalesTerritoryRegion", olddbo_DimSalesTerritoryClass.SalesTerritoryRegion); updateCommand.Parameters.AddWithValue("@OldSalesTerritoryCountry", olddbo_DimSalesTerritoryClass.SalesTerritoryCountry); if (olddbo_DimSalesTerritoryClass.SalesTerritoryGroup != null) { updateCommand.Parameters.AddWithValue("@OldSalesTerritoryGroup", olddbo_DimSalesTerritoryClass.SalesTerritoryGroup); } else { updateCommand.Parameters.AddWithValue("@OldSalesTerritoryGroup", DBNull.Value); } try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }
public static bool Add(dbo_DimSalesTerritoryClass clsdbo_DimSalesTerritory) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string insertStatement = "INSERT " + " [dbo].[DimSalesTerritory] " + " ( " + " [SalesTerritoryAlternateKey] " + " ,[SalesTerritoryRegion] " + " ,[SalesTerritoryCountry] " + " ,[SalesTerritoryGroup] " + " ) " + "VALUES " + " ( " + " @SalesTerritoryAlternateKey " + " ,@SalesTerritoryRegion " + " ,@SalesTerritoryCountry " + " ,@SalesTerritoryGroup " + " ) " + ""; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.CommandType = CommandType.Text; if (clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey.HasValue == true) { insertCommand.Parameters.AddWithValue("@SalesTerritoryAlternateKey", clsdbo_DimSalesTerritory.SalesTerritoryAlternateKey); } else { insertCommand.Parameters.AddWithValue("@SalesTerritoryAlternateKey", DBNull.Value); } insertCommand.Parameters.AddWithValue("@SalesTerritoryRegion", clsdbo_DimSalesTerritory.SalesTerritoryRegion); insertCommand.Parameters.AddWithValue("@SalesTerritoryCountry", clsdbo_DimSalesTerritory.SalesTerritoryCountry); if (clsdbo_DimSalesTerritory.SalesTerritoryGroup != null) { insertCommand.Parameters.AddWithValue("@SalesTerritoryGroup", clsdbo_DimSalesTerritory.SalesTerritoryGroup); } else { insertCommand.Parameters.AddWithValue("@SalesTerritoryGroup", DBNull.Value); } try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }