コード例 #1
0
        public void btnDelete_Click()
        {
            if (CurrentlySelectedFieldId == Guid.Empty)
            {
                return;
            }

            List <Guid> fieldIDs = CurrentFields.Select(field => field.Id).ToList();

            int currentFieldOffset = fieldIDs.IndexOf(CurrentlySelectedFieldId);

            Field_Delete(this.CurrentlySelectedFieldId);
            MakeClientDirty();

            if (currentFieldOffset < fieldIDs.Count - 1)
            {
                CurrentlySelectedFieldId = Guid.Empty;
                Field_Select(fieldIDs[currentFieldOffset + 1]);
            }
        }
コード例 #2
0
        private void Field_Select(Guid fieldId)
        {
            if (ValidateSave())
            {
                if (this.CurrentlySelectedFieldId != Guid.Empty)
                {
                    Field_Save();
                }

                InitializeDetailsSplitPanel();

                var selectedField = CurrentFields.Single(f => f.Id == fieldId);

                this.CurrentlySelectedFieldId = fieldId;

                this.NameField.Text = selectedField.Name;

                this.LabelField.Text = selectedField.Label;
                this.HelpField.Text  = selectedField.HelpText;

                string typeName = selectedField.Type.FullName.GetHashCode().ToString();

                if (this.TypeSelector.Items.FindByValue(typeName) != null)
                {
                    this.TypeSelector.SelectedValue = typeName;
                }
                else
                {
                    this.TypeSelector.Items.Insert(0, new ListItem("UNKNOWN TYPE: " + selectedField.Type.Name));
                }

                btnWidgetFunctionMarkup.Value = selectedField.WidgetFunctionMarkup;

                btnDefaultValueFunctionMarkup.Value = selectedField.DefaultValueFunctionMarkup;

                btnTestValueFunctionMarkup.Value = selectedField.TestValueFunctionMarkup;

                this.PositionField.SelectedValue = (selectedField.Position == this.CurrentFields.Count - 1 ? "-1" : selectedField.Position.ToString());
            }
        }
コード例 #3
0
ファイル: GenerateCode.cs プロジェクト: ghipkin/BiddyandBear
        private void GenerateDataLayer_Click(object sender, EventArgs e)
        {
            StringBuilder        sb             = null;
            List <DatabaseField> DatabaseFields = GetAllDatabaseFields();

            if (DatabaseFields.Count > 0)
            {
                sb = new StringBuilder();

                sb.AppendLine("using System;");
                sb.AppendLine("using System.Text;");
                sb.AppendLine("using System.Linq;");
                sb.AppendLine("using System.Configuration;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine("using System.Data;");
                sb.AppendLine("using System.Data.SqlClient;");
                sb.AppendLine("using System.Diagnostics.CodeAnalysis;");
                sb.AppendLine("using BB.DataLayer.Abstract;");
                sb.AppendLine();
                sb.AppendLine("namespace BB.DataLayer");
                sb.AppendLine("{");

                StringBuilder        AbstractClass = new StringBuilder();
                StringBuilder        RecordClass   = new StringBuilder();
                StringBuilder        MockClass     = new StringBuilder();
                string               CurrentTable  = string.Empty;
                List <DatabaseField> CurrentFields;
                bool IdExists;
                foreach (var Field in DatabaseFields)
                {
                    //are we onto a new table
                    if (CurrentTable != Field.TableName)
                    {
                        //if this is not the first table, then we need to finish off the last one
                        if (!string.IsNullOrEmpty(CurrentTable))
                        {
                            CurrentFields = DatabaseFields.Where(x => x.TableName == CurrentTable).ToList <DatabaseField>();
                            IdExists      = CurrentFields.Exists(x => x.IsIdentity == true);
                            FinishMockClass(MockClass, CurrentTable, IdExists);

                            //Add the overriding methods for the previous class(es)
                            FinishAbstractClass(CurrentTable, CurrentFields, AbstractClass);
                            FinishRecordClass(CurrentTable, CurrentFields, IdExists, RecordClass);

                            //append the abstract record and mocked class to the main stringbuilder
                            sb.AppendLine(AbstractClass.ToString());
                            sb.AppendLine(RecordClass.ToString());
                            sb.AppendLine(MockClass.ToString());

                            //Renew Class StringBuilders for the next table
                            AbstractClass = new StringBuilder();
                            RecordClass   = new StringBuilder();
                            MockClass     = new StringBuilder();
                        }
                        //Create Collection classes
                        string PluralTableName = GetPlural(Field.TableName);
                        GetParentCollectionClass(Field.TableName, PluralTableName, sb);
                        sb.AppendLine("");
                        GetCollectionClass(Field.TableName, PluralTableName, DatabaseFields.Where(x => x.TableName == Field.TableName).ToList <DatabaseField>(), sb);
                        sb.AppendLine("");
                        GetMockCollectionClass(Field.TableName, PluralTableName, DatabaseFields.Where(x => x.TableName == Field.TableName).ToList <DatabaseField>(), sb);
                        sb.AppendLine("");

                        //initialise the abstract, mock and record classes
                        GetClassHeader("ADL_" + Field.TableName, AbstractClass);
                        GetClassHeader("DL_" + Field.TableName, RecordClass, "ADL_" + Field.TableName);
                        GetClassHeader("MOCK_DL_" + Field.TableName, MockClass, "ADL_" + Field.TableName);
                        //add Error message constant to the mock class
                        MockClass.Append("\t\tpublic const string ERR_SAVE_FAILED = \"Could not save ");
                        MockClass.Append(Field.TableName);
                        MockClass.AppendLine(" record.\";");
                    }

                    //get the property code for the abstract class
                    GetPropertyText(Field, AbstractClass);

                    //get the current table
                    CurrentTable = Field.TableName;
                }

                CurrentFields = DatabaseFields.Where(x => x.TableName == CurrentTable).ToList <DatabaseField>();
                IdExists      = CurrentFields.Exists(x => x.IsIdentity == true);

                FinishMockClass(MockClass, CurrentTable, IdExists);

                //Add the overriding methods for the previous class(es)
                FinishAbstractClass(CurrentTable, CurrentFields, AbstractClass);
                FinishRecordClass(CurrentTable, CurrentFields, IdExists, RecordClass);

                //append the record and mocked class to the main stringbuilder
                sb.AppendLine(AbstractClass.ToString());
                sb.AppendLine();
                sb.AppendLine(RecordClass.ToString());
                sb.AppendLine();
                sb.AppendLine(MockClass.ToString());

                sb.AppendLine("}");

                string filename = Application.StartupPath + "\\..\\..\\..\\BB.DataLayer\\BBDataLayer.cs";
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }

                using (var fs = new FileStream(filename, FileMode.CreateNew))
                {
                    fs.Write(Encoding.ASCII.GetBytes(sb.ToString()), 0, sb.ToString().Length);
                    fs.Flush();
                }
            }
        }