public Stock_InOut_Master getStockInOutMaster(SqlConnection con, int StockMID) { Stock_InOut_Master objSM = null; try { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM T_Stock_InOut_Master WHERE StockMID=" + StockMID.ToString(), con); DataTable dt = new DataTable(); da.Fill(dt); da.Dispose(); if (dt.Rows.Count == 0) { return(null); } objSM = new Stock_InOut_Master(); objSM.StockMID = Convert.ToInt32(dt.Rows[0].Field <object>("StockMID")); objSM.TransType = dt.Rows[0].Field <string>("TransType"); objSM.TransDate = dt.Rows[0].Field <DateTime>("TransDate"); objSM.VoucherNo = dt.Rows[0].Field <string>("VoucherNo"); objSM.ChalanNo = dt.Rows[0].Field <string>("ChalanNo"); objSM.ChalanDate = dt.Rows[0].Field <object>("ChalanDate") == DBNull.Value || dt.Rows[0].Field <object>("ChalanDate") == null ? new DateTime(1900, 1, 1) : dt.Rows[0].Field <DateTime>("ChalanDate"); objSM.CustSupplID = dt.Rows[0].Field <object>("CustSupplID") == DBNull.Value || dt.Rows[0].Field <object>("CustSupplID") == null ? -1 : dt.Rows[0].Field <int>("CustSupplID"); objSM.RefID = dt.Rows[0].Field <object>("RefID") == DBNull.Value || dt.Rows[0].Field <object>("RefID") == null ? -1 : dt.Rows[0].Field <int>("RefID"); objSM.Remarks = dt.Rows[0].Field <object>("Remarks") == DBNull.Value || dt.Rows[0].Field <object>("Remarks") == null ? string.Empty : dt.Rows[0].Field <string>("Remarks"); objSM.Module = dt.Rows[0].Field <object>("Module") == DBNull.Value || dt.Rows[0].Field <object>("Module") == null ? string.Empty : dt.Rows[0].Field <string>("Module"); } catch (Exception ex) { throw ex; } return(objSM); }
public int SaveUpdateStockInOutMaster(Stock_InOut_Master obInOutMaster, SqlConnection con, SqlTransaction trans) { int StockMID = 0; SqlCommand com = null; try { com = new SqlCommand("spSaveUpdateStockInOutMaster", con, trans); com.CommandType = CommandType.StoredProcedure; com.Parameters.Add("@StockMID", SqlDbType.Int).Value = obInOutMaster.StockMID; com.Parameters.Add("@TransType", SqlDbType.VarChar, 100).Value = obInOutMaster.TransType; com.Parameters.Add("@TransDate", SqlDbType.DateTime).Value = obInOutMaster.TransDate; com.Parameters.Add("@VoucherNo", SqlDbType.VarChar, 100).Value = obInOutMaster.VoucherNo; if (obInOutMaster.ChalanNo == "") { com.Parameters.Add("@ChalanNo", SqlDbType.VarChar, 100).Value = DBNull.Value; } else { com.Parameters.Add("@ChalanNo", SqlDbType.VarChar, 100).Value = obInOutMaster.ChalanNo; } if (obInOutMaster.ChalanDate == new DateTime(1900, 1, 1)) { com.Parameters.Add("@ChalanDate", SqlDbType.DateTime).Value = DBNull.Value; } else { com.Parameters.Add("@ChalanDate", SqlDbType.DateTime).Value = obInOutMaster.ChalanDate; } if (obInOutMaster.CustSupplID <= 0) { com.Parameters.Add("@CustSupplID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@CustSupplID", SqlDbType.Int).Value = obInOutMaster.CustSupplID; } if (obInOutMaster.RefID <= 0) { com.Parameters.Add("@RefID", SqlDbType.Int).Value = DBNull.Value; } else { com.Parameters.Add("@RefID", SqlDbType.Int).Value = obInOutMaster.RefID; } com.Parameters.Add("@Remarks", SqlDbType.VarChar, 500).Value = obInOutMaster.Remarks; com.Parameters.Add("@CompanyID", SqlDbType.Int).Value = LogInInfo.CompanyID; com.Parameters.Add("@UserID", SqlDbType.Int).Value = LogInInfo.UserID; com.Parameters.Add("@Module", SqlDbType.VarChar, 500).Value = obInOutMaster.Module; com.ExecuteNonQuery(); if (obInOutMaster.StockMID <= 0) { SqlCommand cmd = new SqlCommand("SELECT ISNULL(MAX(StockMID),0) FROM T_Stock_InOut_Master", con, trans); StockMID = Convert.ToInt32(cmd.ExecuteScalar()); } else { StockMID = obInOutMaster.StockMID; } } catch (Exception ex) { throw new Exception(ex.Message); } return(StockMID); }