コード例 #1
0
        public void EditSpecification(Specification s)
        {
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {

                    try
                    {
                        string query = "EditPackageSpecification";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("SpecificationID", s.ID);
                        cmd.Parameters.AddWithValue("PWeight", s.Weight);
                        cmd.Parameters.AddWithValue("DeimensionHeight", s.Height);
                        cmd.Parameters.AddWithValue("DimensionWidth", s.Width);
                        cmd.Parameters.AddWithValue("DimensionLength", s.Length);

                        cmd.ExecuteNonQuery();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        connect.Close();
                    }
                }
            }
        }
コード例 #2
0
        // Create specification
        public int create(int weight, int height, int width, int length)
        {
            // Establish models
            SpecificationModel specModel = new SpecificationModel();

            // Holds the new specification
            Specification newSpec = new Specification();

            // Stored details for the specification
            newSpec.Weight = weight;
            newSpec.Height = height;
            newSpec.Width = width;
            newSpec.Length = length;

            // Adds the object to the database
            int specificationID = specModel.NewSpecification(newSpec);

            // Return the specificationID
            return specificationID;
        }
コード例 #3
0
        public List<Specification> GetSpecificationsList()
        {
            var specList = new List<Specification>();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "ListPackageSpecification";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    connect.Open();

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var s = new Specification();

                        s.ID = (int)reader["Specification_ID"];
                        s.Weight = (int)reader["Weight"];
                        s.Length = (int)reader["Dimension_Height"];
                        s.Width = (int)reader["Dimension_Width"];
                        s.Height = (int)reader["Dimension_Length"];

                        specList.Add(s);

                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return specList;
            }
        }
コード例 #4
0
 public Specification SearchSpecification(Specification s)
 {
     return  SearchSpecification(s.ID);
 }
コード例 #5
0
        public Specification SearchSpecification(int ID)
        {
            var s = new Specification();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "GetPackageSpecification";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };
                    cmd.Parameters.AddWithValue("PackageSpecificationID", ID);
                    connect.Open();

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {

                        s.ID = (int)reader["Specification_ID"];
                        s.Weight = (int)reader["Weight"];
                        s.Length = (int)reader["Dimension_Height"];
                        s.Width = (int)reader["Dimension_Width"];
                        s.Height = (int)reader["Dimension_Length"];

                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return s;
            }
        }
コード例 #6
0
        public int NewSpecification(Specification s)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {

                    try
                    {
                        string query = "NewPackageSpecification";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("PWeight", s.Weight);
                        cmd.Parameters.AddWithValue("DeimensionHeight", s.Height);
                        cmd.Parameters.AddWithValue("DimensionWidth", s.Width);
                        cmd.Parameters.AddWithValue("DimensionLength", s.Length);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();;

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }