private void GetData() { ClearRecord(); dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(Session["CurrencyKey"]); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(Session["DateKey"]); clsdbo_FactCurrencyRate = dbo_FactCurrencyRateDataClass.Select_Record(clsdbo_FactCurrencyRate); if ((clsdbo_FactCurrencyRate != null)) { try { txtCurrencyKey.SelectedValue = System.Convert.ToString(clsdbo_FactCurrencyRate.CurrencyKey); txtDateKey.SelectedValue = System.Convert.ToString(clsdbo_FactCurrencyRate.DateKey); txtAverageRate.Text = System.Convert.ToString(clsdbo_FactCurrencyRate.AverageRate); txtEndOfDayRate.Text = System.Convert.ToString(clsdbo_FactCurrencyRate.EndOfDayRate); if (clsdbo_FactCurrencyRate.Date == null) { txtDate.Text = DateTime.Now.ToString(); } else { txtDate.Text = System.Convert.ToDateTime(clsdbo_FactCurrencyRate.Date).ToShortDateString(); } } catch (Exception ex) { ec.ShowMessage(ex.Message, " Dbo. Fact Currency Rate "); } } }
private void DeleteRecord() { dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(Session["CurrencyKey"]); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(Session["DateKey"]); SetData(clsdbo_FactCurrencyRate); bool bSucess = false; bSucess = dbo_FactCurrencyRateDataClass.Delete(clsdbo_FactCurrencyRate); if (bSucess == true) { pnlForm.Visible = false; pnlSave.Visible = false; pnlGrid.Visible = true; pnlDelete.Visible = false; lblMode.InnerText = ""; Session.Remove("dvdbo_FactCurrencyRate"); LoadGriddbo_FactCurrencyRate(); } else { ec.ShowMessage(" Delete failed. ", " Dbo. Fact Currency Rate "); } }
public static bool Add(dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string insertStatement = "INSERT " + " [dbo].[FactCurrencyRate] " + " ( " + " [CurrencyKey] " + " ,[DateKey] " + " ,[AverageRate] " + " ,[EndOfDayRate] " + " ,[Date] " + " ) " + "VALUES " + " ( " + " @CurrencyKey " + " ,@DateKey " + " ,@AverageRate " + " ,@EndOfDayRate " + " ,@Date " + " ) " + ""; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.CommandType = CommandType.Text; insertCommand.Parameters.AddWithValue("@CurrencyKey", clsdbo_FactCurrencyRate.CurrencyKey); insertCommand.Parameters.AddWithValue("@DateKey", clsdbo_FactCurrencyRate.DateKey); insertCommand.Parameters.AddWithValue("@AverageRate", clsdbo_FactCurrencyRate.AverageRate); insertCommand.Parameters.AddWithValue("@EndOfDayRate", clsdbo_FactCurrencyRate.EndOfDayRate); if (clsdbo_FactCurrencyRate.Date.HasValue == true) { insertCommand.Parameters.AddWithValue("@Date", clsdbo_FactCurrencyRate.Date); } else { insertCommand.Parameters.AddWithValue("@Date", DBNull.Value); } try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }
public static dbo_FactCurrencyRateClass Select_Record(dbo_FactCurrencyRateClass clsdbo_FactCurrencyRatePara) { dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string selectStatement = "SELECT " + " [CurrencyKey] " + " ,[DateKey] " + " ,[AverageRate] " + " ,[EndOfDayRate] " + " ,[Date] " + "FROM " + " [dbo].[FactCurrencyRate] " + "WHERE " + " [CurrencyKey] = @CurrencyKey " + " AND [DateKey] = @DateKey " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@CurrencyKey", clsdbo_FactCurrencyRatePara.CurrencyKey); selectCommand.Parameters.AddWithValue("@DateKey", clsdbo_FactCurrencyRatePara.DateKey); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(reader["CurrencyKey"]); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(reader["DateKey"]); clsdbo_FactCurrencyRate.AverageRate = System.Convert.ToDecimal(reader["AverageRate"]); clsdbo_FactCurrencyRate.EndOfDayRate = System.Convert.ToDecimal(reader["EndOfDayRate"]); clsdbo_FactCurrencyRate.Date = reader["Date"] is DBNull ? null : (DateTime?)reader["Date"]; } else { clsdbo_FactCurrencyRate = null; } reader.Close(); } catch (SqlException) { return(clsdbo_FactCurrencyRate); } finally { connection.Close(); } return(clsdbo_FactCurrencyRate); }
public static bool Delete(dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string deleteStatement = "DELETE FROM " + " [dbo].[FactCurrencyRate] " + "WHERE " + " [CurrencyKey] = @OldCurrencyKey " + " AND [DateKey] = @OldDateKey " + " AND [AverageRate] = @OldAverageRate " + " AND [EndOfDayRate] = @OldEndOfDayRate " + " AND ((@OldDate IS NULL AND [Date] IS NULL) OR [Date] = @OldDate) " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldCurrencyKey", clsdbo_FactCurrencyRate.CurrencyKey); deleteCommand.Parameters.AddWithValue("@OldDateKey", clsdbo_FactCurrencyRate.DateKey); deleteCommand.Parameters.AddWithValue("@OldAverageRate", clsdbo_FactCurrencyRate.AverageRate); deleteCommand.Parameters.AddWithValue("@OldEndOfDayRate", clsdbo_FactCurrencyRate.EndOfDayRate); if (clsdbo_FactCurrencyRate.Date.HasValue == true) { deleteCommand.Parameters.AddWithValue("@OldDate", clsdbo_FactCurrencyRate.Date); } else { deleteCommand.Parameters.AddWithValue("@OldDate", 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 Boolean VerifyDataNew() { DropDownList txtNewCurrencyKey = (DropDownList)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewCurrencyKey"); DropDownList txtNewDateKey = (DropDownList)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewDateKey"); TextBox txtNewAverageRate = (TextBox)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewAverageRate"); TextBox txtNewEndOfDayRate = (TextBox)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewEndOfDayRate"); TextBox txtNewDate = (TextBox)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewDate"); if (txtNewCurrencyKey.Text == "") { ec.ShowMessage(" Currency Key is Required. ", " Dbo. Fact Currency Rate "); txtNewCurrencyKey.Focus(); return(false); } if (txtNewDateKey.Text == "") { ec.ShowMessage(" Date Key is Required. ", " Dbo. Fact Currency Rate "); txtNewDateKey.Focus(); return(false); } if (txtNewAverageRate.Text == "") { ec.ShowMessage(" Average Rate is Required. ", " Dbo. Fact Currency Rate "); txtNewAverageRate.Focus(); return(false); } if (txtNewEndOfDayRate.Text == "") { ec.ShowMessage(" End Of Day Rate is Required. ", " Dbo. Fact Currency Rate "); txtNewEndOfDayRate.Focus(); return(false); } if ( txtNewCurrencyKey.SelectedIndex != -1 && txtNewDateKey.SelectedIndex != -1 ) { dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(txtNewCurrencyKey.SelectedValue); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(txtNewDateKey.SelectedValue); clsdbo_FactCurrencyRate = dbo_FactCurrencyRateDataClass.Select_Record(clsdbo_FactCurrencyRate); if (clsdbo_FactCurrencyRate != null) { ec.ShowMessage(" Record already exists. ", " Dbo. Fact Currency Rate "); txtNewCurrencyKey.Focus(); return(false); } } return(true); }
private void SetData(dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate) { clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(txtCurrencyKey.SelectedValue); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(txtDateKey.SelectedValue); clsdbo_FactCurrencyRate.AverageRate = System.Convert.ToDecimal(txtAverageRate.Text); clsdbo_FactCurrencyRate.EndOfDayRate = System.Convert.ToDecimal(txtEndOfDayRate.Text); if (string.IsNullOrEmpty(txtDate.Text)) { clsdbo_FactCurrencyRate.Date = null; } else { clsdbo_FactCurrencyRate.Date = System.Convert.ToDateTime(txtDate.Text); } }
private void Edit() { try { dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); Label lblCurrencyKey = (Label)grddbo_FactCurrencyRate.Rows[grddbo_FactCurrencyRate.EditIndex].FindControl("lblCurrencyKey"); clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(lblCurrencyKey.Text); Label lblDateKey = (Label)grddbo_FactCurrencyRate.Rows[grddbo_FactCurrencyRate.EditIndex].FindControl("lblDateKey"); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(lblDateKey.Text); clsdbo_FactCurrencyRate = dbo_FactCurrencyRateDataClass.Select_Record(clsdbo_FactCurrencyRate); Session["CurrencyKey_SelectedValue"] = clsdbo_FactCurrencyRate.CurrencyKey; Session["DateKey_SelectedValue"] = clsdbo_FactCurrencyRate.DateKey; LoadGriddbo_FactCurrencyRate(); } catch { } }
private void UpdateRecord() { try { DropDownList txtCurrencyKey = (DropDownList)grddbo_FactCurrencyRate.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtCurrencyKey"); DropDownList txtDateKey = (DropDownList)grddbo_FactCurrencyRate.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtDateKey"); TextBox txtAverageRate = (TextBox)grddbo_FactCurrencyRate.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtAverageRate"); TextBox txtEndOfDayRate = (TextBox)grddbo_FactCurrencyRate.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtEndOfDayRate"); TextBox txtDate = (TextBox)grddbo_FactCurrencyRate.Rows[Convert.ToInt32(Session["Row"])].FindControl("txtDate"); dbo_FactCurrencyRateClass oclsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); oclsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(txtCurrencyKey.Text); oclsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(txtDateKey.Text); oclsdbo_FactCurrencyRate = dbo_FactCurrencyRateDataClass.Select_Record(oclsdbo_FactCurrencyRate); if (VerifyData() == true) { clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(txtCurrencyKey.SelectedValue); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(txtDateKey.SelectedValue); clsdbo_FactCurrencyRate.AverageRate = System.Convert.ToDecimal(txtAverageRate.Text); clsdbo_FactCurrencyRate.EndOfDayRate = System.Convert.ToDecimal(txtEndOfDayRate.Text); if (string.IsNullOrEmpty(txtDate.Text)) { clsdbo_FactCurrencyRate.Date = null; } else { clsdbo_FactCurrencyRate.Date = System.Convert.ToDateTime(txtDate.Text); } bool bSucess = false; bSucess = dbo_FactCurrencyRateDataClass.Update(oclsdbo_FactCurrencyRate, clsdbo_FactCurrencyRate); if (bSucess == true) { Session.Remove("dvdbo_FactCurrencyRate"); grddbo_FactCurrencyRate.EditIndex = -1; LoadGriddbo_FactCurrencyRate(); } else { ec.ShowMessage(" Update failed. ", " Dbo. Fact Currency Rate "); } } } catch { } }
private Boolean VerifyData() { if (txtCurrencyKey.Text == "") { ec.ShowMessage(" Currency Key is Required. ", " Dbo. Fact Currency Rate "); txtCurrencyKey.Focus(); return(false); } if (txtDateKey.Text == "") { ec.ShowMessage(" Date Key is Required. ", " Dbo. Fact Currency Rate "); txtDateKey.Focus(); return(false); } if (txtAverageRate.Text == "") { ec.ShowMessage(" Average Rate is Required. ", " Dbo. Fact Currency Rate "); txtAverageRate.Focus(); return(false); } if (txtEndOfDayRate.Text == "") { ec.ShowMessage(" End Of Day Rate is Required. ", " Dbo. Fact Currency Rate "); txtEndOfDayRate.Focus(); return(false); } if ( txtCurrencyKey.SelectedIndex != -1 && txtDateKey.SelectedIndex != -1 ) { dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(txtCurrencyKey.SelectedValue); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(txtDateKey.SelectedValue); clsdbo_FactCurrencyRate = dbo_FactCurrencyRateDataClass.Select_Record(clsdbo_FactCurrencyRate); if (clsdbo_FactCurrencyRate != null && (String)Session["Mode"] == "Add") { ec.ShowMessage(" Record already exists. ", " Dbo. Fact Currency Rate "); txtCurrencyKey.Focus(); return(false); } } return(true); }
private void InsertRecord() { try { DropDownList txtNewCurrencyKey = (DropDownList)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewCurrencyKey"); DropDownList txtNewDateKey = (DropDownList)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewDateKey"); TextBox txtNewAverageRate = (TextBox)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewAverageRate"); TextBox txtNewEndOfDayRate = (TextBox)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewEndOfDayRate"); TextBox txtNewDate = (TextBox)grddbo_FactCurrencyRate.FooterRow.FindControl("txtNewDate"); dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); if (VerifyDataNew() == true) { clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(txtNewCurrencyKey.SelectedValue); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(txtNewDateKey.SelectedValue); clsdbo_FactCurrencyRate.AverageRate = System.Convert.ToDecimal(txtNewAverageRate.Text); clsdbo_FactCurrencyRate.EndOfDayRate = System.Convert.ToDecimal(txtNewEndOfDayRate.Text); if (string.IsNullOrEmpty(txtNewDate.Text)) { clsdbo_FactCurrencyRate.Date = null; } else { clsdbo_FactCurrencyRate.Date = System.Convert.ToDateTime(txtNewDate.Text); } bool bSucess = false; bSucess = dbo_FactCurrencyRateDataClass.Add(clsdbo_FactCurrencyRate); if (bSucess == true) { Session.Remove("dvdbo_FactCurrencyRate"); LoadGriddbo_FactCurrencyRate(); } else { ec.ShowMessage(" Insert failed. ", " Dbo. Fact Currency Rate "); } } } catch { } }
private void DeleteRecord() { dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); Label lblCurrencyKey = (Label)grddbo_FactCurrencyRate.Rows[Convert.ToInt32(Session["Row"])].FindControl("lblCurrencyKey"); clsdbo_FactCurrencyRate.CurrencyKey = System.Convert.ToInt32(lblCurrencyKey.Text); Label lblDateKey = (Label)grddbo_FactCurrencyRate.Rows[Convert.ToInt32(Session["Row"])].FindControl("lblDateKey"); clsdbo_FactCurrencyRate.DateKey = System.Convert.ToInt32(lblDateKey.Text); clsdbo_FactCurrencyRate = dbo_FactCurrencyRateDataClass.Select_Record(clsdbo_FactCurrencyRate); bool bSucess = false; bSucess = dbo_FactCurrencyRateDataClass.Delete(clsdbo_FactCurrencyRate); if (bSucess == true) { Session.Remove("dvdbo_FactCurrencyRate"); LoadGriddbo_FactCurrencyRate(); } else { ec.ShowMessage(" Delete failed. ", " Dbo. Fact Currency Rate "); } }
private void InsertRecord() { dbo_FactCurrencyRateClass clsdbo_FactCurrencyRate = new dbo_FactCurrencyRateClass(); if (VerifyData() == true) { SetData(clsdbo_FactCurrencyRate); bool bSucess = false; bSucess = dbo_FactCurrencyRateDataClass.Add(clsdbo_FactCurrencyRate); if (bSucess == true) { pnlForm.Visible = false; pnlSave.Visible = false; pnlGrid.Visible = true; lblMode.InnerText = ""; Session.Remove("dvdbo_FactCurrencyRate"); LoadGriddbo_FactCurrencyRate(); } else { ec.ShowMessage(" Insert failed. ", " Dbo. Fact Currency Rate "); } } }
public static bool Update(dbo_FactCurrencyRateClass olddbo_FactCurrencyRateClass, dbo_FactCurrencyRateClass newdbo_FactCurrencyRateClass) { SqlConnection connection = AdventureWorksDW2012DataClass.GetConnection(); string updateStatement = "UPDATE " + " [dbo].[FactCurrencyRate] " + "SET " + " [CurrencyKey] = @NewCurrencyKey " + " ,[DateKey] = @NewDateKey " + " ,[AverageRate] = @NewAverageRate " + " ,[EndOfDayRate] = @NewEndOfDayRate " + " ,[Date] = @NewDate " + "WHERE " + " [CurrencyKey] = @OldCurrencyKey " + " AND [DateKey] = @OldDateKey " + " AND [AverageRate] = @OldAverageRate " + " AND [EndOfDayRate] = @OldEndOfDayRate " + " AND ((@OldDate IS NULL AND [Date] IS NULL) OR [Date] = @OldDate) " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; updateCommand.Parameters.AddWithValue("@NewCurrencyKey", newdbo_FactCurrencyRateClass.CurrencyKey); updateCommand.Parameters.AddWithValue("@NewDateKey", newdbo_FactCurrencyRateClass.DateKey); updateCommand.Parameters.AddWithValue("@NewAverageRate", newdbo_FactCurrencyRateClass.AverageRate); updateCommand.Parameters.AddWithValue("@NewEndOfDayRate", newdbo_FactCurrencyRateClass.EndOfDayRate); if (newdbo_FactCurrencyRateClass.Date.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewDate", newdbo_FactCurrencyRateClass.Date); } else { updateCommand.Parameters.AddWithValue("@NewDate", DBNull.Value); } updateCommand.Parameters.AddWithValue("@OldCurrencyKey", olddbo_FactCurrencyRateClass.CurrencyKey); updateCommand.Parameters.AddWithValue("@OldDateKey", olddbo_FactCurrencyRateClass.DateKey); updateCommand.Parameters.AddWithValue("@OldAverageRate", olddbo_FactCurrencyRateClass.AverageRate); updateCommand.Parameters.AddWithValue("@OldEndOfDayRate", olddbo_FactCurrencyRateClass.EndOfDayRate); if (olddbo_FactCurrencyRateClass.Date.HasValue == true) { updateCommand.Parameters.AddWithValue("@OldDate", olddbo_FactCurrencyRateClass.Date); } else { updateCommand.Parameters.AddWithValue("@OldDate", DBNull.Value); } try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }