Esempio n. 1
0
        //DeleteOB
        public bool _DeleteOb(Ob_HT_KeyAPI ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From HT_KeyAPI Where ID_KeyAPI=@ID_KeyAPI"
            };

            command.Parameters.Add(new SqlParameter("ID_KeyAPI", ob.ID_KEYAPI));
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Không thể xóa dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            command.Dispose();
            command = null;
            conn.Close();
            return(true);
        }
Esempio n. 2
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_HT_KeyAPI ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update HT_KeyAPI Set ID_KeyAPI=@ID_KeyAPI, MaKhoa=@MaKhoa, APIKey=@APIKey Where ID_KeyAPI=@ID_KeyAPI"
            };

            command.Parameters.Add("ID_KeyAPI", SqlDbType.Int).Value = ob.ID_KEYAPI;
            if (ob.MAKHOA.Trim() == "")
            {
                command.Parameters.Add("MaKhoa", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaKhoa", SqlDbType.VarChar).Value = ob.MAKHOA;
            }
            if (ob.APIKEY.Trim() == "")
            {
                command.Parameters.Add("APIKey", SqlDbType.NChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("APIKey", SqlDbType.NChar).Value = ob.APIKEY;
            }
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Không thể cập nhật dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            if (command.ExecuteNonQuery() == 0)
            {
                MessageBox.Show("Không thể cập nhật dữ liệu. \r\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            command.Dispose();
            command = null;
            conn.Close();
            return(true);
        }
Esempio n. 3
0
        //GetObWhere
        public Ob_HT_KeyAPI _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_HT_KeyAPI ob      = new Ob_HT_KeyAPI();
            SqlCommand   command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_KeyAPI, MaKhoa, APIKey From HT_KeyAPI Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_KEYAPI = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MAKHOA = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.APIKEY = Convert.ToString(reader[2]);
                }
            }
            if (num == 0)
            {
                command.Dispose();
                command = null;
                reader.Dispose();
                reader = null;
                conn.Close();
                return(null);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(ob);
        }
Esempio n. 4
0
        //InsertobGetId
        public int _InsertObGetId(Ob_HT_KeyAPI ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into HT_KeyAPI (ID_KeyAPI, MaKhoa, APIKey) Values(@ID_KeyAPI, @MaKhoa, @APIKey)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_KeyAPI", SqlDbType.Int).Value = ob.ID_KEYAPI;
                if (ob.MAKHOA.Trim() == "")
                {
                    command.Parameters.Add("MaKhoa", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaKhoa", SqlDbType.VarChar).Value = ob.MAKHOA;
                }
                if (ob.APIKEY.Trim() == "")
                {
                    command.Parameters.Add("APIKey", SqlDbType.NChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("APIKey", SqlDbType.NChar).Value = ob.APIKEY;
                }
                try
                {
                    num = Convert.ToInt32(command.ExecuteScalar());
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Không thể thêm dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    command.Dispose();
                    command = null;
                    conn.Close();
                    return(num);
                }
                command.Dispose();
                command = null;
                conn.Close();
            }
            return(num);
        }
Esempio n. 5
0
        //ListWhere_sp
        public List <Ob_HT_KeyAPI> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_KeyAPI> list    = new List <Ob_HT_KeyAPI>();
            SqlCommand          command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

            command.Parameters.AddRange(ArrayParameter);
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_KeyAPI ob = new Ob_HT_KeyAPI();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_KEYAPI = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MAKHOA = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.APIKEY = Convert.ToString(reader[2]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Esempio n. 6
0
        //ListAll
        public List <Ob_HT_KeyAPI> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_KeyAPI> list    = new List <Ob_HT_KeyAPI>();
            SqlCommand          command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_KeyAPI, MaKhoa, APIKey From HT_KeyAPI"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_KeyAPI ob = new Ob_HT_KeyAPI();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_KEYAPI = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MAKHOA = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.APIKEY = Convert.ToString(reader[2]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Esempio n. 7
0
 public Ob_HT_KeyAPI(Ob_HT_KeyAPI newOb)
 {
     id_keyapi = newOb.ID_KEYAPI;
     makhoa    = newOb.MAKHOA;
     apikey    = newOb.APIKEY;
 }