private void tgridViewTable_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F9) { ExportDataToExcel(); return; } if (e.KeyCode == Keys.F2) { iCurrentPage = 1; strCondition = strOnlyHashTable; MST_SearchPartyBO objBO = new MST_SearchPartyBO(); TotalRecord = objBO.GetRowCount(strTable, strCondition); GetNumberOfPage(); InitCombobox(); dset = objBO.GetList(strTable, strKeyWord, SelectMultiRow, strCondition, iCurrentPage, PCSComUtils.Common.Constants.CountPage); BindData(); ValueFilter = string.Empty; return; } if (GetTotalPage > 1 && (e.KeyCode == Keys.PageDown || e.KeyCode == Keys.PageUp || e.KeyCode == Keys.Home || e.KeyCode == Keys.End)) { bool bContinue = false; if (e.KeyCode == Keys.PageDown && GetTotalPage > iCurrentPage) { iCurrentPage++; bContinue = true; } if (e.KeyCode == Keys.PageUp && iCurrentPage > 1) { iCurrentPage--; bContinue = true; } if (e.KeyCode == Keys.Home && iCurrentPage > 1) { iCurrentPage = 1; bContinue = true; } if (e.KeyCode == Keys.End && iCurrentPage < GetTotalPage) { iCurrentPage = GetTotalPage; bContinue = true; } if (bContinue) { cmbPage.SelectedIndex = iCurrentPage - 1; MST_SearchPartyBO objBO = new MST_SearchPartyBO(); dset = objBO.GetList(strTable, strKeyWord, SelectMultiRow, strCondition, iCurrentPage, PCSComUtils.Common.Constants.CountPage); BindData(); } } //MessageBox.Show(tgridViewTable.Row.ToString()); //e.KeyCode == Keys.F4 if (tgridViewTable.FilterBar == true && !string.IsNullOrEmpty(ValueFilter) && e.KeyCode == Keys.Enter) { const string METHOD_NAME = ".tgridViewTable_KeyDown()"; try { if (sender.Equals(mniContain)) { enmLike = LikeCondition.Contain; } else { enmLike = sender.Equals(mniEndWith) ? LikeCondition.EndWith : LikeCondition.StartWith; } string strColoumName = tgridViewTable.Columns[tgridViewTable.Col].Caption; if (tgridViewTable.Col == 0) { return; } string strColoumValue = string.Empty; strCondition = strOnlyHashTable; if (strCondition != null && strCondition.Length > 0) { strCondition += " AND "; } strCondition += strColoumName + " like N'%" + ValueFilter + "%' "; iCurrentPage = 1; strCondition = FormControlComponents.KillInjectionInLikeClause(strCondition); MST_SearchPartyBO objBO = new MST_SearchPartyBO(); TotalRecord = objBO.GetRowCount(strTable, strCondition); GetNumberOfPage(); InitCombobox(); dset = objBO.GetList(strTable, strKeyWord, SelectMultiRow, strCondition, iCurrentPage, PCSComUtils.Common.Constants.CountPage); BindData(); ValueFilter = string.Empty; } catch (PCSException ex) { // Displays the error message if throwed from PCSException. PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error); try { // Log error message into log file. Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR); } catch { // Show message if logger has an error. PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error); } } catch (Exception ex) { // Displays the error message if throwed from system. PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error); try { // Log error message into log file. Logger.LogMessage(ex, METHOD_NAME, Level.ERROR); } catch { // Show message if logger has an error. PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error); } } return; } if (e.KeyCode == Keys.Enter) { GetDataRow(); } }
private string GenerateFilterConditionToSQL(string strFilterFieldValue, string strFilterFieldName, Hashtable htbOrtherFilterCondition) { StringBuilder strFilterCondition = new StringBuilder(); if (htbOrtherFilterCondition != null) { var myEnumerator = htbOrtherFilterCondition.GetEnumerator(); while (myEnumerator.MoveNext()) { if (myEnumerator.Value == DBNull.Value) { if (strFilterCondition.Length > 0) { strFilterCondition.Append(" AND "); } strFilterCondition.Append(strTable + "." + myEnumerator.Key.ToString().Trim()); strFilterCondition.Append("IS NULL"); } else if (myEnumerator.Value.ToString().ToUpper().Contains("IS NOT NULL")) { if (strFilterCondition.Length > 0) { strFilterCondition.Append(" AND "); } strFilterCondition.Append(strTable + "." + myEnumerator.Key.ToString().Trim()); strFilterCondition.Append("IS NOT NULL"); } else { if (strFilterCondition.Length > 0) { strFilterCondition.Append(" AND "); } strFilterCondition.Append(strTable + "." + myEnumerator.Key.ToString().Trim()); strFilterCondition.Append("=N'"); strFilterCondition.Append(myEnumerator.Value); strFilterCondition.Append("'"); } } strOnlyHashTable = strFilterCondition.ToString(); } strFilterFieldValue = FormControlComponents.KillInjection(strFilterFieldValue); if (!string.IsNullOrEmpty(strFilterFieldName) && strFilterFieldValue != string.Empty) { if (strFilterCondition.Length > 0) { strFilterCondition.Append(" AND "); } strFilterCondition.Append(strTable + "." + strFilterFieldName); strFilterCondition.Append(" LIKE N'%"); strFilterCondition.Append(strFilterFieldValue.Replace("'", "''")); strFilterCondition.Append("%'"); } #region /// HACKED: Thachnn: fix bug injection StringBuilder sql = new StringBuilder(); sql.Append(FormControlComponents.KillInjectionInLikeClause(strFilterCondition.ToString())); #endregion /// ENDHACKED: Thachnn: fix bug injection //var strConditionByRecord = Utilities.Instance.GetConditionByRecord(SystemProperty.UserName, strTableNameOrView); //sql.Append(strConditionByRecord); return(sql.ToString()); }