Ejemplo n.º 1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (XtraMessageBox.Show(this, "Are you sure to delete selected record?", clsGlobal.pstrAppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         try
         {
             using (clsConnection oConn = new clsConnection())
             {
                 frmMain.setLoadDialog(true, "Deleting data...");
                 tbm_carcategory oObject = new tbm_carcategory();
                 oConn.Open();
                 oObject.Koneksi    = oConn.Conn;
                 oObject.categoryid = Convert.ToString(gridViewData.GetFocusedRowCellValue(colCarBrandId));
                 oObject.opedit     = clsGlobal.strUserName;
                 oObject.pcedit     = SystemInformation.ComputerName;
                 oObject.SoftDelete();
                 oObject = null;
                 gridViewData.DeleteSelectedRows();
                 XtraMessageBox.Show(this, "Record Successfully Deleted", clsGlobal.pstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         catch (NpgsqlException ex)
         {
         }
         catch (Exception ex)
         {
             ////clsGlobal.generateErrMessageAndSendmail(ex, false);
         }
         finally
         {
             frmMain.setLoadDialog(false, "");
         }
     }
 }
Ejemplo n.º 2
0
        private void gridViewData_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                using (clsConnection oConn = new clsConnection())
                {
                    string categoryId = Convert.ToString(gridViewData.GetFocusedRowCellValue(colCarCategoryId));
                    string strCount   = clsGlobal.getData1Field("select count(*) from tbm_carcategory where dlt='0' and trim(lower(carcategoryname))=trim(lower('" + Convert.ToString(gridViewData.GetFocusedRowCellValue(colCategoryName)) + "')) and carcategoryid <>'" + categoryId + "'");
                    if (Convert.ToInt32(strCount) == 0)
                    {
                        tbm_carcategory oObject = new tbm_carcategory();
                        oConn.Open();
                        oObject.Koneksi = oConn.Conn;
                        if (!string.IsNullOrEmpty(categoryId))
                        {
                            oObject.GetByPrimaryKey(categoryId);
                        }
                        oObject.categoryid   = Convert.ToString(gridViewData.GetFocusedRowCellValue(colCarCategoryId));
                        oObject.categoryname = Convert.ToString(gridViewData.GetFocusedRowCellValue(colCategoryName));

                        if (oObject.categoryname == "")
                        {
                            XtraMessageBox.Show("Data Can't Be Null", "Warning");
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(categoryId))
                            {
                                oObject.categoryid = oObject.NewID();
                                oObject.opadd      = clsGlobal.strUserName;
                                oObject.pcadd      = SystemInformation.ComputerName;
                                oObject.luadd      = DateTime.Now;
                                oObject.Insert();
                                gridViewData.SetFocusedRowCellValue(colCarCategoryId, oObject.categoryid);
                            }
                            else
                            {
                                oObject.opedit = clsGlobal.strUserName;
                                oObject.pcedit = SystemInformation.ComputerName;
                                oObject.luedit = DateTime.Now;
                                oObject.Update();
                            }
                            oObject = null;
                            e.Valid = true;
                        }
                    }
                    else
                    {
                        e.ErrorText = "This code " + Convert.ToString(gridViewData.GetFocusedRowCellValue(colCategoryName)) + " already exists in database and cannot be filled the same value.!\n";
                        gridViewData.FocusedColumn = colCategoryName;
                        e.Valid = false;
                        return;
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                ////clsGlobal.generateErrMessageAndSendmail(ex, false);
            }
            catch (Exception ex)
            {
                ////clsGlobal.generateErrMessageAndSendmail(ex, false);
            }
        }