Exemple #1
0
 /// <summary>
 /// sửa lại năm học
 /// </summary>
 /// <returns>true</returns>
 private static void UpdateNamHoc(NamHoc item)
 {
     try
     {
         Conn.ExcuteQuerySql("update NAMHOC set NamHoc = '" + item.namhoc + "' WHERE ID = "+item.ID+"");
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
     }
 }
 protected override void SaveDetail()
 {
     try
     {
         if (ValidateData())
         {
             MessageBox.Show(@"Vui lòng nhập đầy đủ thông tin", @"Lỗi");
         }
         else
         {
             foreach (var row in dgv_DanhSach.Rows.Where(row => string.IsNullOrEmpty(row.Cells["ID"].Text)))
             {
                 var hs = new NamHoc
                 {
                     namhoc = row.Cells["NamHoc"].Text
                 };
                 _listAdd.Add(hs);
             }
             if (_listUpdate.Count <= 0 && IdDelete.Count <= 0 && _listAdd.Count <= 0) return;
             if (_listUpdate.Count > 0) UpdateData.UpdateNamHoc(_listUpdate);
             if (_listAdd.Count > 0) InsertData.ThemNamHoc(_listAdd);
             MessageBox.Show(FormResource.MsgThongbaothanhcong, FormResource.MsgCaption, MessageBoxButtons.OK,
                 MessageBoxIcon.Information);
             LoadFormDetail();
         }
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
     }
 }
 private void dgv_DanhSach_AfterExitEditMode(object sender, EventArgs e)
 {
     try
     {
         if (DeleteAndUpdate)
         {
             DeleteAndUpdate = false;
             return;
         }
         var id = dgv_DanhSach.ActiveRow.Cells["ID"].Text;
         if (string.IsNullOrEmpty(id)) return;
         foreach (var item in _listUpdate.Where(item => item.ID == int.Parse(id)))
         {
             item.namhoc = dgv_DanhSach.ActiveRow.Cells["NamHoc"].Text;
             return;
         }
         var hs = new NamHoc
         {
             ID = int.Parse(id),
             namhoc = dgv_DanhSach.ActiveRow.Cells["NamHoc"].Text
         };
         _listUpdate.Add(hs);
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
     }
 }
 /// <summary>
 /// Thêm mới 1 năm học
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public static bool ThemNamHoc(NamHoc item)
 {
     try
     {
         Conn.ExcuteQuerySql("insert into NAMHOC(NamHoc) values('"+item.namhoc+"')");
         return true;
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
         return false;
     }
 }