private void UpdateRecord() { dbo_DimProductCategoryClass oclsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); oclsdbo_DimProductCategory.ProductCategoryKey = System.Convert.ToInt32(Session["ProductCategoryKey"]); oclsdbo_DimProductCategory = dbo_DimProductCategoryDataClass.Select_Record(oclsdbo_DimProductCategory); if (VerifyData() == true) { SetData(clsdbo_DimProductCategory); bool bSucess = false; bSucess = dbo_DimProductCategoryDataClass.Update(oclsdbo_DimProductCategory, clsdbo_DimProductCategory); if (bSucess == true) { pnlForm.Visible = false; pnlSave.Visible = false; pnlGrid.Visible = true; lblMode.InnerText = ""; Session.Remove("dvdbo_DimProductCategory"); LoadGriddbo_DimProductCategory(); } else { ec.ShowMessage(" Update failed. ", " Dbo. Dim Product Category "); } } }
private void GetData() { ClearRecord(); dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); clsdbo_DimProductCategory.ProductCategoryKey = System.Convert.ToInt32(Session["ProductCategoryKey"]); clsdbo_DimProductCategory = dbo_DimProductCategoryDataClass.Select_Record(clsdbo_DimProductCategory); if ((clsdbo_DimProductCategory != null)) { try { txtProductCategoryKey.Text = System.Convert.ToString(clsdbo_DimProductCategory.ProductCategoryKey); if (clsdbo_DimProductCategory.ProductCategoryAlternateKey == null) { txtProductCategoryAlternateKey.Text = default(string); } else { txtProductCategoryAlternateKey.Text = System.Convert.ToString(clsdbo_DimProductCategory.ProductCategoryAlternateKey); } txtEnglishProductCategoryName.Text = System.Convert.ToString(clsdbo_DimProductCategory.EnglishProductCategoryName); txtSpanishProductCategoryName.Text = System.Convert.ToString(clsdbo_DimProductCategory.SpanishProductCategoryName); txtFrenchProductCategoryName.Text = System.Convert.ToString(clsdbo_DimProductCategory.FrenchProductCategoryName); } catch (Exception ex) { ec.ShowMessage(ex.Message, " Dbo. Dim Product Category "); } } }
public static bool Add(dbo_DimProductCategoryClass clsdbo_DimProductCategory) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string insertStatement = "INSERT " + " [dbo].[DimProductCategory] " + " ( " + " [ProductCategoryAlternateKey] " + " ,[EnglishProductCategoryName] " + " ,[SpanishProductCategoryName] " + " ,[FrenchProductCategoryName] " + " ) " + "VALUES " + " ( " + " @ProductCategoryAlternateKey " + " ,@EnglishProductCategoryName " + " ,@SpanishProductCategoryName " + " ,@FrenchProductCategoryName " + " ) " + ""; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.CommandType = CommandType.Text; if (clsdbo_DimProductCategory.ProductCategoryAlternateKey.HasValue == true) { insertCommand.Parameters.AddWithValue("@ProductCategoryAlternateKey", clsdbo_DimProductCategory.ProductCategoryAlternateKey); } else { insertCommand.Parameters.AddWithValue("@ProductCategoryAlternateKey", DBNull.Value); } insertCommand.Parameters.AddWithValue("@EnglishProductCategoryName", clsdbo_DimProductCategory.EnglishProductCategoryName); insertCommand.Parameters.AddWithValue("@SpanishProductCategoryName", clsdbo_DimProductCategory.SpanishProductCategoryName); insertCommand.Parameters.AddWithValue("@FrenchProductCategoryName", clsdbo_DimProductCategory.FrenchProductCategoryName); try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }
private void Edit() { try { dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); Label lblProductCategoryKey = (Label)grddbo_DimProductCategory.Rows[grddbo_DimProductCategory.EditIndex].FindControl("lblProductCategoryKey"); clsdbo_DimProductCategory.ProductCategoryKey = System.Convert.ToInt32(lblProductCategoryKey.Text); clsdbo_DimProductCategory = dbo_DimProductCategoryDataClass.Select_Record(clsdbo_DimProductCategory); LoadGriddbo_DimProductCategory(); } catch { } }
private void SetData(dbo_DimProductCategoryClass clsdbo_DimProductCategory) { if (string.IsNullOrEmpty(txtProductCategoryAlternateKey.Text)) { clsdbo_DimProductCategory.ProductCategoryAlternateKey = null; } else { clsdbo_DimProductCategory.ProductCategoryAlternateKey = System.Convert.ToInt32(txtProductCategoryAlternateKey.Text); } clsdbo_DimProductCategory.EnglishProductCategoryName = System.Convert.ToString(txtEnglishProductCategoryName.Text); clsdbo_DimProductCategory.SpanishProductCategoryName = System.Convert.ToString(txtSpanishProductCategoryName.Text); clsdbo_DimProductCategory.FrenchProductCategoryName = System.Convert.ToString(txtFrenchProductCategoryName.Text); }
public static bool Delete(dbo_DimProductCategoryClass clsdbo_DimProductCategory) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string deleteStatement = "DELETE FROM " + " [dbo].[DimProductCategory] " + "WHERE " + " [ProductCategoryKey] = @OldProductCategoryKey " + " AND ((@OldProductCategoryAlternateKey IS NULL AND [ProductCategoryAlternateKey] IS NULL) OR [ProductCategoryAlternateKey] = @OldProductCategoryAlternateKey) " + " AND [EnglishProductCategoryName] = @OldEnglishProductCategoryName " + " AND [SpanishProductCategoryName] = @OldSpanishProductCategoryName " + " AND [FrenchProductCategoryName] = @OldFrenchProductCategoryName " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldProductCategoryKey", clsdbo_DimProductCategory.ProductCategoryKey); if (clsdbo_DimProductCategory.ProductCategoryAlternateKey.HasValue == true) { deleteCommand.Parameters.AddWithValue("@OldProductCategoryAlternateKey", clsdbo_DimProductCategory.ProductCategoryAlternateKey); } else { deleteCommand.Parameters.AddWithValue("@OldProductCategoryAlternateKey", DBNull.Value); } deleteCommand.Parameters.AddWithValue("@OldEnglishProductCategoryName", clsdbo_DimProductCategory.EnglishProductCategoryName); deleteCommand.Parameters.AddWithValue("@OldSpanishProductCategoryName", clsdbo_DimProductCategory.SpanishProductCategoryName); deleteCommand.Parameters.AddWithValue("@OldFrenchProductCategoryName", clsdbo_DimProductCategory.FrenchProductCategoryName); try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }
public static dbo_DimProductCategoryClass Select_Record(dbo_DimProductCategoryClass clsdbo_DimProductCategoryPara) { dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string selectStatement = "SELECT " + " [ProductCategoryKey] " + " ,[ProductCategoryAlternateKey] " + " ,[EnglishProductCategoryName] " + " ,[SpanishProductCategoryName] " + " ,[FrenchProductCategoryName] " + "FROM " + " [dbo].[DimProductCategory] " + "WHERE " + " [ProductCategoryKey] = @ProductCategoryKey " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@ProductCategoryKey", clsdbo_DimProductCategoryPara.ProductCategoryKey); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsdbo_DimProductCategory.ProductCategoryKey = System.Convert.ToInt32(reader["ProductCategoryKey"]); clsdbo_DimProductCategory.ProductCategoryAlternateKey = reader["ProductCategoryAlternateKey"] is DBNull ? null : (Int32?)reader["ProductCategoryAlternateKey"]; clsdbo_DimProductCategory.EnglishProductCategoryName = System.Convert.ToString(reader["EnglishProductCategoryName"]); clsdbo_DimProductCategory.SpanishProductCategoryName = System.Convert.ToString(reader["SpanishProductCategoryName"]); clsdbo_DimProductCategory.FrenchProductCategoryName = System.Convert.ToString(reader["FrenchProductCategoryName"]); } else { clsdbo_DimProductCategory = null; } reader.Close(); } catch (SqlException) { return(clsdbo_DimProductCategory); } finally { connection.Close(); } return(clsdbo_DimProductCategory); }
private void UpdateRecord() { try { TextBox txtProductCategoryKey = (TextBox)grddbo_DimProductCategory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtProductCategoryKey"); TextBox txtProductCategoryAlternateKey = (TextBox)grddbo_DimProductCategory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtProductCategoryAlternateKey"); TextBox txtEnglishProductCategoryName = (TextBox)grddbo_DimProductCategory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtEnglishProductCategoryName"); TextBox txtSpanishProductCategoryName = (TextBox)grddbo_DimProductCategory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtSpanishProductCategoryName"); TextBox txtFrenchProductCategoryName = (TextBox)grddbo_DimProductCategory.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtFrenchProductCategoryName"); dbo_DimProductCategoryClass oclsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); oclsdbo_DimProductCategory.ProductCategoryKey = System.Convert.ToInt32(txtProductCategoryKey.Text); oclsdbo_DimProductCategory = dbo_DimProductCategoryDataClass.Select_Record(oclsdbo_DimProductCategory); if (VerifyData() == true) { if (string.IsNullOrEmpty(txtProductCategoryAlternateKey.Text)) { clsdbo_DimProductCategory.ProductCategoryAlternateKey = null; } else { clsdbo_DimProductCategory.ProductCategoryAlternateKey = System.Convert.ToInt32(txtProductCategoryAlternateKey.Text); } clsdbo_DimProductCategory.EnglishProductCategoryName = System.Convert.ToString(txtEnglishProductCategoryName.Text); clsdbo_DimProductCategory.SpanishProductCategoryName = System.Convert.ToString(txtSpanishProductCategoryName.Text); clsdbo_DimProductCategory.FrenchProductCategoryName = System.Convert.ToString(txtFrenchProductCategoryName.Text); bool bSucess = false; bSucess = dbo_DimProductCategoryDataClass.Update(oclsdbo_DimProductCategory, clsdbo_DimProductCategory); if (bSucess == true) { Session.Remove("dvdbo_DimProductCategory"); grddbo_DimProductCategory.EditIndex = -1; LoadGriddbo_DimProductCategory(); } else { ec.ShowMessage(" Update failed. ", " Dbo. Dim Product Category "); } } } catch { } }
private void DeleteRecord() { dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); Label lblProductCategoryKey = (Label)grddbo_DimProductCategory.Rows[Convert.ToInt32(Session["Row"])].FindControl("lblProductCategoryKey"); clsdbo_DimProductCategory.ProductCategoryKey = System.Convert.ToInt32(lblProductCategoryKey.Text); clsdbo_DimProductCategory = dbo_DimProductCategoryDataClass.Select_Record(clsdbo_DimProductCategory); bool bSucess = false; bSucess = dbo_DimProductCategoryDataClass.Delete(clsdbo_DimProductCategory); if (bSucess == true) { Session.Remove("dvdbo_DimProductCategory"); LoadGriddbo_DimProductCategory(); } else { ec.ShowMessage(" Delete failed. ", " Dbo. Dim Product Category "); } }
private void InsertRecord() { try { TextBox txtNewProductCategoryAlternateKey = (TextBox)grddbo_DimProductCategory.FooterRow.FindControl("txtNewProductCategoryAlternateKey"); TextBox txtNewEnglishProductCategoryName = (TextBox)grddbo_DimProductCategory.FooterRow.FindControl("txtNewEnglishProductCategoryName"); TextBox txtNewSpanishProductCategoryName = (TextBox)grddbo_DimProductCategory.FooterRow.FindControl("txtNewSpanishProductCategoryName"); TextBox txtNewFrenchProductCategoryName = (TextBox)grddbo_DimProductCategory.FooterRow.FindControl("txtNewFrenchProductCategoryName"); dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); if (VerifyDataNew() == true) { if (string.IsNullOrEmpty(txtNewProductCategoryAlternateKey.Text)) { clsdbo_DimProductCategory.ProductCategoryAlternateKey = null; } else { clsdbo_DimProductCategory.ProductCategoryAlternateKey = System.Convert.ToInt32(txtNewProductCategoryAlternateKey.Text); } clsdbo_DimProductCategory.EnglishProductCategoryName = System.Convert.ToString(txtNewEnglishProductCategoryName.Text); clsdbo_DimProductCategory.SpanishProductCategoryName = System.Convert.ToString(txtNewSpanishProductCategoryName.Text); clsdbo_DimProductCategory.FrenchProductCategoryName = System.Convert.ToString(txtNewFrenchProductCategoryName.Text); bool bSucess = false; bSucess = dbo_DimProductCategoryDataClass.Add(clsdbo_DimProductCategory); if (bSucess == true) { Session.Remove("dvdbo_DimProductCategory"); LoadGriddbo_DimProductCategory(); } else { ec.ShowMessage(" Insert failed. ", " Dbo. Dim Product Category "); } } } catch { } }
private void InsertRecord() { dbo_DimProductCategoryClass clsdbo_DimProductCategory = new dbo_DimProductCategoryClass(); if (VerifyData() == true) { SetData(clsdbo_DimProductCategory); bool bSucess = false; bSucess = dbo_DimProductCategoryDataClass.Add(clsdbo_DimProductCategory); if (bSucess == true) { pnlForm.Visible = false; pnlSave.Visible = false; pnlGrid.Visible = true; lblMode.InnerText = ""; Session.Remove("dvdbo_DimProductCategory"); LoadGriddbo_DimProductCategory(); } else { ec.ShowMessage(" Insert failed. ", " Dbo. Dim Product Category "); } } }
public static bool Update(dbo_DimProductCategoryClass olddbo_DimProductCategoryClass, dbo_DimProductCategoryClass newdbo_DimProductCategoryClass) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string updateStatement = "UPDATE " + " [dbo].[DimProductCategory] " + "SET " + " [ProductCategoryAlternateKey] = @NewProductCategoryAlternateKey " + " ,[EnglishProductCategoryName] = @NewEnglishProductCategoryName " + " ,[SpanishProductCategoryName] = @NewSpanishProductCategoryName " + " ,[FrenchProductCategoryName] = @NewFrenchProductCategoryName " + "WHERE " + " [ProductCategoryKey] = @OldProductCategoryKey " + " AND ((@OldProductCategoryAlternateKey IS NULL AND [ProductCategoryAlternateKey] IS NULL) OR [ProductCategoryAlternateKey] = @OldProductCategoryAlternateKey) " + " AND [EnglishProductCategoryName] = @OldEnglishProductCategoryName " + " AND [SpanishProductCategoryName] = @OldSpanishProductCategoryName " + " AND [FrenchProductCategoryName] = @OldFrenchProductCategoryName " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; if (newdbo_DimProductCategoryClass.ProductCategoryAlternateKey.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewProductCategoryAlternateKey", newdbo_DimProductCategoryClass.ProductCategoryAlternateKey); } else { updateCommand.Parameters.AddWithValue("@NewProductCategoryAlternateKey", DBNull.Value); } updateCommand.Parameters.AddWithValue("@NewEnglishProductCategoryName", newdbo_DimProductCategoryClass.EnglishProductCategoryName); updateCommand.Parameters.AddWithValue("@NewSpanishProductCategoryName", newdbo_DimProductCategoryClass.SpanishProductCategoryName); updateCommand.Parameters.AddWithValue("@NewFrenchProductCategoryName", newdbo_DimProductCategoryClass.FrenchProductCategoryName); updateCommand.Parameters.AddWithValue("@OldProductCategoryKey", olddbo_DimProductCategoryClass.ProductCategoryKey); if (olddbo_DimProductCategoryClass.ProductCategoryAlternateKey.HasValue == true) { updateCommand.Parameters.AddWithValue("@OldProductCategoryAlternateKey", olddbo_DimProductCategoryClass.ProductCategoryAlternateKey); } else { updateCommand.Parameters.AddWithValue("@OldProductCategoryAlternateKey", DBNull.Value); } updateCommand.Parameters.AddWithValue("@OldEnglishProductCategoryName", olddbo_DimProductCategoryClass.EnglishProductCategoryName); updateCommand.Parameters.AddWithValue("@OldSpanishProductCategoryName", olddbo_DimProductCategoryClass.SpanishProductCategoryName); updateCommand.Parameters.AddWithValue("@OldFrenchProductCategoryName", olddbo_DimProductCategoryClass.FrenchProductCategoryName); try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }