示例#1
0
        private static string GetJoinedDateCode()
        {
            string code = null;

            try
            {
                string str = "CREATE PROCEDURE [dbo].[sp_GetJoinedDate](@StaffID int,@JoinedDate datetime output)";

                // Parse the stored procedure signature
                SPSignature signature = new SPSignature(str);

                code = SPCallerGen.GenCode(signature, "GetJoinedDate", SPCallerGen.ReturnType.Tables, null, null, false);
            }
            catch (System.Exception ex)
            {
                Debug.Print(ex.Message);
            }
            return(code);
        }
示例#2
0
        private static string GetAllEmployeeCode()
        {
            string code = null;

            try
            {
                string str = "CREATE PROCEDURE [dbo].[sp_GetAllEmployee]";

                // Parse the stored procedure signature
                SPSignature signature = new SPSignature(str);

                code = SPCallerGen.GenCode(signature, "GetAllEmployee", SPCallerGen.ReturnType.Tables, null, null, false);
            }
            catch (System.Exception ex)
            {
                Debug.Print(ex.Message);
            }
            return(code);
        }
示例#3
0
        private static string InsertEmployeeCode()
        {
            string code = null;

            try
            {
                string str = "CREATE PROCEDURE [dbo].[sp_InsertEmp](";
                str += "@ID int OUTPUT," + "@Name nvarchar(30),";
                str += "@Title varchar(20)," + "@Address varchar(30),";
                str += "@Salary money," + "@JoinedDate datetime,";
                str += "@Children tinyint)";

                // Parse the stored procedure signature
                SPSignature signature = new SPSignature(str);

                code = SPCallerGen.GenCode(signature, "InsertEmployee", SPCallerGen.ReturnType.None, null, null, false);
            }
            catch (System.Exception ex)
            {
                Debug.Print(ex.Message);
            }
            return(code);
        }
示例#4
0
        private void btnGenCode_Click(object sender, RoutedEventArgs e)
        {
            string msg = null;

            if (string.IsNullOrEmpty(txtSignature.Text))
            {
                msg = "Signature is not specified.";
            }
            if (string.IsNullOrEmpty(txtMethodName.Text))
            {
                msg = "Method Name is not specified.";
            }

            if (string.IsNullOrEmpty(msg) == false)
            {
                MessageBox.Show(msg);
                return;
            }

            string code = string.Empty;

            if (chkMySql.IsChecked == false)
            {
                SPCallerGen.ReturnType retType = SPCallerGen.ReturnType.Tables;
                if (radioTables.IsChecked == true)
                {
                    retType = SPCallerGen.ReturnType.Tables;
                }
                else if (radioInteger.IsChecked == true)
                {
                    retType = SPCallerGen.ReturnType.Integer;
                }
                else if (radioNone.IsChecked == true)
                {
                    retType = SPCallerGen.ReturnType.None;
                }
                else
                {
                    MessageBox.Show("No return type is selected.");
                    return;
                }

                SPSignature signature = new SPSignature();
                try
                {
                    signature.Parse(txtSignature.Text + " ", chkNoNullableTypes.IsChecked == true);
                    if (signature.HasTableParam)
                    {
                        GetTableScriptWin form = new GetTableScriptWin();
                        form.SProcSignature = signature;
                        form.ShowDialog();
                        if (form.TableTypeSignatureList.Count != signature.TableParamNum)
                        {
                            MessageBox.Show("Error with getting table script", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        foreach (TableTypeSignature ttSign in form.TableTypeSignatureList)
                        {
                            code += TableTypeGen.GenCode(ttSign);
                        }
                    }
                    code += SPCallerGen.GenCode(signature, txtMethodName.Text, retType, null, null, false);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error:" + ex.Message);
                    return;
                }
            }
            else
            {
                SPMySQLCallerGen.ReturnType retType = SPMySQLCallerGen.ReturnType.Tables;
                if (radioTables.IsChecked == true)
                {
                    retType = SPMySQLCallerGen.ReturnType.Tables;
                }
                else if (radioInteger.IsChecked == true)
                {
                    retType = SPMySQLCallerGen.ReturnType.Integer;
                }
                else if (radioNone.IsChecked == true)
                {
                    retType = SPMySQLCallerGen.ReturnType.None;
                }
                else
                {
                    MessageBox.Show("No return type is selected.");
                    return;
                }

                SPMySQLSignature signature = new SPMySQLSignature();
                try
                {
                    signature.Parse(txtSignature.Text, chkNoNullableTypes.IsChecked == true);
                    code += SPMySQLCallerGen.GenCode(signature, txtMethodName.Text, retType, null, null, false);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error:" + ex.Message);
                    return;
                }
            }

            if (string.IsNullOrEmpty(code) == false)
            {
                Clipboard.SetData(DataFormats.Text, code);
                MessageBox.Show("The auto-generated code has been copied to clipboard!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("No code is generated", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#5
0
        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);
            }
        }