Esempio n. 1
0
        private void CRUD()
        {
            try
            {
                switch (function)
                {
                case "add":
                    objThietBi = new ThietBi();
                    setDataObj();
                    if (objThietBi.add() > 0 && DBInstance.commit() > 0)
                    {
                        XtraMessageBox.Show("Thêm thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        reLoadAndFocused(objThietBi.id);
                    }
                    break;

                case "edit":
                    setDataObj();
                    if (objThietBi.update() > 0 && DBInstance.commit() > 0)
                    {
                        XtraMessageBox.Show("Sửa thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        reLoadAndFocused(objThietBi.id);
                    }
                    break;

                case "delete":
                    //Xóa sạch, ko luyến tiếc
                    int[]   indexCacRow = gridViewThietBi.GetSelectedRows();
                    String  message     = "";
                    Boolean thanhcong   = true;
                    if (indexCacRow.Count() == 1)
                    {
                        message = "Bạn có chắc là xóa thiết bị này?";
                    }
                    if (indexCacRow.Count() > 1)
                    {
                        message = "Bạn có chắc là xóa những thiết bị đã chọn?";
                    }
                    if (indexCacRow.Count() > 0)
                    {
                        if (XtraMessageBox.Show(message, "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            //splashScreenManager.ShowWaitForm();
                            //splashScreenManager.SetWaitFormCaption("Đang xóa thiết bị");
                            for (int i = 0; i < indexCacRow.Count(); i++)
                            {
                                try
                                {
                                    objThietBi = gridViewThietBi.GetRow(indexCacRow[i]) as ThietBi;
                                    if (objThietBi.ctthietbis != null)
                                    {
                                        for (int j = 0; j < objThietBi.ctthietbis.Count; j++)
                                        {
                                            //KHÔNG NÊN XÓA BĂNG TAY KIÊU NÀY
                                            //objThietBi.ctthietbis.ElementAt(j).delete();
                                        }
                                    }
                                    if (objThietBi.logthietbis != null)
                                    {
                                        for (int j = 0; j < objThietBi.logthietbis.Count; j++)
                                        {
                                            //KHÔNG NÊN XÓA BĂNG TAY KIÊU NÀY
                                            //objThietBi.logthietbis.ElementAt(j).delete();
                                        }
                                    }
                                    thanhcong = objThietBi.delete() > 0 && DBInstance.commit() > 0;
                                }
                                catch
                                {
                                    thanhcong = false;
                                    break;
                                }
                            }
                            if (thanhcong)
                            {
                                reLoad();
                                //splashScreenManager.CloseWaitForm();
                                XtraMessageBox.Show("Xóa thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                reLoad();
                                //splashScreenManager.CloseWaitForm();
                                XtraMessageBox.Show("Đã xảy ra lỗi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(this.Name + " : CRUD : " + ex.Message);
            }
        }
 private void CRUD()
 {
     try
     {
         switch (function)
         {
             case "add":
                 objThietBi = new ThietBi();
                 setDataObj();
                 if (objThietBi.add() > 0 && DBInstance.commit() > 0)
                 {
                     XtraMessageBox.Show("Thêm thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     reLoadAndFocused(objThietBi.id);
                 }
                 break;
             case "edit":
                 setDataObj();
                 if (objThietBi.update() > 0 && DBInstance.commit() > 0)
                 {
                     XtraMessageBox.Show("Sửa thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     reLoadAndFocused(objThietBi.id);
                 }
                 break;
             case "delete":
                 //Xóa sạch, ko luyến tiếc
                 int[] indexCacRow = gridViewThietBi.GetSelectedRows();
                 String message = "";
                 Boolean thanhcong = true;
                 if (indexCacRow.Count() == 1)
                     message = "Bạn có chắc là xóa thiết bị này?";
                 if (indexCacRow.Count() > 1)
                     message = "Bạn có chắc là xóa những thiết bị đã chọn?";
                 if (indexCacRow.Count() > 0)
                 {
                     if (XtraMessageBox.Show(message, "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                     {
                         //splashScreenManager.ShowWaitForm();
                         //splashScreenManager.SetWaitFormCaption("Đang xóa thiết bị");
                         for (int i = 0; i < indexCacRow.Count(); i++)
                         {
                             try
                             {
                                 objThietBi = gridViewThietBi.GetRow(indexCacRow[i]) as ThietBi;
                                 if (objThietBi.ctthietbis != null)
                                 {
                                     for (int j = 0; j < objThietBi.ctthietbis.Count; j++)
                                     {
                                         //KHÔNG NÊN XÓA BĂNG TAY KIÊU NÀY
                                         //objThietBi.ctthietbis.ElementAt(j).delete();
                                     }
                                 }
                                 if (objThietBi.logthietbis != null)
                                 {
                                     for (int j = 0; j < objThietBi.logthietbis.Count; j++)
                                     {
                                         //KHÔNG NÊN XÓA BĂNG TAY KIÊU NÀY
                                         //objThietBi.logthietbis.ElementAt(j).delete();
                                     }
                                 }
                                 thanhcong = objThietBi.delete() > 0 && DBInstance.commit() > 0;
                             }
                             catch
                             {
                                 thanhcong = false;
                                 break;
                             }
                         }
                         if (thanhcong)
                         {
                             reLoad();
                             //splashScreenManager.CloseWaitForm();
                             XtraMessageBox.Show("Xóa thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         }
                         else
                         {
                             reLoad();
                             //splashScreenManager.CloseWaitForm();
                             XtraMessageBox.Show("Đã xảy ra lỗi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         }
                     }
                 }
                 break;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + " : CRUD : " + ex.Message);
     }
 }