private void btnParse_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(txtFunctionName.Text)) { MessageBox.Show("Please fill in the function name"); return; } if (string.IsNullOrEmpty(txtSQL.Text)) { MessageBox.Show("Please fill in the SQL statement"); return; } _Signature = new SPSignature(); _Signature.Name = txtFunctionName.Text; List <string> listParamStr = _Signature.GetAllParam(txtSQL.Text); if (listParamStr.Count == 0) { MessageBox.Show("No @ parameters found"); return; } _ListParam = new List <Parameter>(); foreach (string str in listParamStr) { _ListParam.Add(new Parameter { Name = str, SQLType = "NVarChar", TextLength = "50" }); } SQLType type = _Signature.GetType(txtSQL.Text); if (type == SQLType.INSERT) { chkReturnPrimaryKey.IsEnabled = true; } else { chkReturnPrimaryKey.IsEnabled = false; } if (type == SQLType.SELECT) { chkUseSQLReader.IsEnabled = true; } else { chkUseSQLReader.IsEnabled = false; } listBoxSQPParameterType.ItemsSource = _ListParam; btnGenerateCode.IsEnabled = true; }
private void btnGenerateCode_Click(object sender, RoutedEventArgs e) { if (_Signature == null) { MessageBox.Show("Please click the Parse button first"); return; } _Signature.ClearAllColumns(); foreach (var par in _ListParam) { _Signature.AddColumn(par.Name, par.SQLType, par.TextLength); } _Signature.Sql = txtSQL.Text; SQLType type = _Signature.GetType(txtSQL.Text); string GeneratedCode = string.Empty; if (type == SQLType.INSERT) { if (chkReturnPrimaryKey.IsChecked == true) { GeneratedCode = SPCallerGen.GenInsertRetPriKeyCode(_Signature, _Signature.Name, txtAddParameterCode.Text, txtAddExceptionCode.Text, chkPassConnection.IsChecked ?? false, chkPassTransaction.IsChecked ?? false, chkUseTransaction.IsChecked ?? false); } else { GeneratedCode = SPCallerGen.GenInsertCode(_Signature, _Signature.Name, txtAddParameterCode.Text, txtAddExceptionCode.Text, chkPassConnection.IsChecked ?? false, chkPassTransaction.IsChecked ?? false, chkUseTransaction.IsChecked ?? false); } } else if (type == SQLType.SELECT) { if (chkUseSQLReader.IsChecked == true) { GeneratedCode = SPCallerGen.GenSelectReaderCode(_Signature, _Signature.Name, txtAddParameterCode.Text, txtAddExceptionCode.Text, chkPassConnection.IsChecked ?? false, chkPassTransaction.IsChecked ?? false, chkUseTransaction.IsChecked ?? false); } else { GeneratedCode = SPCallerGen.GenSelectCode(_Signature, _Signature.Name, txtAddParameterCode.Text, txtAddExceptionCode.Text, chkPassConnection.IsChecked ?? false, chkPassTransaction.IsChecked ?? false, chkUseTransaction.IsChecked ?? false); } } else if (type == SQLType.UPDATE) { GeneratedCode = SPCallerGen.GenUpdateCode(_Signature, _Signature.Name, txtAddParameterCode.Text, txtAddExceptionCode.Text, chkPassConnection.IsChecked ?? false, chkPassTransaction.IsChecked ?? false, chkUseTransaction.IsChecked ?? false); } else if (type == SQLType.DELETE) { GeneratedCode = SPCallerGen.GenDeleteCode(_Signature, _Signature.Name, txtAddParameterCode.Text, txtAddExceptionCode.Text, chkPassConnection.IsChecked ?? false, chkPassTransaction.IsChecked ?? false, chkUseTransaction.IsChecked ?? false); } if (string.IsNullOrEmpty(GeneratedCode) == false) { txtGeneratedCode.Text = GeneratedCode; if (chkCopyClipboard.IsChecked == true) { Clipboard.SetData(DataFormats.Text, GeneratedCode); MessageBox.Show("The auto-generated code has been copied to clipboard!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); return; } MessageBox.Show("The auto-generated code has been generated successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } else { txtGeneratedCode.Text = string.Empty; MessageBox.Show("No code is generated", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }