예제 #1
0
        private void AddNew()
        {
            try
            {
                Class_DSKhoa DSK = new Class_DSKhoa
                {
                    MaKhoa  = txtMaKhoa.Text.Trim(),
                    TenKhoa = txtTenKhoa.Text.Trim(),
                    GhiChu  = txtGhiChu.Text.Trim()
                };

                int result = da.ExecuteData(DSK.ToInsertQuery(), DSK.ToParameters());
                if (result > 0)
                {
                    MessageBox.Show("Success");
                    ButtonClick = "";
                    ViewMode();
                    LoadData();
                }
                else
                {
                    MessageBox.Show("Failed");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        public static List <KeyValuePair <string, object> > ToParameters(this Class_DSKhoa DSK)
        {
            var parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>("MaKhoa", DSK.MaKhoa));
            parameters.Add(new KeyValuePair <string, object>("TenKhoa", DSK.TenKhoa));
            parameters.Add(new KeyValuePair <string, object>("GhiChu", DSK.GhiChu));

            return(parameters);
        }
예제 #3
0
 public static string ToUpdateQuery(this Class_DSKhoa DSK)
 {
     return(@"UPDATE DANHSACHKHOA
             SET TenKhoa = @TenKhoa, GhiChu = @GhiChu WHERE MaKhoa = @MaKhoa");
 }
예제 #4
0
 public static string ToInsertQuery(this Class_DSKhoa DSK)
 {
     return(@"INSERT INTO DANHSACHKHOA(MaKhoa, TenKhoa, GhiChu) VALUES (@MaKhoa, @TenKhoa, @GhiChu)");
 }