Beispiel #1
0
    /*  public static DataTable Search(string sField, string sCondition, string sValue)
     * {
     *    SqlConnection connection = SAMDataClass.GetConnection();
     *    string selectProcedure = "[dbo].[CNDNDetailSearch]";
     *    SqlCommand selectCommand = new SqlCommand(selectProcedure, connection);
     *    selectCommand.CommandType = CommandType.StoredProcedure;
     *    if (sField == "C N D N Detail I D")
     *    {
     *        selectCommand.Parameters.AddWithValue("@CNDN_Detail_ID", sValue);
     *    }
     *    else
     *    {
     *        selectCommand.Parameters.AddWithValue("@CNDN_Detail_ID", DBNull.Value);
     *    }
     *    if (sField == "S A M C N D N No")
     *    {
     *        selectCommand.Parameters.AddWithValue("@SAM_CN_DN_No", sValue);
     *    }
     *    else
     *    {
     *        selectCommand.Parameters.AddWithValue("@SAM_CN_DN_No", DBNull.Value);
     *    }
     *    if (sField == "Product I D")
     *    {
     *        selectCommand.Parameters.AddWithValue("@Product_ID", sValue);
     *    }
     *    else
     *    {
     *        selectCommand.Parameters.AddWithValue("@Product_ID", DBNull.Value);
     *    }
     *    if (sField == "Price")
     *    {
     *        selectCommand.Parameters.AddWithValue("@Price", sValue);
     *    }
     *    else
     *    {
     *        selectCommand.Parameters.AddWithValue("@Price", DBNull.Value);
     *    }
     *    if (sField == "Vat")
     *    {
     *        selectCommand.Parameters.AddWithValue("@Vat", sValue);
     *    }
     *    else
     *    {
     *        selectCommand.Parameters.AddWithValue("@Vat", DBNull.Value);
     *    }
     *    if (sField == "Quantity")
     *    {
     *        selectCommand.Parameters.AddWithValue("@Quantity", sValue);
     *    }
     *    else
     *    {
     *        selectCommand.Parameters.AddWithValue("@Quantity", DBNull.Value);
     *    }
     *    if (sField == "Sub Total")
     *    {
     *        selectCommand.Parameters.AddWithValue("@Sub_Total", sValue);
     *    }
     *    else
     *    {
     *        selectCommand.Parameters.AddWithValue("@Sub_Total", DBNull.Value);
     *    }
     *    selectCommand.Parameters.AddWithValue("@SearchCondition", sCondition);
     *    DataTable dt = new DataTable();
     *    try
     *    {
     *        connection.Open();
     *        SqlDataReader reader = selectCommand.ExecuteReader();
     *        if (reader.HasRows)
     *        {
     *            dt.Load(reader);
     *        }
     *        reader.Close();
     *    }
     *    catch (SqlException ex)
     *    {
     *        logger.Error(ex.Message);
     *        return dt;
     *    }
     *    finally
     *    {
     *        connection.Close();
     *    }
     *    return dt;
     * }
     */
    public static dbo_CNDNDetailClass Select_Record(String CNDN_Detail_ID)
    {
        dbo_CNDNDetailClass clsdbo_CNDNDetail = new dbo_CNDNDetailClass();
        SqlConnection       connection        = SAMDataClass.GetConnection();
        string     selectProcedure            = "[dbo].[CNDNDetailSelect]";
        SqlCommand selectCommand = new SqlCommand(selectProcedure, connection);

        selectCommand.CommandType = CommandType.StoredProcedure;
        selectCommand.Parameters.AddWithValue("@CNDN_Detail_ID", CNDN_Detail_ID);
        try
        {
            connection.Open();
            SqlDataReader reader
                = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
            if (reader.Read())
            {
                clsdbo_CNDNDetail.CNDN_Detail_ID = reader["CNDN_Detail_ID"] is DBNull ? null : reader["CNDN_Detail_ID"].ToString();
                clsdbo_CNDNDetail.SAM_CN_DN_No   = reader["SAM_CN_DN_No"] is DBNull ? null : reader["SAM_CN_DN_No"].ToString();
                clsdbo_CNDNDetail.Product_ID     = reader["Product_ID"] is DBNull ? null : reader["Product_ID"].ToString();
                clsdbo_CNDNDetail.Price          = reader["Price"] is DBNull ? null : (Decimal?)reader["Price"];
                clsdbo_CNDNDetail.Vat            = reader["Vat"] is DBNull ? null : (Byte?)reader["Vat"];
                clsdbo_CNDNDetail.Quantity       = reader["Quantity"] is DBNull ? null : (Int16?)reader["Quantity"];
                clsdbo_CNDNDetail.Sub_Total      = reader["Sub_Total"] is DBNull ? null : (Decimal?)reader["Sub_Total"];
            }
            else
            {
                clsdbo_CNDNDetail = null;
            }
            reader.Close();
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(clsdbo_CNDNDetail);
        }
        finally
        {
            connection.Close();
        }
        return(clsdbo_CNDNDetail);
    }
Beispiel #2
0
    public static bool Update(dbo_CNDNDetailClass newdbo_CNDNDetailClass)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        updateProcedure = "[CNDNDetailUpdate]";
        SqlCommand    updateCommand   = new SqlCommand(updateProcedure, connection);

        updateCommand.CommandType = CommandType.StoredProcedure;
        if (newdbo_CNDNDetailClass.CNDN_Detail_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@NewCNDN_Detail_ID", newdbo_CNDNDetailClass.CNDN_Detail_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewCNDN_Detail_ID", DBNull.Value);
        }
        if (newdbo_CNDNDetailClass.SAM_CN_DN_No != null)
        {
            updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_No", newdbo_CNDNDetailClass.SAM_CN_DN_No);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewSAM_CN_DN_No", DBNull.Value);
        }
        if (newdbo_CNDNDetailClass.Product_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@NewProduct_ID", newdbo_CNDNDetailClass.Product_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewProduct_ID", DBNull.Value);
        }
        if (newdbo_CNDNDetailClass.Price.HasValue == true)
        {
            updateCommand.Parameters.AddWithValue("@NewPrice", newdbo_CNDNDetailClass.Price);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewPrice", DBNull.Value);
        }
        if (newdbo_CNDNDetailClass.Vat.HasValue == true)
        {
            updateCommand.Parameters.AddWithValue("@NewVat", newdbo_CNDNDetailClass.Vat);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewVat", DBNull.Value);
        }
        if (newdbo_CNDNDetailClass.Quantity.HasValue == true)
        {
            updateCommand.Parameters.AddWithValue("@NewQuantity", newdbo_CNDNDetailClass.Quantity);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewQuantity", DBNull.Value);
        }
        if (newdbo_CNDNDetailClass.Sub_Total.HasValue == true)
        {
            updateCommand.Parameters.AddWithValue("@NewSub_Total", newdbo_CNDNDetailClass.Sub_Total);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewSub_Total", 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();
        }
    }
Beispiel #3
0
    public static bool Add(dbo_CNDNDetailClass clsdbo_CNDNDetail, 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 = "[dbo].[CNDNDetailInsert]";
        SqlCommand    insertCommand   = new SqlCommand(insertProcedure, connection);

        insertCommand.CommandType = CommandType.StoredProcedure;
        if (clsdbo_CNDNDetail.CNDN_Detail_ID != null)
        {
            insertCommand.Parameters.AddWithValue("@CNDN_Detail_ID", clsdbo_CNDNDetail.CNDN_Detail_ID);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@CNDN_Detail_ID", DBNull.Value);
        }
        if (clsdbo_CNDNDetail.SAM_CN_DN_No != null)
        {
            insertCommand.Parameters.AddWithValue("@SAM_CN_DN_No", clsdbo_CNDNDetail.SAM_CN_DN_No);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@SAM_CN_DN_No", DBNull.Value);
        }
        if (clsdbo_CNDNDetail.Product_ID != null)
        {
            insertCommand.Parameters.AddWithValue("@Product_ID", clsdbo_CNDNDetail.Product_ID);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Product_ID", DBNull.Value);
        }
        if (clsdbo_CNDNDetail.Price.HasValue == true)
        {
            insertCommand.Parameters.AddWithValue("@Price", clsdbo_CNDNDetail.Price);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Price", DBNull.Value);
        }
        if (clsdbo_CNDNDetail.Vat.HasValue == true)
        {
            insertCommand.Parameters.AddWithValue("@Vat", clsdbo_CNDNDetail.Vat);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Vat", DBNull.Value);
        }
        if (clsdbo_CNDNDetail.Quantity.HasValue == true)
        {
            insertCommand.Parameters.AddWithValue("@Quantity", clsdbo_CNDNDetail.Quantity);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Quantity", DBNull.Value);
        }
        if (clsdbo_CNDNDetail.Sub_Total.HasValue == true)
        {
            insertCommand.Parameters.AddWithValue("@Sub_Total", clsdbo_CNDNDetail.Sub_Total);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Sub_Total", 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();
        }
    }