public static dbo_CNDNClass Select_Record(String SAM_CN_DN_No) { dbo_CNDNClass clsdbo_CNDN = new dbo_CNDNClass(); SqlConnection connection = SAMDataClass.GetConnection(); string selectProcedure = "[CNDNSelect]"; SqlCommand selectCommand = new SqlCommand(selectProcedure, connection); selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.Parameters.AddWithValue("@SAM_CN_DN_No", SAM_CN_DN_No); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsdbo_CNDN.SAM_CN_DN_No = reader["SAM_CN_DN_No"] is DBNull ? null : reader["SAM_CN_DN_No"].ToString(); clsdbo_CNDN.CV_Code = reader["CV_Code"] is DBNull ? null : reader["CV_Code"].ToString(); clsdbo_CNDN.SAM_CN_DN_Type = reader["SAM_CN_DN_Type"] is DBNull ? null : reader["SAM_CN_DN_Type"].ToString(); clsdbo_CNDN.SAM_CN_DN_Date = reader["SAM_CN_DN_Date"] is DBNull ? null : (DateTime?)reader["SAM_CN_DN_Date"]; clsdbo_CNDN.SAM_CN_DN_Quantity = reader["SAM_CN_DN_Quantity"] is DBNull ? null : (Int16?)reader["SAM_CN_DN_Quantity"]; clsdbo_CNDN.SAM_CN_DN_Status = reader["SAM_CN_DN_Status"] is DBNull ? null : reader["SAM_CN_DN_Status"].ToString(); clsdbo_CNDN.Billing_ID = reader["Billing_ID"] is DBNull ? null : reader["Billing_ID"].ToString(); clsdbo_CNDN.Invoice_No = reader["Invoice_No"] is DBNull ? null : reader["Invoice_No"].ToString(); clsdbo_CNDN.Invoice_Date = reader["Invoice_Date"] is DBNull ? null : (DateTime?)reader["Invoice_Date"]; } else { clsdbo_CNDN = null; } reader.Close(); } catch (SqlException ex) { logger.Error(ex.Message); return(clsdbo_CNDN); } finally { connection.Close(); } return(clsdbo_CNDN); }
public static bool Update(dbo_CNDNClass newdbo_CNDNClass) { SqlConnection connection = SAMDataClass.GetConnection(); string updateProcedure = "[CNDNUpdate]"; SqlCommand updateCommand = new SqlCommand(updateProcedure, connection); updateCommand.CommandType = CommandType.StoredProcedure; if (newdbo_CNDNClass.SAM_CN_DN_No != null) { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_No", newdbo_CNDNClass.SAM_CN_DN_No); } else { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_No", DBNull.Value); } if (newdbo_CNDNClass.CV_Code != null) { updateCommand.Parameters.AddWithValue("@NewCV_Code", newdbo_CNDNClass.CV_Code); } else { updateCommand.Parameters.AddWithValue("@NewCV_Code", DBNull.Value); } if (newdbo_CNDNClass.SAM_CN_DN_Type != null) { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Type", newdbo_CNDNClass.SAM_CN_DN_Type); } else { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Type", DBNull.Value); } if (newdbo_CNDNClass.SAM_CN_DN_Date.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Date", newdbo_CNDNClass.SAM_CN_DN_Date); } else { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Date", DBNull.Value); } if (newdbo_CNDNClass.SAM_CN_DN_Quantity.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Quantity", newdbo_CNDNClass.SAM_CN_DN_Quantity); } else { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Quantity", DBNull.Value); } if (newdbo_CNDNClass.SAM_CN_DN_Status != null) { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Status", newdbo_CNDNClass.SAM_CN_DN_Status); } else { updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_Status", DBNull.Value); } if (newdbo_CNDNClass.Billing_ID != null) { updateCommand.Parameters.AddWithValue("@NewBilling_ID", newdbo_CNDNClass.Billing_ID); } else { updateCommand.Parameters.AddWithValue("@NewBilling_ID", DBNull.Value); } if (newdbo_CNDNClass.Invoice_No != null) { updateCommand.Parameters.AddWithValue("@NewInvoice_No", newdbo_CNDNClass.Invoice_No); } else { updateCommand.Parameters.AddWithValue("@NewInvoice_No", DBNull.Value); } if (newdbo_CNDNClass.Invoice_Date.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewInvoice_Date", newdbo_CNDNClass.Invoice_Date); } else { updateCommand.Parameters.AddWithValue("@NewInvoice_Date", DBNull.Value); } updateCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int); updateCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output; try { connection.Open(); updateCommand.ExecuteNonQuery(); int count = System.Convert.ToInt32(updateCommand.Parameters["@ReturnValue"].Value); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { logger.Error(ex.Message); return(false); } finally { connection.Close(); } }
public static bool Add(dbo_CNDNClass clsdbo_CNDN, String Created_By) { logger.Info(System.Web.HttpContext.Current.Request.Cookies["User_ID"].Value == null ? string.Empty : System.Web.HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name); SqlConnection connection = SAMDataClass.GetConnection(); string insertProcedure = "[CNDNInsert]"; SqlCommand insertCommand = new SqlCommand(insertProcedure, connection); insertCommand.CommandType = CommandType.StoredProcedure; if (clsdbo_CNDN.SAM_CN_DN_No != null) { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_No", clsdbo_CNDN.SAM_CN_DN_No); } else { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_No", DBNull.Value); } if (clsdbo_CNDN.CV_Code != null) { insertCommand.Parameters.AddWithValue("@CV_Code", clsdbo_CNDN.CV_Code); } else { insertCommand.Parameters.AddWithValue("@CV_Code", DBNull.Value); } if (clsdbo_CNDN.SAM_CN_DN_Type != null) { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Type", clsdbo_CNDN.SAM_CN_DN_Type); } else { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Type", DBNull.Value); } if (clsdbo_CNDN.SAM_CN_DN_Date.HasValue == true) { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Date", clsdbo_CNDN.SAM_CN_DN_Date); } else { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Date", DBNull.Value); } if (clsdbo_CNDN.SAM_CN_DN_Quantity.HasValue == true) { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Quantity", clsdbo_CNDN.SAM_CN_DN_Quantity); } else { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Quantity", DBNull.Value); } if (clsdbo_CNDN.SAM_CN_DN_Status != null) { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Status", clsdbo_CNDN.SAM_CN_DN_Status); } else { insertCommand.Parameters.AddWithValue("@SAM_CN_DN_Status", DBNull.Value); } if (clsdbo_CNDN.Billing_ID != null) { insertCommand.Parameters.AddWithValue("@Billing_ID", clsdbo_CNDN.Billing_ID); } else { insertCommand.Parameters.AddWithValue("@Billing_ID", DBNull.Value); } if (clsdbo_CNDN.Invoice_No != null) { insertCommand.Parameters.AddWithValue("@Invoice_No", clsdbo_CNDN.Invoice_No); } else { insertCommand.Parameters.AddWithValue("@Invoice_No", DBNull.Value); } if (clsdbo_CNDN.Invoice_Date.HasValue == true) { insertCommand.Parameters.AddWithValue("@Invoice_Date", clsdbo_CNDN.Invoice_Date); } else { insertCommand.Parameters.AddWithValue("@Invoice_Date", DBNull.Value); } if (!string.IsNullOrEmpty(Created_By)) { insertCommand.Parameters.AddWithValue("@Created_By", Created_By); } else { insertCommand.Parameters.AddWithValue("@Created_By", DBNull.Value); } insertCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int); insertCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output; try { connection.Open(); insertCommand.ExecuteNonQuery(); int count = System.Convert.ToInt32(insertCommand.Parameters["@ReturnValue"].Value); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { logger.Error(ex.Message); return(false); } finally { connection.Close(); } }