コード例 #1
0
ファイル: TransportModel.cs プロジェクト: campbellre/TWART
        public int CreateAccount(Transport t)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "NewTransportation";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("TransportationType", t.Type);

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

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
コード例 #2
0
ファイル: TransportModel.cs プロジェクト: campbellre/TWART
        public void EditTransport(Transport t)
        {
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "EditTransportation";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("TransportationID", t.ID);
                        cmd.Parameters.AddWithValue("TransportationType", t.Type);

                        cmd.ExecuteNonQuery();

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
        }
コード例 #3
0
ファイル: TransportModel.cs プロジェクト: campbellre/TWART
 public Transport SearchTransportt(Transport a)
 {
     return SearchTransport(a.ID);
 }
コード例 #4
0
ファイル: TransportModel.cs プロジェクト: campbellre/TWART
        // The main method to get a user account.
        public Transport SearchTransport(int ID)
        {
            var transport = new Transport();

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

                    connect.Open();

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        transport.ID = int.Parse(reader["Transportation_ID"].ToString());
                        transport.Type = reader["Transportation_Type"].ToString();

                    }

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

                return transport;
            }
        }