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_cartype oObject = new tbm_cartype(); oConn.Open(); oObject.Koneksi = oConn.Conn; oObject.typeid = Convert.ToString(gridViewData.GetFocusedRowCellValue(colTypeid)); 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, ""); } } }
private void gridViewData_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { using (clsConnection oConn = new clsConnection()) { string typeid = Convert.ToString(gridViewData.GetFocusedRowCellValue(colTypeid)); string strCount = clsGlobal.getData1Field("select count(*) from tbm_cartype where dlt='0' and trim(lower(typename))=trim(lower('" + Convert.ToString(gridViewData.GetFocusedRowCellValue(colTypename)) + "')) and typeid <>'" + typeid + "'"); if (Convert.ToInt32(strCount) == 0) { tbm_cartype oObject = new tbm_cartype(); oConn.Open(); oObject.Koneksi = oConn.Conn; if (!string.IsNullOrEmpty(typeid)) { oObject.GetByPrimaryKey(typeid); } string categoryid = clsGlobal.getData1Field("select carcategoryid from tbm_carcategory where carcategoryname='" + Convert.ToString(gridViewData.GetFocusedRowCellValue(colCategoryname)) + "'"); string brandid = clsGlobal.getData1Field("select carbrandid from tbm_carbrand where brandname='" + Convert.ToString(gridViewData.GetFocusedRowCellValue(colBrandname)) + "'"); oObject.typeid = Convert.ToString(gridViewData.GetFocusedRowCellValue(colTypeid)); oObject.categoryid = categoryid; oObject.brandid = brandid; oObject.typename = Convert.ToString(gridViewData.GetFocusedRowCellValue(colTypename)); if (oObject.categoryname == "") { XtraMessageBox.Show("Data Can't Be Null", "Warning"); } else { if (string.IsNullOrEmpty(typeid)) { oObject.typeid = oObject.NewID(); oObject.opadd = clsGlobal.strUserName; oObject.pcadd = SystemInformation.ComputerName; oObject.luadd = DateTime.Now; oObject.Insert(); gridViewData.SetFocusedRowCellValue(colTypeid, oObject.typeid); } 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(colTypename)) + " already exists in database and cannot be filled the same value.!\n"; gridViewData.FocusedColumn = colTypename; e.Valid = false; return; } } } catch (NpgsqlException ex) { ////clsGlobal.generateErrMessageAndSendmail(ex, false); } catch (Exception ex) { ////clsGlobal.generateErrMessageAndSendmail(ex, false); } }