Exemplo n.º 1
0
    private void InsertRecord()
    {
        logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);
        dbo_ProductClass clsdbo_Product = new dbo_ProductClass();

        SetData(clsdbo_Product);


        bool   success = false;
        string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;

        success = dbo_ProductDataClass.Add(clsdbo_Product, User_ID);

        dbo_ProductListClass clsdbo_ProductList = new dbo_ProductListClass();


        List <dbo_PriceGroupClass> price_group    = dbo_PriceGroupDataClass.Search(string.Empty, "0");
        dbo_PriceGroupClass        price_group_id = price_group.FirstOrDefault(f => f.StandardPrice == true);

        clsdbo_ProductList.Price_Group_ID  = price_group_id.Price_Group_ID;
        clsdbo_ProductList.Product_List_ID = GenerateID.Product_List_ID();
        var date = new DateTime(9456, 12, 31);

        clsdbo_ProductList.Agent_Price            = clsdbo_Product.Agent_Price;
        clsdbo_ProductList.Product_Effective_Date = DateTime.Now;
        clsdbo_ProductList.Start_Effective_Date   = DateTime.Now;
        clsdbo_ProductList.End_Effective_Date     = date;
        clsdbo_ProductList.Product_ID             = clsdbo_Product.Product_ID;
        clsdbo_ProductList.Product_Name           = clsdbo_Product.Product_Name;
        clsdbo_ProductList.Point = clsdbo_Product.Point;
        clsdbo_ProductList.Vat   = clsdbo_Product.Vat;
        //clsdbo_ProductList.CP_Meiji_Price = clsdbo_Product.CP_Meiji_Price;

        dbo_ProductListDataClass.Add(clsdbo_ProductList, User_ID);

        price_group    = dbo_PriceGroupDataClass.Search(string.Empty, "1");
        price_group_id = price_group.FirstOrDefault(f => f.StandardPrice == true);


        if (price_group_id != null)
        {
            clsdbo_ProductList.Price_Group_ID  = price_group_id.Price_Group_ID;
            clsdbo_ProductList.SP_Price        = clsdbo_Product.SP_Price;
            clsdbo_ProductList.CP_Meiji_Price  = clsdbo_Product.CP_Meiji_Price;
            clsdbo_ProductList.Agent_Price     = null;
            clsdbo_ProductList.Product_List_ID = GenerateID.Product_List_ID();

            dbo_ProductListDataClass.Add(clsdbo_ProductList, User_ID);
        }

        if (success)
        {
            Show("บันทึกสำเร็จ");
        }
        else
        {
            Show("error");
        }
    }
Exemplo n.º 2
0
    public static dbo_PriceGroupClass Select_Record(string Price_Group_ID)
    {
        dbo_PriceGroupClass clsdbo_PriceGroup = new dbo_PriceGroupClass();
        SqlConnection       connection        = SAMDataClass.GetConnection();
        string     selectProcedure            = "PriceGroupSelect";
        SqlCommand selectCommand = new SqlCommand(selectProcedure, connection);

        selectCommand.CommandType = CommandType.StoredProcedure;
        selectCommand.Parameters.AddWithValue("@Price_Group_ID", Price_Group_ID);
        try
        {
            connection.Open();
            SqlDataReader reader
                = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
            if (reader.Read())
            {
                clsdbo_PriceGroup.Price_Group_ID   = reader["Price_Group_ID"] is DBNull ? null : reader["Price_Group_ID"].ToString();
                clsdbo_PriceGroup.Price_Group_Name = reader["Price_Group_Name"] is DBNull ? null : reader["Price_Group_Name"].ToString();
                clsdbo_PriceGroup.Price_Group_Type = reader["Price_Group_Type"] is DBNull ? null : (reader["Price_Group_Type"].ToString() == "0" ? "เอเยนต์" : "สาว");
                clsdbo_PriceGroup.StandardPrice    = reader["StandardPrice"] is DBNull ? false : (Boolean)reader["StandardPrice"];
            }
            else
            {
                clsdbo_PriceGroup = null;
            }
            reader.Close();
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(clsdbo_PriceGroup);
        }
        finally
        {
            connection.Close();
        }
        return(clsdbo_PriceGroup);
    }
Exemplo n.º 3
0
    public static bool Update(dbo_PriceGroupClass newdbo_PriceGroupClass, String Last_Modified_By)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        updateProcedure = "PriceGroupUpdate";
        SqlCommand    updateCommand   = new SqlCommand(updateProcedure, connection);

        updateCommand.CommandType = CommandType.StoredProcedure;

        if (newdbo_PriceGroupClass.Price_Group_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@NewPrice_Group_ID", newdbo_PriceGroupClass.Price_Group_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewPrice_Group_ID", DBNull.Value);
        }

        if (newdbo_PriceGroupClass.Price_Group_Name != null)
        {
            updateCommand.Parameters.AddWithValue("@NewPrice_Group_Name", newdbo_PriceGroupClass.Price_Group_Name);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewPrice_Group_Name", DBNull.Value);
        }

        if (newdbo_PriceGroupClass.StandardPrice != null)
        {
            updateCommand.Parameters.AddWithValue("@StandardPrice", newdbo_PriceGroupClass.StandardPrice);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@StandardPrice", DBNull.Value);
        }

        if (Last_Modified_By != null)
        {
            updateCommand.Parameters.AddWithValue("@Last_Modified_By", Last_Modified_By);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@Last_Modified_By", 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();
        }
    }
Exemplo n.º 4
0
    public static bool Add(dbo_PriceGroupClass clsdbo_PriceGroup, String Created_By)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        insertProcedure = "[PriceGroupInsert]";
        SqlCommand    insertCommand   = new SqlCommand(insertProcedure, connection);

        insertCommand.CommandType = CommandType.StoredProcedure;
        if (clsdbo_PriceGroup.Price_Group_ID != null)
        {
            insertCommand.Parameters.AddWithValue("@Price_Group_ID", clsdbo_PriceGroup.Price_Group_ID);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Price_Group_ID", DBNull.Value);
        }
        if (clsdbo_PriceGroup.Price_Group_Name != null)
        {
            insertCommand.Parameters.AddWithValue("@Price_Group_Name", clsdbo_PriceGroup.Price_Group_Name);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Price_Group_Name", DBNull.Value);
        }
        if (clsdbo_PriceGroup.Price_Group_Type != null)
        {
            insertCommand.Parameters.AddWithValue("@Price_Group_Type", clsdbo_PriceGroup.Price_Group_Type);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Price_Group_Type", DBNull.Value);
        }


        if (clsdbo_PriceGroup.StandardPrice != null)
        {
            insertCommand.Parameters.AddWithValue("@StandardPrice", clsdbo_PriceGroup.StandardPrice);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@StandardPrice", DBNull.Value);
        }

        if (Created_By != null)
        {
            insertCommand.Parameters.AddWithValue("@Created_By", Created_By);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Created_By", DBNull.Value);
        }

        if (Created_By != null)
        {
            insertCommand.Parameters.AddWithValue("@CV_Code", Created_By);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@CV_Code", 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();
        }
    }