Example #1
0
        public string BuildFieldClause(DataJuggler.Net.DataRow FieldRow, DataJuggler.Net.DataField Field, int FieldCount)
        {
            // if FieldCount > 0
            StringBuilder sb = new StringBuilder();

            // If FieldCount > 0
            if (FieldCount > 1)
            {
                // Append The Word And
                sb.Append(" And ");
            }

            // Append fieldName
            sb.Append(Field.FieldName);
            sb.Append(" = ");

            // If This Is Not Numeric Data Add Single Quote '
            if (!FieldRow.IsNumericDataType(Field.DataType))
            {
                sb.Append("'");
            }

            // Append fieldValue
            sb.Append(Field.FieldValue);

            // If This Is Not Numeric Data Add Single Quote '
            if (!FieldRow.IsNumericDataType(Field.DataType))
            {
                sb.Append("'");
            }

            // Return New String
            return(sb.ToString());
        }
Example #2
0
        public bool IsUpdateable(DataJuggler.Net.DataRow Row)
        {
            // Initial Value
            bool updateable = false;

            // Check If There Is A PrimaryKey
            DataJuggler.Net.DataField PrimaryKey = Row.PrimaryKey();

            // Check If PrimaryKey Exists
            if (PrimaryKey.FieldName == "void")
            {
                // Not Updateable
                updateable = false;
            }
            else
            {
                // Check If PrimaryKey Has A Value
                // If It Does Have A Value Then It Is Updateable
                // Else It Is Not
                updateable = PrimaryKey.HasValue();
            }

            // return value
            return(updateable);
        }
Example #3
0
        /// <summary>
        /// This method prepares this control to be shown
        /// </summary>
        public void Setup(MethodInfo methodInfo, Project openProject, CustomReader customReader = null, DTNField orderByField = null, FieldSet orderByFieldSet = null)
        {
            // store the args
            this.MethodInfo  = methodInfo;
            this.OpenProject = openProject;

            // locals
            DataJuggler.Net.DataField        parameter  = null;
            List <DataJuggler.Net.DataField> parameters = null;
            ProcedureWriter writer = null;

            // If the MethodInfo object exists
            if (this.HasMethodInfo)
            {
                // create a new
                MethodsWriter methodsWriter = new MethodsWriter();

                // get the StoredXml
                StoredXml = methodsWriter.ExportMethodInfo(this.MethodInfo);

                // if the OrderByFieldSet object exists
                if (NullHelper.Exists(orderByFieldSet))
                {
                    // set the gateway
                    Gateway gateway = new Gateway();

                    // load the orderByFields
                    orderByFieldSet.FieldSetFields = gateway.LoadFieldSetFieldViewsByFieldSetId(orderByFieldSet.FieldSetId);
                }

                // Set the Name of the Table
                this.SelectedTableControl.Text = this.MethodInfo.SelectedTable.TableName;

                // set the procedureName
                this.ProcedureNameControl.Text = MethodInfo.ProcedureName;

                // Check the button for Manual Update (user clicks Copy and goes to their SQL instance and executes).
                this.ManualUpdateRadioButton.Checked = true;

                // Check the box if UseCustomReader is true
                this.CustomWhereCheckBox.Checked = MethodInfo.UseCustomWhere;

                // Set the CustomWhereText (if any)
                this.WhereTextBox.Text = MethodInfo.WhereText;

                // convert the table
                DataJuggler.Net.DataTable table = DataConverter.ConvertDataTable(MethodInfo.SelectedTable, this.OpenProject);

                // if this is a Single Field Parameter and the Parameter Field exists
                if ((MethodInfo.ParameterType == ParameterTypeEnum.Single_Field) && (MethodInfo.HasParameterField))
                {
                    // convert the field from a DTNField to a DataJuggler.Net.DataField
                    parameter = DataConverter.ConvertDataField(MethodInfo.ParameterField);

                    // Create a new instance of a 'ProcedureWriter' object (in TextWriter mode).
                    writer = new ProcedureWriter(true);

                    // if this is a FindByField method
                    if (writer.HasTextWriter)
                    {
                        // If Delete By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Delete_By)
                        {
                            // Write out the Delete Proc
                            writer.CreateDeleteProc(table, MethodInfo.ProcedureName, parameter);
                        }
                        // If Find By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Find_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, false, MethodInfo.ProcedureName, parameter, customReader, orderByField, orderByFieldSet, methodInfo.OrderByDescending, methodInfo.TopRows);
                        }
                        // if Load By is the Method Type
                        else if (MethodInfo.MethodType == MethodTypeEnum.Load_By)
                        {
                            // If the orderByField object exists
                            if (NullHelper.Exists(orderByFieldSet))
                            {
                                // if there are not any fields loaded
                                if (!ListHelper.HasOneOrMoreItems(orderByFieldSet.Fields))
                                {
                                    // load the Fields
                                    orderByFieldSet.Fields = FieldSetHelper.LoadFieldSetFields(orderByFieldSet.FieldSetId);
                                }
                            }

                            // create a find procedure
                            writer.CreateFindProc(table, true, MethodInfo.ProcedureName, parameter, customReader, orderByField, orderByFieldSet, methodInfo.OrderByDescending, methodInfo.TopRows);
                        }
                    }
                }
                else if ((MethodInfo.ParameterType == ParameterTypeEnum.Field_Set) && (MethodInfo.HasParameterFieldSet) && (MethodInfo.ParameterFieldSet.HasFields))
                {
                    // convert the DTNFields to DataFields
                    parameters = DataConverter.ConvertDataFields(MethodInfo.ParameterFieldSet.Fields);

                    // If the parameters collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(parameters))
                    {
                        // set the FieldSetName so the description writes the method description correctly
                        parameters[0].FieldSetName = MethodInfo.ParameterFieldSet.Name;
                    }

                    // Create a new instance of a 'ProcedureWriter' object (in TextWriter mode).
                    writer = new ProcedureWriter(true);

                    // if this is a FindByField method
                    if (writer.HasTextWriter)
                    {
                        // If Delete By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Delete_By)
                        {
                            // Write out the Delete Proc
                            writer.CreateDeleteProc(table, MethodInfo.ProcedureName, parameters);
                        }
                        // If Find By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Find_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, false, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                        // if Load By is the Method Type
                        else if (MethodInfo.MethodType == MethodTypeEnum.Load_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, true, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                    }
                }
                else if ((MethodInfo.ParameterType == ParameterTypeEnum.No_Parameters))
                {
                    // Create a new instance of a 'ProcedureWriter' object (in TextWriter mode).
                    writer = new ProcedureWriter(true);

                    // if this is a FindByField method
                    if (writer.HasTextWriter)
                    {
                        // If Delete By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Delete_By)
                        {
                            // Write out the Delete Proc
                            writer.CreateDeleteProc(table, MethodInfo.ProcedureName, parameters);
                        }
                        // If Find By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Find_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, false, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                        // if Load By is the Method Type
                        else if (MethodInfo.MethodType == MethodTypeEnum.Load_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, true, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                    }
                }

                // if the writer exists
                if (NullHelper.Exists(writer))
                {
                    // get the procedureText
                    string procedureText = writer.TextWriter.ToString();

                    // Show the Where Panel if CustomWhere is true
                    WherePanel.Visible = MethodInfo.UseCustomWhere;

                    // if CustomWhere
                    if (MethodInfo.UseCustomWhere)
                    {
                        // now the existing where text must be replaced
                        int whereIndex = procedureText.ToLower().IndexOf("where [");

                        // if the WhereText does not exist yet
                        if ((!MethodInfo.HasWhereText) && (whereIndex > 0))
                        {
                            // Set the text as it is now
                            string whereText = procedureText.Substring(whereIndex);

                            // If the whereText string exists
                            if (TextHelper.Exists(whereText))
                            {
                                // get the textLines
                                List <TextLine> textLines = WordParser.GetTextLines(whereText);

                                // If the textLines collection exists and has one or more items
                                if (ListHelper.HasOneOrMoreItems(textLines))
                                {
                                    // Create a new instance of a 'StringBuilder' object.
                                    StringBuilder sb = new StringBuilder();

                                    // add each textLine of the Where Clause except the last one
                                    foreach (TextLine textLine in textLines)
                                    {
                                        // if this is the End line
                                        if (!textLine.Text.ToLower().StartsWith("end"))
                                        {
                                            // Add this line
                                            sb.Append(textLine.Text);
                                        }
                                    }

                                    // Get the Where Clause
                                    MethodInfo.WhereText = sb.ToString().Trim();
                                }
                            }
                        }

                        // Set the WhereText
                        WhereTextBox.Text = MethodInfo.WhereText;

                        // if the whereIndex was found
                        if (whereIndex >= 0)
                        {
                            // if the WhereText does not already exist
                            if (!TextHelper.Exists(MethodInfo.WhereText))
                            {
                                // Set the default WhereText
                                MethodInfo.WhereText = procedureText.Substring(whereIndex);
                            }

                            // set the new ProcedureText
                            procedureText = procedureText.Substring(0, whereIndex) + MethodInfo.WhereText + Environment.NewLine + Environment.NewLine + "END";
                        }
                    }

                    // Remove any double blank lines
                    procedureText = CodeLineHelper.RemoveDoubleBlankLines(procedureText);

                    // display the procedure As Is for now.
                    this.ProcedureTextBox.Text = procedureText;
                }
            }
        }