Closed tieuquyngok1995 closed 3 years ago
private void lstDataSQL_MouseClick(object sender, MouseEventArgs e) { if (lstDataSQL.SelectedRows.Count > 0) { int selectedrowindex = lstDataSQL.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = lstDataSQL.Rows[selectedrowindex]; strInputSQL = Convert.ToString(selectedRow.Cells[CONSTANTS.CONST_STRING_COLUMNS_SQL].Value); if (!string.IsNullOrEmpty(strInputSQL)) { lstParam = new List<string>(); dataParam.Clear(); handleInputParam(strInputSQL); btnConvert.Enabled = true; } } } public void handleInputParam(string strSQL) { try { string[] arrInputSQL = strSQL.Split(CONSTANTS.CONST_CHAR_LINE_BREAK); string result = string.Empty; string itemCheck = string.Empty; foreach (string item in arrInputSQL) { if (item.Contains(CONSTANTS.CONST_STRING_CHECK_IF) || item.Contains(CONSTANTS.CONST_STRING_CHECK_ELSE)) { string strItem = item.Replace(CONSTANTS.CONST_STRING_CHECK_IF, string.Empty). Replace(CONSTANTS.CONST_STRING_CHECK_ELSE, string.Empty).Trim(); string[] arrItem = strItem.Split(new string[] { CONSTANTS.CONST_STRING_AND_ALSO, CONSTANTS.CONST_STRING_AND, CONSTANTS.CONST_STRING_OR_ELSE, CONSTANTS.CONST_STRING_OR, CONSTANTS.CONST_STRING_UPPER_AND_ALSO, CONSTANTS.CONST_STRING_UPPER_AND, CONSTANTS.CONST_STRING_UPPER_OR_ELSE, CONSTANTS.CONST_STRING_UPPER_OR }, StringSplitOptions.None); foreach (string itemParam in arrItem) { if (string.IsNullOrEmpty(itemParam)) { continue; } result = handleItemParam(itemParam, lstParam); if (!string.IsNullOrEmpty(result)) { strInputSQL = strInputSQL.Replace(itemParam, result); } } } else { if (string.IsNullOrEmpty(item)) continue; int indexRow = 1; string[] arrItem = item.Split(new string[] { CONSTANTS.CONST_STRING_CHECK_PARAM_OPEN, CONSTANTS.CONST_STRING_CHECK_PARAM_CLOSE }, StringSplitOptions.None); while (indexRow < arrItem.Length) { if (!string.IsNullOrEmpty(arrItem[indexRow])) { itemCheck = arrItem[indexRow].Replace(CONSTANTS.CONST_STRING_CHECK_PARAM_CLOSE, string.Empty).Trim(); if (lstParam.Count == 0 || !lstParam.Any(itemLst => itemLst.Equals(itemCheck))) { lstParam.Add(itemCheck); } } indexRow += 2; }; } } // Add data to data grid view handleDataToLstInputParam(lstParam); } catch (Exception ex) { MessageBox.Show("An abnormal error occurs in the function: HandleInputParam\nError content: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
region Input Param