public DataTable GetDtb(string WhereCondition = "")
        {
            LocalTable.Rows.Clear();

            SQLiteCommand command = new SQLiteCommand();

            command.CommandType = CommandType.Text;
            if (WhereCondition.Length == 0)
            {
                command.CommandText = "SELECT * FROM " + LocalTable.TableName;
            }
            else
            {
                command.CommandText = "SELECT * FROM " + LocalTable.TableName + " WHERE " + WhereCondition;
            }
            command.Connection = DbAccess.DatabaseConnection;

            DbAccess.OpenConnection();
            SQLiteDataReader r = command.ExecuteReader();

            while (r.Read())
            {
                DataRow newRow = LocalTable.NewRow();
                for (int i = 0; i < 9; i++)
                {
                    newRow[i] = r[i];
                }
                LocalTable.Rows.Add(newRow);
            }
            DbAccess.CloseConnection();

            return(LocalTable);
        }
        public DataTable GetDtb(string WhereCondition = "")
        {
            LocalTable.Rows.Clear();

            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "SELECT * FROM " + LocalTable.TableName + (WhereCondition.Length > 0? (" WHERE " + WhereCondition): "");

            DbAccess.OpenConnection();
            SQLiteDataReader r = cm.ExecuteReader();

            while (r.Read())
            {
                DataRow dr = LocalTable.NewRow();
                dr["id"]        = r["id"];
                dr["nam"]       = r["nam"];
                dr["danhHieu"]  = r["danhhieu"];
                dr["trangThai"] = r["trangThai"];
                LocalTable.Rows.Add(dr);
            }
            DbAccess.CloseConnection();

            return(LocalTable);
        }
        public void CreateDataByYear(long baseYear = 0)
        {
            long          y  = DateTime.Now.Year;
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "SELECT COUNT(nam) FROM " + LocalTable.TableName + " WHERE nam =" + y;

            DbAccess.OpenConnection();
            long count = (long)cm.ExecuteScalar();

            DbAccess.CloseConnection();

            if (count > 0)
            {
                return;
            }

            var d = from DataRow x in LocalTable.Rows
                    where (long)x["nam"] == baseYear orderby(long) x["id"]
                    select x;

            foreach (var item in d)
            {
                Obj_DanhHieu o = CreateObj(item);
                o.Nam = y;
                o.ID  = GetNextID();
                Insert(o);
            }
        }
        public DataTable GetDtbChucDanh()
        {
            LocalTable.Rows.Clear();

            SQLiteCommand command = new SQLiteCommand(DbAccess.DatabaseConnection);

            command.CommandType = CommandType.Text;
            command.CommandText = "SELECT * FROM " + LocalTable.TableName;

            DbAccess.OpenConnection();
            SQLiteDataReader r = command.ExecuteReader();

            while (r.Read())
            {
                DataRow dataRow = LocalTable.NewRow();
                for (int i = 0; i < LocalTable.Columns.Count; i++)
                {
                    dataRow[i] = r[i];
                }
                LocalTable.Rows.Add(dataRow);
            }
            DbAccess.CloseConnection();

            return(LocalTable);
        }
        public int Delete(Obj_CaNhan obj_CaNhan)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "DELETE FROM " + LocalTable.TableName + " WHERE id = " + obj_CaNhan.ID;

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            if (i == 1)
            {
                foreach (DataRow item in LocalTable.Rows)
                {
                    if ((long)item[0] == obj_CaNhan.ID)
                    {
                        LocalTable.Rows.Remove(item);
                        LocalTable.AcceptChanges();
                        break;
                    }
                }
            }

            return(i);
        }
        public int Insert(Obj_DanhHieu obj)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "INSERT INTO " + LocalTable.TableName + " VALUES (" +
                             "id = @id, " +
                             "nam = @nam, " +
                             "danhHieu = @danhHieu, " +
                             "trangThai = @trangThai)";
            cm.Parameters.Add(new SQLiteParameter("@id", typeof(long)));
            cm.Parameters.Add(new SQLiteParameter("@nam", typeof(long)));
            cm.Parameters.Add(new SQLiteParameter("@danhHieu", typeof(string)));
            cm.Parameters.Add(new SQLiteParameter("@trangThai", typeof(bool)));

            int i = -1;

            DbAccess.OpenConnection();
            i = cm.ExecuteNonQuery();
            DbAccess.CloseConnection();

            if (i == 1)
            {
                DataRow item = LocalTable.NewRow();
                item["id"]        = obj.ID;
                item["nam"]       = obj.Nam;
                item["danhHieu"]  = obj.DanhHieu;
                item["trangThai"] = obj.TrangThai;
                LocalTable.Rows.Add(item);
                LocalTable.AcceptChanges();
            }

            return(i);
        }
Esempio n. 7
0
        public int Delete(Obj_TieuChi obj)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "DELETE FROM " + LocalTable.TableName + " WHERE id = @id";
            cm.Parameters.Add(new SQLiteParameter("@id", obj.ID));

            int i = -1;

            DbAccess.OpenConnection();
            i = cm.ExecuteNonQuery();
            DbAccess.CloseConnection();

            if (i == 1)
            {
                foreach (DataRow r in LocalTable.Rows)
                {
                    if ((long)r["id"] == obj.ID)
                    {
                        LocalTable.Rows.Remove(r);
                        break;
                    }
                }
            }

            return(i);
        }
Esempio n. 8
0
        public DataTable GetDtb(string WhereCondition = "")
        {
            LocalTable.Rows.Clear();
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "SELECT * FROM " + LocalTable.TableName + ((WhereCondition.Length > 0) ? WhereCondition : "");

            try
            {
                DbAccess.OpenConnection();
                SQLiteDataReader r = cm.ExecuteReader();
                while (r.Read())
                {
                    DataRow dr = LocalTable.NewRow();
                    for (int i = 0; i < LocalTable.Columns.Count; i++)
                    {
                        dr[i] = r[i];
                    }
                    LocalTable.Rows.Add(dr);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DbAccess.CloseConnection();
            }

            return(LocalTable);
        }
Esempio n. 9
0
        public DataTable GetDtb(string whereCondition = "")
        {
            SQLiteCommand command = new SQLiteCommand(DbAccess.DatabaseConnection);

            command.CommandType = CommandType.Text;
            command.CommandText = "SELECT * FROM " + LocalTable.TableName + (whereCondition.Length > 0 ? (" WHERE " + whereCondition) : "");

            LocalTable.Rows.Clear();

            DbAccess.OpenConnection();
            SQLiteDataReader r = command.ExecuteReader();

            while (r.Read())
            {
                DataRow nr = LocalTable.NewRow();
                for (int i = 0; i < LocalTable.Columns.Count; i++)
                {
                    nr[i] = r[i];
                }
                LocalTable.Rows.Add(nr);
            }
            DbAccess.CloseConnection();

            return(LocalTable);
        }
        public int Update(Obj_CaNhan obj_CaNhan)
        {
            SQLiteCommand command = new SQLiteCommand(DbAccess.DatabaseConnection)
            {
                CommandType = CommandType.Text,
                CommandText =
                    "UPDATE " + LocalTable.TableName +
                    " SET " +
                    "idDonVi = @idDonVi, " +
                    "hoTen = @hoTen, " +
                    "gioiTinh = @gioiTinh, " +
                    "ngaySinh = @ngaySinh, " +
                    "chucDanh = @chucDanh, " +
                    "chucVu = @chucVu, " +
                    "email = @email, " +
                    "phone = @phone " +
                    "WHERE id = @id "
            };

            command.Parameters.Add(new SQLiteParameter("@idDonVi", obj_CaNhan.ID_DonVi));
            command.Parameters.Add(new SQLiteParameter("@hoTen", obj_CaNhan.HoTen));
            command.Parameters.Add(new SQLiteParameter("@gioiTinh", obj_CaNhan.GioiTinh));
            command.Parameters.Add(new SQLiteParameter("@ngaySinh", obj_CaNhan.NgaySinh));
            command.Parameters.Add(new SQLiteParameter("@chucDanh", obj_CaNhan.ChucDanh));
            command.Parameters.Add(new SQLiteParameter("@chucVu", obj_CaNhan.ChucVu));
            command.Parameters.Add(new SQLiteParameter("@email", obj_CaNhan.Email));
            command.Parameters.Add(new SQLiteParameter("@phone", obj_CaNhan.Phone));
            command.Parameters.Add(new SQLiteParameter("@id", obj_CaNhan.ID));

            DbAccess.OpenConnection();
            int i = command.ExecuteNonQuery();

            DbAccess.CloseConnection();

            //update to localtable
            if (i == 1)
            {
                foreach (DataRow item in LocalTable.Rows)
                {
                    if ((long)item[0] == obj_CaNhan.ID)
                    {
                        item[1] = obj_CaNhan.ID_DonVi;
                        item[2] = obj_CaNhan.HoTen;
                        item[3] = obj_CaNhan.GioiTinh;
                        item[4] = obj_CaNhan.NgaySinh;
                        item[5] = obj_CaNhan.ChucDanh;
                        item[6] = obj_CaNhan.ChucVu;
                        item[7] = obj_CaNhan.Email;
                        item[8] = obj_CaNhan.Phone;
                        LocalTable.AcceptChanges();
                        break;
                    }
                }
            }

            return(i);
        }
        public int Insert(Obj_CaNhan obj_CaNhan)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "INSERT INTO " + LocalTable.TableName + " VALUES (" +
                             "@id, " +
                             "@idDonVi, " +
                             "@hoTen, " +
                             "@gioiTinh, " +
                             "@ngaySinh, " +
                             "@chucDanh, " +
                             "@chucVu, " +
                             "@email, " +
                             "@phone)";

            cm.Parameters.Add(new SQLiteParameter("@id", obj_CaNhan.ID));
            cm.Parameters.Add(new SQLiteParameter("@idDonVi", obj_CaNhan.ID_DonVi));
            cm.Parameters.Add(new SQLiteParameter("@hoTen", obj_CaNhan.HoTen));
            cm.Parameters.Add(new SQLiteParameter("@gioiTinh", obj_CaNhan.GioiTinh));
            cm.Parameters.Add(new SQLiteParameter("@ngaySinh", obj_CaNhan.NgaySinh));
            cm.Parameters.Add(new SQLiteParameter("@chucDanh", obj_CaNhan.ChucDanh));
            cm.Parameters.Add(new SQLiteParameter("@chucVu", obj_CaNhan.ChucVu));
            cm.Parameters.Add(new SQLiteParameter("@email", obj_CaNhan.Email));
            cm.Parameters.Add(new SQLiteParameter("@phone", obj_CaNhan.Phone));

            int i = -1;

            if (DbAccess.OpenConnection())
            {
                i = cm.ExecuteNonQuery();
                DbAccess.CloseConnection();
            }

            if (i == 1)
            {
                DataRow item = LocalTable.NewRow();
                item[0] = obj_CaNhan.ID;
                item[1] = obj_CaNhan.ID_DonVi;
                item[2] = obj_CaNhan.HoTen;
                item[3] = obj_CaNhan.GioiTinh;
                item[4] = obj_CaNhan.NgaySinh;
                item[5] = obj_CaNhan.ChucDanh;
                item[6] = obj_CaNhan.ChucVu;
                item[7] = obj_CaNhan.Email;
                item[8] = obj_CaNhan.Phone;
                LocalTable.Rows.Add(item);
                LocalTable.AcceptChanges();
            }

            return(i);
        }
Esempio n. 12
0
        public int Delete(Obj_GioiTinh obj_GioiTinh)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "DELETE FROM " + LocalTable.TableName + " WHERE id = " + obj_GioiTinh.ID;

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            return(i);
        }
        public int Delete(string whereCondition)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "DELETE FROM " + LocalTable.TableName + " WHERE " + whereCondition;

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            return(i);
        }
        public long GetNextID()
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "SELECT IFNULL(MAX(id), -1) FROM " + LocalTable.TableName;

            DbAccess.OpenConnection();
            long i = (long)cm.ExecuteScalar();

            DbAccess.CloseConnection();

            return(i + 1);
        }
        public int Update(Obj_DonVi obj_DonVi)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "UPDATE " + LocalTable.TableName +
                             " SET " +
                             "loai = @loai, " +
                             "tenDonVi = @tenDonVi, " +
                             "diaDiem = @diaDiem, " +
                             "email = @email, " +
                             "phone = @phone, " +
                             "trangThai = @trangThai" +
                             " WHERE id = @id";
            cm.Parameters.Add(new SQLiteParameter("@loai", obj_DonVi.Loai));
            cm.Parameters.Add(new SQLiteParameter("@tenDonVi", obj_DonVi.TenDonVi));
            cm.Parameters.Add(new SQLiteParameter("@diaDiem", obj_DonVi.DiaDiem));
            cm.Parameters.Add(new SQLiteParameter("@email", obj_DonVi.Email));
            cm.Parameters.Add(new SQLiteParameter("@phone", obj_DonVi.Phone));
            cm.Parameters.Add(new SQLiteParameter("@trangThai", obj_DonVi.TrangThai));
            cm.Parameters.Add(new SQLiteParameter("@id", obj_DonVi.ID));

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            if (i == 1)
            {
                foreach (DataRow item in LocalTable.Rows)
                {
                    if ((long)item[0] == obj_DonVi.ID)
                    {
                        item[1] = obj_DonVi.Loai;
                        item[2] = obj_DonVi.TenDonVi;
                        item[3] = obj_DonVi.DiaDiem;
                        item[4] = obj_DonVi.Email;
                        item[5] = obj_DonVi.Phone;
                        item[6] = obj_DonVi.TrangThai;
                        LocalTable.AcceptChanges();
                        break;
                    }
                }
            }

            return(i);
        }
Esempio n. 16
0
        public int Update(Obj_HoSoThiDua obj)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "UPDATE " + LocalTable.TableName +
                             " SET " +
                             "idCaNhan = @idCaNhan                               , " +
                             "idDonVi = @idDonVi                                 , " +
                             "nam = @nam                                         , " +
                             "danhHieuDangKy = @danhHieuDangKy                   , " +
                             "danhHieuDatDuoc = @danhHieuDatDuoc " +
                             "WHERE id = @id";
            cm.Parameters.Add(new SQLiteParameter("@idCaNhan", obj.IDCaNhan));
            cm.Parameters.Add(new SQLiteParameter("@idDonVi", obj.IDDonVi));
            cm.Parameters.Add(new SQLiteParameter("@nam", obj.Nam));
            cm.Parameters.Add(new SQLiteParameter("@danhHieuDangKy", obj.DanhHieuDangKy));
            cm.Parameters.Add(new SQLiteParameter("@danhHieuDatDuoc", obj.DanhHieuDatDuoc));
            cm.Parameters.Add(new SQLiteParameter("@id", obj.ID));

            int i = -1;

            DbAccess.OpenConnection();
            i = cm.ExecuteNonQuery();
            DbAccess.CloseConnection();

            //update to localtable
            if (i == 1)
            {
                foreach (DataRow r in LocalTable.Rows)
                {
                    if ((long)r[0] == obj.ID)
                    {
                        r["idCaNhan"]        = obj.IDCaNhan;
                        r["idDonVi"]         = obj.IDDonVi;
                        r["nam"]             = obj.Nam;
                        r["danhHieuDangKy"]  = obj.DanhHieuDangKy;
                        r["danhHieuDatDuoc"] = obj.DanhHieuDatDuoc;
                        LocalTable.AcceptChanges();
                        break;
                    }
                }
            }

            return(i);
        }
Esempio n. 17
0
        public bool CheckExisted(long idCaNhan, long nam)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "SELECT COUNT(id) FROM " + LocalTable.TableName + " WHERE idCaNhan = @idCaNhan AND nam = @nam";

            cm.Parameters.Add(new SQLiteParameter("@idCaNhan", idCaNhan));
            cm.Parameters.Add(new SQLiteParameter("@nam", nam));

            int i = -1;

            DbAccess.OpenConnection();
            i = (int)cm.ExecuteScalar();
            DbAccess.CloseConnection();

            return(i >= 1);
        }
        public int Insert(Obj_DonVi obj_DonVi)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "INSERT INTO " + LocalTable.TableName +
                             " VALUES (" +
                             "@id, " +
                             "@loai, " +
                             "@tenDonVi, " +
                             "@diaDiem, " +
                             "@email, " +
                             "@phone, " +
                             "@trangThai)";
            cm.Parameters.Add(new SQLiteParameter("@id", obj_DonVi.ID));
            cm.Parameters.Add(new SQLiteParameter("@loai", obj_DonVi.Loai));
            cm.Parameters.Add(new SQLiteParameter("@tenDonVi", obj_DonVi.TenDonVi));
            cm.Parameters.Add(new SQLiteParameter("@diaDiem", obj_DonVi.DiaDiem));
            cm.Parameters.Add(new SQLiteParameter("@email", obj_DonVi.Email));
            cm.Parameters.Add(new SQLiteParameter("@phone", obj_DonVi.Phone));
            cm.Parameters.Add(new SQLiteParameter("@trangThai", obj_DonVi.TrangThai));

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            if (i == 1)
            {
                DataRow item = LocalTable.NewRow();
                item[0] = obj_DonVi.ID;
                item[1] = obj_DonVi.Loai;
                item[2] = obj_DonVi.TenDonVi;
                item[3] = obj_DonVi.DiaDiem;
                item[4] = obj_DonVi.Email;
                item[5] = obj_DonVi.Phone;
                item[6] = obj_DonVi.TrangThai;
                LocalTable.Rows.Add(item);
                LocalTable.AcceptChanges();
            }

            return(i);
        }
Esempio n. 19
0
        public int Update(Obj_TieuChi obj)
        {
            SQLiteCommand command = new SQLiteCommand(DbAccess.DatabaseConnection);

            command.CommandType = CommandType.Text;
            command.CommandText = "UPDATE " + LocalTable.TableName + " SET " +
                                  "ten = @ten, " +
                                  "moTa = @moTa, " +
                                  "ghiChu = @ghiChu " +
                                  "WHERE id = @id";

            command.Parameters.Add(new SQLiteParameter("@ten", obj.Ten));
            command.Parameters.Add(new SQLiteParameter("@moTa", obj.MoTa));
            command.Parameters.Add(new SQLiteParameter("@ghiChu", obj.GhiChu));
            command.Parameters.Add(new SQLiteParameter("@id", obj.ID));

            int i = -1;

            try
            {
                DbAccess.OpenConnection();
                i = command.ExecuteNonQuery();
            }
            finally
            {
                DbAccess.CloseConnection();
                if (i == 1)
                {
                    foreach (DataRow item in LocalTable.Rows)
                    {
                        if ((long)item["id"] == obj.ID)
                        {
                            item["ten"]    = obj.Ten;
                            item["moTa"]   = obj.MoTa;
                            item["ghiChu"] = obj.GhiChu;
                            break;
                        }
                    }
                }
            }
            return(i);
        }
Esempio n. 20
0
        public int Update(Obj_GioiTinh obj_GioiTinh)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "UPDATE " + LocalTable.TableName + " SET " +
                             "gioitinh = @gioiTinh, " +
                             "trangThai = @trangThai " +
                             " WHERE id = @id";
            cm.Parameters.Add(new SQLiteParameter("@gioiTinh", obj_GioiTinh.GioiTinh));
            cm.Parameters.Add(new SQLiteParameter("@trangThai", obj_GioiTinh.TrangThai));
            cm.Parameters.Add(new SQLiteParameter("@id", obj_GioiTinh.ID));

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            return(i);
        }
Esempio n. 21
0
        public int Insert(Obj_GioiTinh obj_GioiTinh)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "INSERT INTO " + LocalTable.TableName + " VALUES (" +
                             "@id, " +
                             "@gioiTinh, " +
                             "@trangThai)";
            cm.Parameters.Add(new SQLiteParameter("@id", obj_GioiTinh.ID));
            cm.Parameters.Add(new SQLiteParameter("@gioiTinh", obj_GioiTinh.GioiTinh));
            cm.Parameters.Add(new SQLiteParameter("@trangThai", obj_GioiTinh.TrangThai));

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            return(i);
        }
Esempio n. 22
0
        public int Insert(Obj_TieuChi obj)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "INSERT INTO " + LocalTable.TableName + " VALUES (" +
                             "@id, " +
                             "@nam, " +
                             "@ten, " +
                             "@moTa, " +
                             "@ghiChu)";
            cm.Parameters.Add(new SQLiteParameter("@id", obj.ID));
            cm.Parameters.Add(new SQLiteParameter("@nam", obj.Nam));
            cm.Parameters.Add(new SQLiteParameter("@ten", obj.Ten));
            cm.Parameters.Add(new SQLiteParameter("@moTa", obj.MoTa));
            cm.Parameters.Add(new SQLiteParameter("@ghiChu", obj.GhiChu));

            int i = -1;

            try
            {
                DbAccess.OpenConnection();
                i = cm.ExecuteNonQuery();
            }
            finally
            {
                DbAccess.CloseConnection();
                if (i == 1)
                {
                    DataRow r = LocalTable.NewRow();
                    r["id"]     = obj.ID;
                    r["ten"]    = obj.Ten;
                    r["moTa"]   = obj.MoTa;
                    r["ghiChu"] = obj.GhiChu;
                    LocalTable.Rows.Add(r);
                }
            }

            return(i);
        }
Esempio n. 23
0
        public int Insert(Obj_HoSoThiDua obj)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "INSERT INTO " + LocalTable.TableName + " VALUES (" +
                             "@id, " +
                             "@idCaNhan, " +
                             "@idDonVi, " +
                             "@nam, " +
                             "@danhHieuDangKy, " +
                             "@danhHieuDatDuoc)";
            cm.Parameters.Add(new SQLiteParameter("@id", obj.ID));
            cm.Parameters.Add(new SQLiteParameter("@idCaNhan", obj.IDCaNhan));
            cm.Parameters.Add(new SQLiteParameter("@idDonVi", obj.IDDonVi));
            cm.Parameters.Add(new SQLiteParameter("@nam", obj.Nam));
            cm.Parameters.Add(new SQLiteParameter("@danhHieuDangKy", obj.DanhHieuDangKy));
            cm.Parameters.Add(new SQLiteParameter("@danhHieuDatDuoc", obj.DanhHieuDatDuoc));

            int i = -1;

            DbAccess.OpenConnection();
            i = cm.ExecuteNonQuery();
            DbAccess.CloseConnection();

            if (i == 1)
            {
                DataRow nr = LocalTable.NewRow();
                nr["id"]              = obj.ID;
                nr["idCaNhan"]        = obj.IDCaNhan;
                nr["idDonVi"]         = obj.IDDonVi;
                nr["nam"]             = obj.Nam;
                nr["danhHieuDangKy"]  = obj.DanhHieuDangKy;
                nr["danhHieuDatDuoc"] = obj.DanhHieuDatDuoc;
                LocalTable.Rows.Add(nr);
            }

            return(i);
        }
Esempio n. 24
0
        public int Update(Obj_ChucVu obj_ChucVu)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "UPDATE " + LocalTable.TableName +
                             " SET " +
                             "chucVu = @chucVu, " +
                             "trangThai = @trangThai " +
                             "WHERE id = @id";

            cm.Parameters.Add(new SQLiteParameter("@chucVu", obj_ChucVu.ChucVu));
            cm.Parameters.Add(new SQLiteParameter("@trangThai", obj_ChucVu.TrangThai));
            cm.Parameters.Add(new SQLiteParameter("@id", obj_ChucVu.ID));

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            return(i);
        }
        public int Update(Obj_DanhHieu obj)
        {
            SQLiteCommand cm = new SQLiteCommand(DbAccess.DatabaseConnection);

            cm.CommandType = CommandType.Text;
            cm.CommandText = "UPDATE " + LocalTable.TableName + " SET " +
                             "nam = @nam, " +
                             "danhHieu = @danhHieu, " +
                             "trangThai = @trangThai " +
                             "WHERE id = @id";
            cm.Parameters.Add(new SQLiteParameter("@nam", obj.Nam));
            cm.Parameters.Add(new SQLiteParameter("@danhHieu", obj.DanhHieu));
            cm.Parameters.Add(new SQLiteParameter("@trangThai", obj.TrangThai));
            cm.Parameters.Add(new SQLiteParameter("@id", obj.ID));

            DbAccess.OpenConnection();
            int i = cm.ExecuteNonQuery();

            DbAccess.CloseConnection();

            if (i == 1)
            {
                foreach (DataRow item in LocalTable.Rows)
                {
                    if ((long)item["id"] == obj.ID)
                    {
                        item["nam"]       = obj.Nam;
                        item["danhHieu"]  = obj.DanhHieu;
                        item["trangThai"] = obj.TrangThai;
                        break;
                    }
                }
            }

            return(i);
        }