public ActionResult Create(column column)
        {
            if (ModelState.IsValid)
            {
                db.columns.Add(column);
                db.SaveChanges();
                //for adding adding to the current sprint to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                var xx = db.projects.Select(x => x).Where(x => x.id == column.projectid).FirstOrDefault();

                String username = Convert.ToString(Session["UserName"]);
                activitystr.actiontype  = "Add Column";
                activitystr.description = username + " Added Column " + column.name + " To Project " + xx.projectname;
                activitystr.issueid     = 4;
                activitystr.issuekey    = "-";
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = column.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();

                return(RedirectToAction("indexproject", "Column", new { id = column.projectid }));;
            }

            ViewBag.projectid = new SelectList(db.projects, "id", "projectkey", column.projectid);
            return(View(column));
        }
Example #2
0
        public static Dictionary <string, column> getColumns(DataSet ds)
        {
            var tmpColumns = new Dictionary <string, column>();

            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    var tb = ds.Tables[0];
                    foreach (DataRow item in tb.Rows)
                    {
                        if (tmpColumns.ContainsKey(item["COLUMN_NAME"].ToString()))
                        {
                            var tmpcol = new column()
                            {
                                COLUMN_NAME = item["COLUMN_NAME"].ToString(),
                                COLUMN_ID   = Convert.ToInt32(item["COLUMN_ID"]),
                                DATA_LENGTH = Convert.ToInt32(item["DATA_LENGTH"]),
                                DATA_TYPE   = item["DATA_TYPE"].ToString(),
                                NULLABLE    = item["NULLABLE"].ToString()
                            };
                            tmpColumns.Add(tmpcol.COLUMN_NAME, tmpcol);
                        }
                    }
                }
            }
            return(tmpColumns);
        }
        public static Dictionary<string, column> getColumns(DataSet ds)
        {
            var tmpColumns = new Dictionary<string, column>();

            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    var tb = ds.Tables[0];
                    foreach (DataRow item in tb.Rows)
                    {
                        if (tmpColumns.ContainsKey(item["COLUMN_NAME"].ToString()))
                        {
                            var tmpcol = new column()
                            {
                                COLUMN_NAME = item["COLUMN_NAME"].ToString(),
                                COLUMN_ID = Convert.ToInt32(item["COLUMN_ID"]),
                                DATA_LENGTH = Convert.ToInt32(item["DATA_LENGTH"]),
                                DATA_TYPE = item["DATA_TYPE"].ToString(),
                                NULLABLE = item["NULLABLE"].ToString()
                            };
                            tmpColumns.Add(tmpcol.COLUMN_NAME, tmpcol);
                        }
                    }

                }
            }
            return tmpColumns;
        }
Example #4
0
        private String getTableColumns(FileInfo file, DlineageCommon dlineage)
        {
            if (dlineage.DataMetaInfos == null)
            {
                return(null);
            }
            StringBuilder buffer = new StringBuilder();

            for (int i = 0; i < dlineage.DataMetaInfos.Length; i++)
            {
                database db = dlineage.DataMetaInfos[i];
                for (int j = 0; j < db.tables.Length; j++)
                {
                    demos.dlineage.model.ddl.schema.table currentTable = db.tables[j];
                    if (currentTable.columns == null || currentTable.columns.Length == 0)
                    {
                        continue;
                    }

                    if (!string.ReferenceEquals(currentTable.isView, null) && true == Convert.ToBoolean(currentTable.isView))
                    {
                        continue;
                    }

                    if ("CONSTANT".Equals(currentTable.name))
                    {
                        continue;
                    }

                    String tableName = "";

                    if (currentTable.name.IndexOf(".") != -1)
                    {
                        tableName = currentTable.name.Replace(".", ",");
                    }
                    else
                    {
                        if (!string.ReferenceEquals(db.name, null) && !"unknown".Equals(db.name, StringComparison.CurrentCultureIgnoreCase))
                        {
                            tableName = (db.name + "," + currentTable.name);
                        }
                        else
                        {
                            tableName = ("," + currentTable.name);
                        }
                    }

                    for (int k = 0; k < currentTable.columns.Length; k++)
                    {
                        column column = currentTable.columns[k];
                        if ("*".Equals(column.name))
                        {
                            continue;
                        }
                        buffer.Append(tableName).Append(",").Append(column.name).Append(",").Append(file.Name).Append("\r\n");
                    }
                }
            }
            return(buffer.ToString());
        }
        public Chart Profits(DateTime Start, DateTime End, DateStatistics format)
        {
            Chart chartTevenue     = Tevenue(Start, End, format);
            Chart chartImportMoney = ImportMoney(Start, End, format);
            Chart chartProfits     = new Chart();



            int  count    = chartTevenue.ColumnCount;
            long maxValue = 0;

            for (int i = 0; i < count; i++)
            {
                column cl;
                cl.value   = chartTevenue.ListColumn[i].value - chartImportMoney.ListColumn[i].value;
                cl.percent = 0;

                cl.name = "" + chartTevenue.ListColumn[i].name;
                if (cl.value > maxValue)
                {
                    maxValue = cl.value;
                }
                chartProfits.ListColumn.Add(cl);
            }
            for (int i = 0; i < count; i++)
            {
                column cl = chartProfits.listColumn[i];
                cl.percent = cl.value / maxValue;
                chartProfits.listColumn[i] = cl;
            }

            return(chartProfits);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            column column = db.columns.Find(id);

            db.columns.Remove(column);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #7
0
 public UserInfo()
 {
     HEADER = new column {
         id_    = "Id",
         name_  = "Name",
         point_ = "Point"
     };
 }
        //
        // GET: /Column/Delete/5

        public ActionResult Delete(int id = 0)
        {
            column column = db.columns.Find(id);

            if (column == null)
            {
                return(HttpNotFound());
            }
            return(View(column));
        }
 public ActionResult Edit(column column)
 {
     if (ModelState.IsValid)
     {
         db.Entry(column).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.projectid = new SelectList(db.projects, "id", "projectkey", column.projectid);
     return(View(column));
 }
Example #10
0
 public TimeLine()
 {
     HEADER = new column {
         globalId_ = "gId",
         localId_  = "lId",
         name_     = "Name",
         text_     = "Text",
         time_     = "Time",
         enabled_  = "Enabled"
     };
 }
        //
        // GET: /Column/Edit/5

        public ActionResult Edit(int id = 0)
        {
            column column = db.columns.Find(id);

            if (column == null)
            {
                return(HttpNotFound());
            }
            ViewBag.projectid = new SelectList(db.projects, "id", "projectkey", column.projectid);
            return(View(column));
        }
Example #12
0
        public ContentValues updateEntry(column _column)
        {
            ContentValues values = new ContentValues();

            values.Put("gId", _column.globalId_);
            values.Put("Name", _column.name_);
            values.Put("Time", _column.time_);
            values.Put("Text", _column.text_);
            values.Put("Enabled", _column.enabled_);

            return(values);
        }
        public static void AddColumn(this key thisKey, column column)
        {
            if (thisKey.column == null)
            {
                thisKey.column = new column[0];
            }

            column[] items = thisKey.column;
            Array.Resize(ref items, thisKey.column.Length + 1);
            items[items.Length - 1] = column;
            thisKey.column          = items;
        }
Example #14
0
        private static IEnumerable <column> GetColumnNodes(IEnumerable <IColumn> columns)
        {
            List <column> columnNodes = new List <column>();

            foreach (var mappedColumn in columns)
            {
                var columnNode = new column {
                    name = mappedColumn.Name.BackTick()
                };
                columnNodes.Add(columnNode);
            }
            return(columnNodes);
        }
Example #15
0
        public JsonResult Select2AjaxTable(string PageName, string colname, List <inputParameter> Parameters)
        {
            Page Info = PDAL.FindPage(PageName);

            ConvertNullToEmpty(Parameters);

            column Pp = null;

            for (int k = 0; k < Info.tables[0].columns.Count; k++)
            {
                if (Info.tables[0].columns[k].name == colname)
                {
                    Pp = Info.tables[0].columns[k];
                }
            }

            for (int k = 0; k < Pp.DBSelectCommandParameters.Count; k++)
            {
                if (Pp.DBSelectCommandParameters[k].source == "Session")
                {
                    inputParameter i = new inputParameter();
                    i.key   = Pp.DBSelectCommandParameters[k].name;
                    i.value = PDAL.GetSession(Pp.DBSelectCommandParameters[k].Parameter);
                    Parameters.Add(i);
                }
            }


            DataTable   Dt = PDAL.ReadRecords(ref Pp.DBSelect2Command, Parameters);
            List <item> it = new List <item>();

            for (int k = 0; k < Pp.options.Count; k++)
            {
                item i = new item();
                i.id   = Pp.options[k].value;
                i.text = Pp.options[k].text;
                it.Add(i);
            }
            for (int k = 0; k < Dt.Rows.Count; k++)
            {
                item i = new item();
                i.id   = Dt.Rows[k][Pp.codeColumn].ToString();
                i.text = Dt.Rows[k][Pp.textColumn].ToString();
                it.Add(i);
            }

            obj o = new obj();

            o.results = it.ToArray();
            return(Json(o));
        }
        public JsonResult GetOperations()
        {
            GetDatabase();
            string[]         files        = Directory.GetFiles(Server.MapPath(@"~\Content\Templates\"), "*.ipynb");
            List <DataModel> TemplateList = new List <DataModel>();

            if (files.Count() != 0)
            {
                foreach (var file in files)
                {
                    DataModel      newtemplate      = new DataModel();
                    List <column>  functions        = new List <column>();
                    var            notebooktemplate = System.IO.File.ReadAllText(file);
                    dynamic        template         = JsonConvert.DeserializeObject <dynamic>(notebooktemplate);
                    List <string>  code             = new List <string>();
                    List <dynamic> cellslist        = new List <dynamic>();
                    if (notebooktemplate.Contains("worksheets"))
                    {
                        cellslist = template.worksheets[0].cells.ToObject <List <dynamic> >();
                    }
                    else
                    {
                        cellslist = template.cells.ToObject <List <dynamic> >();
                    }
                    var markdowncells = cellslist.Where(x => x.cell_type == "markdown").Select(z => z.source.ToString()).ToList();
                    var oper          = markdowncells.Select(y => Regex.Match(y, @"\""UNIQUEID-([\w\s+]*)").Groups[1].ToString().Replace(@"\n", "")).ToList();
                    newtemplate.Id          = Path.GetFileNameWithoutExtension(file);
                    newtemplate.text        = Path.GetFileNameWithoutExtension(file);
                    newtemplate.tooltiptext = Path.GetFileNameWithoutExtension(file);
                    foreach (var op in oper)
                    {
                        if (op != "")
                        {
                            column column = new column();
                            column.Id   = Path.GetFileNameWithoutExtension(file) + "." + op;
                            column.text = op;
                            var nre = markdowncells.Where(y => y.Contains("UNIQUEID-" + op)).Select(y => y).ToList();
                            column.tooltiptext = nre[0].Replace("\"", "").Replace("\\n", "<br>").Replace("[", "").Replace("]", "").Replace(",", "");
                            functions.Add(column);
                        }
                    }
                    newtemplate.children  = functions;
                    newtemplate.IsChecked = false;
                    TemplateList.Add(newtemplate);
                }
            }
            return(Json(TemplateList, JsonRequestBehavior.AllowGet));
        }
Example #17
0
            }     //end constructor

            public bool AddDerivedData(data_item data, int ordinal)
            {
                foreach (column c in this.items)
                {
                    //we cant update an ordinal that already exists...
                    if (c.index == ordinal)
                    {
                        return(false);
                    }
                }

                //ok we got herer, the column doesnt exist. lets add it.
                column new_data_column = new column(data.value, this.config, ordinal);

                this.items.Add(new_data_column);

                return(true);
            }
Example #18
0
        public static column Setup(this column column, MemberInfo memberInfo, string columnName = null, string columnPrefix = "", bool?notnull = true)
        {
            column.SetName(columnName ?? column.GetName() ?? memberInfo.Name.Sanitise(), columnPrefix);

            if (memberInfo.ReturnType() == typeof(string))
            {
                var    stringLengthAttribute = memberInfo.GetCustomAttributes(true).OfType <StringLengthAttribute>().SingleOrDefault();
                string maxLength             = stringLengthAttribute == null ? SqlDialect.Current.VarcharMax : stringLengthAttribute.MaximumLength.ToString();
                column.sqltype = "NVARCHAR(" + maxLength + ")";
            }
            if (memberInfo.ReturnType() == typeof(byte[]))
            {
                column.sqltype = "VARBINARY(MAX)";
            }

            column.notnull = notnull;

            return(column);
        }
Example #19
0
        private key GetKeyNode(ITable joinedTable)
        {
            int count   = joinedTable.ColumnsInPrimaryKey.Count();
            key keyNode = new key();

            if (count > 1)
            {
                foreach (var col in joinedTable.ColumnsInPrimaryKey)
                {
                    column column = new column {
                        name = col.Name
                    };
                    keyNode.AddColumn(column);
                }
            }
            else if (count == 1)
            {
                keyNode.column1 = joinedTable.ColumnsInPrimaryKey.First().Name.BackTick();
            }

            return(keyNode);
        }
Example #20
0
 /// <summary>
 /// 根据表格名称获取表格信息
 /// </summary>
 /// <param name="connection">SQL连接</param>
 /// <param name="tableName">表格名称</param>
 /// <param name="isExecute">SQL连接执行是否成功</param>
 /// <returns>表格信息</returns>
 internal override table getTable(DbConnection connection, string tableName, ref byte isExecute)
 {
     using (DbCommand command = GetCommand(connection, "select top 1 * from [" + tableName + "]"))
     {
         using (DataSet dataSet = GetDataSet(command, ref isExecute))
         {
             DataTable         table    = dataSet.Tables[0];
             column            identity = null;
             subArray <column> columns  = new subArray <column>(table.Columns.Count);
             foreach (DataColumn dataColumn in table.Columns)
             {
                 column column = new column
                 {
                     Name         = dataColumn.ColumnName,
                     DbType       = fastCSharp.sql.sqlDbType.formCSharpType(dataColumn.DataType),
                     Size         = dataColumn.MaxLength,
                     DefaultValue = dataColumn.DefaultValue == null ? null : dataColumn.DefaultValue.ToString(),
                     IsNull       = dataColumn.AllowDBNull,
                 };
                 if (dataColumn.AutoIncrement)
                 {
                     identity = column;
                 }
                 columns.UnsafeAdd(column);
             }
             return(new table
             {
                 Columns = new columnCollection
                 {
                     Name = tableName,
                     Columns = columns.array,
                     Type = sql.columnCollection.type.None
                 },
                 Identity = identity
             });
         }
     }
 }
        public static void AddColumn(this manytoone thisManyToOne, column column)
        {
            //throw new NotImplementedException("TODO: What are we meant to do here?");

            //if (thisManyToOne.column == null)
            //    thisManyToOne.column = new column[0];

            //var items = thisManyToOne.column;
            //Array.Resize(ref items, thisManyToOne.column.Length + 1);
            //items[items.Length - 1] = column;
            //thisManyToOne.column = items;

            if (thisManyToOne.Items == null)
            {
                thisManyToOne.Items = new column[0];
            }

            var items = thisManyToOne.Items;

            Array.Resize(ref items, thisManyToOne.Items.Length + 1);
            items[items.Length - 1] = column;
            thisManyToOne.Items     = items;
        }
Example #22
0
            //populate derived column data after the fact.
            public void derive_column_data()
            {
                if (this.derive_key_columns | this.derive_array_columns)
                {
                    foreach (row r in this.items)
                    {
                        int count = r.items.Count;
                        for (int i = 0; i < count; i++)
                        {
                            column            c          = r.items[i];
                            column_definition column_def = this.config.columns.get_column_by_ordinal(c.index);
                            List <data_item>  new_data   = new List <data_item>();

                            foreach (data_item d in c.items)
                            {
                                if (d.is_key_value)
                                {
                                    column_definition derived_column_def = this.config.columns.get_column_by_name(d.key);
                                    r.AddDerivedData(d, derived_column_def.ordinal);
                                    continue;
                                }

                                if (d.is_value)
                                {
                                    //we only add array data if the max item count is >1
                                    if (column_def.max_items > 1)
                                    {
                                        column_definition derived_column_def = this.config.columns.get_column_by_ordinal(c.index, d.index);
                                        r.AddDerivedData(d, derived_column_def.ordinal);
                                    }
                                }
                            } //end inner
                        }     //end minor
                    }         //end major loop
                }             //end if derived
            }                 //end
Example #23
0
            public row(string data, table_config config, int index)
            {
                this.config = config;
                //clean data by trimming
                this.index = index;
                string clean_row = data.Trim();


                //if its empty skip. we dont need it
                if (clean_row.Length == 0)
                {
                    return;
                }

                //comments are skipped...
                if (clean_row[0] == config.comment_delimiter)
                {
                    return;
                }


                //process whats left into columns
                //split the ros on the column delimiter
                string[] raw_colums = data.Split(config.column_delimiter);

                int column_index = 0;

                //loop through the columns and append them
                foreach (string raw_column in raw_colums)
                {
                    column processed_column = new column(raw_column, config, column_index);
                    //add proccessed row, with or without errors
                    items.Add(processed_column);
                    ++column_index;
                } //end column loop
            }     //end constructor
 public Test()
 {
     kKey   = 42;
     dMoney = 3.1415926f;
     cValue = "May the force be with you!";
 }
Example #25
0
 set => SetValue(column, value);
Example #26
0
 public void OrderBy(column v,orderType o)
 {
     this.orderby = v;
      this.ordtype = o;
 }
Example #27
0
        private void appendTables(Dlineage dlineage, Element dlineageRelation)
        {
            if (dlineage.DataMetaInfos == null)
            {
                return;
            }
            for (int i = 0; i < dlineage.DataMetaInfos.Length; i++)
            {
                database db = dlineage.DataMetaInfos[i];
                for (int j = 0; j < db.tables.Length; j++)
                {
                    table currentTable = db.tables[j];
                    if (currentTable.columns == null || currentTable.columns.Length == 0)
                    {
                        continue;
                    }

                    Element tableNode = new Element("table");

                    if (!string.ReferenceEquals(currentTable.isView, null) && true == Convert.ToBoolean(currentTable.isView))
                    {
                        tableNode.Add(new XAttribute("isView", currentTable.isView));
                    }

                    if (!string.ReferenceEquals(db.name, null) && !"unknown".Equals(db.name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        tableNode.Add(new XAttribute("name", db.name + "." + currentTable.name));
                    }
                    else
                    {
                        tableNode.Add(new XAttribute("name", currentTable.name));
                    }

                    for (int k = 0; k < currentTable.columns.Length; k++)
                    {
                        column  column     = currentTable.columns[k];
                        Element columnNode = new Element("column");


                        if (column.autoIncrement != null)
                        {
                            columnNode.Add(new XAttribute("autoIncrement", column.autoIncrement.ToLower()));
                        }


                        if (column.defaultValue != null)
                        {
                            columnNode.Add(new XAttribute("default", column.defaultValue));
                        }
                        if (column.description != null)
                        {
                            columnNode.Add(new XAttribute("description", column.description));
                        }

                        columnNode.Add(new XAttribute("name", column.name));

                        if (column.primaryKey != null)
                        {
                            columnNode.Add(new XAttribute("primaryKey", column.primaryKey.ToLower()));
                        }
                        if (column.required != null)
                        {
                            columnNode.Add(new XAttribute("required", column.required.ToLower()));
                        }

                        if (column.size != null)
                        {
                            columnNode.Add(new XAttribute("size", column.size));
                        }

                        if (column.type != null)
                        {
                            columnNode.Add(new XAttribute("type", column.type));
                        }

                        tableNode.Add(columnNode);
                    }
                    dlineageRelation.Add(tableNode);
                }
            }
        }
Example #28
0
        private database[] collectDDLInfo()
        {
            LinkedHashMap <string, database> databaseMap = new LinkedHashMap <string, database>();

            if (tableColumns != null)
            {
                IEnumerator <TableMetaData> tableIter = tableColumns.Keys.GetEnumerator();
                while (tableIter.MoveNext())
                {
                    TableMetaData tableMetadata = tableIter.Current;

                    string databaseName = tableMetadata.CatalogDisplayName;
                    if (string.ReferenceEquals(databaseName, null))
                    {
                        databaseName = "unknown";
                    }
                    if (!databaseMap.ContainsKey(databaseName))
                    {
                        database database = new database();
                        database.name             = databaseName;
                        databaseMap[databaseName] = database;
                    }

                    database datasource = databaseMap[databaseName];
                    table    table      = new table();
                    if (!string.ReferenceEquals(tableMetadata.SchemaDisplayName, null))
                    {
                        table.name = tableMetadata.SchemaDisplayName + "." + tableMetadata.DisplayName;
                    }
                    else
                    {
                        table.name = tableMetadata.DisplayName;
                    }

                    if (tableMetadata.View)
                    {
                        table.isView = true.ToString();
                    }
                    if (tableMetadata.Indices != null && tableMetadata.Indices.Count > 0)
                    {
                        table.indices = tableMetadata.Indices.ToArray();
                    }
                    if (tableMetadata.Uniques != null && tableMetadata.Uniques.Count > 0)
                    {
                        table.uniques = tableMetadata.Uniques.ToArray();
                    }
                    if (tableMetadata.ForeignKeys != null && tableMetadata.ForeignKeys.Count > 0)
                    {
                        table.foreignKeys = tableMetadata.ForeignKeys.ToArray();
                    }

                    List <table> tables = new List <table>();
                    if (datasource.tables != null)
                    {
                        tables.AddRange(datasource.tables);
                    }
                    tables.Add(table);
                    tables.Sort();
                    datasource.tables = tables.ToArray();

                    IList <ColumnMetaData> columnMetadatas = tableColumns[tableMetadata];
                    if (columnMetadatas != null)
                    {
                        for (int i = 0; i < columnMetadatas.Count; i++)
                        {
                            ColumnMetaData columnMetadata = columnMetadatas[i];
                            column         column         = new column();
                            column.name          = columnMetadata.DisplayName;
                            column.type          = columnMetadata.Type;
                            column.size          = columnMetadata.Size;
                            column.primaryKey    = columnMetadata.isPrimaryKey();
                            column.description   = columnMetadata.Comment;
                            column.defaultValue  = columnMetadata.DefaultValue;
                            column.required      = columnMetadata.Required;
                            column.autoIncrement = columnMetadata.AutoIncrease;

                            List <column> columns = new List <column>();
                            if (table.columns != null)
                            {
                                columns.AddRange(table.columns);
                            }
                            columns.Add(column);
                            table.columns = columns.ToArray();
                        }
                    }
                }
            }
            if (databaseMap.Count > 0)
            {
                List <database> databases = new List <database>();

                IEnumerator <string> databaseIter = databaseMap.Keys.GetEnumerator();
                while (databaseIter.MoveNext())
                {
                    database database = databaseMap[databaseIter.Current];
                    databases.Add(database);
                }
                return(databases.ToArray());
            }
            else
            {
                return(null);
            }
        }
Example #29
0
        private void txtOutput_DragDrop(object sender, DragEventArgs e)
        {
            relFiles = new List <relFile>();
            relf     = new relFile();
            headers  = new List <string>();
            Headers  = new List <Header>();
            nutrNos  = new List <string>();
            txtOutput.Clear();
            txtName.Clear();
            txtNutrDesc.Clear();
            txtFlavVal.Clear();
            txtNdb.Clear();
            txtNutrNo.Clear();
            listBox1.Items.Clear();

            if (radioMultiKey.Checked)
            {
                string folder = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
                if (!Directory.Exists(folder))
                {
                    MessageBox.Show("Is not a valid directory\n" + folder);
                    txtOutput.Text = "<Drag and drop>\r\n<the folder>\r\n<contains *.TXT files>\r\n<more than one!!>";
                    return;
                }
                files        = Directory.GetFiles(((string[])e.Data.GetData(DataFormats.FileDrop))[0]);
                folder       = folder.Split(new char[] { '/', '\\' })[folder.Split(new char[] { '/', '\\' }).Length - 1];
                txtName.Text = folder.ToUpper();
                foreach (string s in files)
                {
                    relFile r = new relFile();
                    r.file    = s;
                    r.lines   = File.ReadAllLines(s);
                    r.headers = r.lines[0].Split('\t');

                    for (int i = 0; i < r.headers.Length; i++)
                    {
                        if (r.unit == "")
                        {
                            try
                            {
                                r.unit       = r.headers[i].Split('(')[1].Split(')')[0];
                                r.headers[i] = r.headers[i].Split('(')[0].Trim();
                            }
                            catch { }
                        }
                        if (!headers.Contains(r.headers[i]))
                        {
                            headers.Add(r.headers[i]);
                        }
                    }
                    column c = new column();

                    string f = s.Split(Path.DirectorySeparatorChar)[s.Split(Path.DirectorySeparatorChar).Length - 1];
                    txtOutput.Text += f + "\r\n";
                    txtOutput.Text += $"{string.Join("\r\n", r.headers)}\r\n\r\n";
                    relFiles.Add(r);
                }

                foreach (string s in headers)
                {
                    Header h = new Header();
                    h.header = s;
                    Headers.Add(h);
                }

                foreach (Header h in Headers)
                {
                    foreach (relFile r in relFiles)
                    {
                        if (r.headers.Contains(h.header))
                        {
                            h.occcurance++;
                        }
                    }
                }

                int hMax = 0;
                foreach (Header h in Headers)
                {
                    if (h.occcurance > hMax)
                    {
                        hMax = h.occcurance;
                    }
                }

                List <string> suspKeys = new List <string>();
                for (int i = hMax; i > 1; i--)
                {
                    foreach (Header h in Headers)
                    {
                        if (h.occcurance == i)
                        {
                            suspKeys.Add(h.header);
                        }
                    }
                }
                txtOutput.Text = $"Recurrent keys:\r\n{string.Join("\r\n", suspKeys)}\r\n\r\n" + txtOutput.Text;


                string[] parentHeaders = File.ReadAllLines(activeDBdir + slash + "_nameKeyPairs.TXT");
                for (int i = 0; i < parentHeaders.Length; i++)
                {
                    parentHeaders[i] = parentHeaders[i].Split('|')[1];
                }

                foreach (string s in parentHeaders)
                {
                    foreach (string st in headers)
                    {
                        if (s == st)
                        {
                            listBox1.Items.Add(s);
                        }
                    }
                }

                AutoCompleteStringCollection source = new AutoCompleteStringCollection();
                foreach (string s in headers)
                {
                    source.Add(s);
                    if (s == "NDB_No")
                    {
                        txtNdb.Text = s;
                    }
                    else if (s == "NutrDesc")
                    {
                        txtNutrDesc.Text = s;
                    }
                    else if (s == "Nutr_No")
                    {
                        txtNutrNo.Text = s;
                    }
                    else if (s == "Flav_Val" || s == "Isfl_Val")
                    {
                        txtFlavVal.Text = s;
                    }
                }

                txtNutrDesc.AutoCompleteCustomSource = source;
                txtNutrDesc.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                txtNutrDesc.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;

                txtNutrNo.AutoCompleteCustomSource = source;
                txtNutrNo.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                txtNutrNo.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;

                txtFlavVal.AutoCompleteCustomSource = source;
                txtFlavVal.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                txtFlavVal.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;

                txtNdb.AutoCompleteCustomSource = source;
                txtNdb.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                txtNdb.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
            }
            else
            {
                string file = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
                if (!File.Exists(file) || !file.EndsWith(".TXT"))
                {
                    MessageBox.Show("Is not a valid .TXT file\n" + file);
                    txtOutput.Text = "<Drag and drop>\r\n<a single .TXT file>";
                    return;
                }

                relFile r = new relFile();
                r.file    = file;
                r.lines   = File.ReadAllLines(file);
                r.headers = r.lines[0].Split('\t');
                relf      = r;
                foreach (string s in r.headers)
                {
                    Header H = new Header();
                    H.header = s.Split('(')[0].Trim();
                    try {
                        H.unit = s.Split('(')[1].Split(')')[0];
                    }
                    catch { }
                    if (!headers.Contains(s.Split('(')[0].Trim()))
                    {
                        headers.Add(s.Split('(')[0].Trim());
                    }
                    Headers.Add(H);
                }


                file         = file.Split(Path.DirectorySeparatorChar)[file.Split(Path.DirectorySeparatorChar).Length - 1].Replace(".TXT", "");
                txtName.Text = file;


                txtOutput.Text += file + ".TXT\r\n";
                foreach (Header H in Headers)
                {
                    txtOutput.Text += H.header + "\r\n";
                }

                txtOutput.Text += "\r\nUnits detected:\r\n";
                foreach (Header H in Headers)
                {
                    if (H.unit != null && H.unit != "")
                    {
                        txtOutput.Text += H.unit + "\r\n";
                    }
                }

                string[] parentHeaders = File.ReadAllLines(activeDBdir + slash + "_nameKeyPairs.TXT");
                for (int i = 0; i < parentHeaders.Length; i++)
                {
                    parentHeaders[i] = parentHeaders[i].Split('|')[1];
                }

                foreach (string s in parentHeaders)
                {
                    foreach (string st in headers)
                    {
                        if (s == st)
                        {
                            listBox1.Items.Add(s);
                        }
                    }
                }

                AutoCompleteStringCollection source = new AutoCompleteStringCollection();
                foreach (Header H in Headers)
                {
                    string s = H.header;
                    source.Add(s);
                    if (s == "NDB_No")
                    {
                        txtNdb.Text = s;
                    }
                }
                txtFlavVal.AutoCompleteCustomSource = source;
                txtFlavVal.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                txtFlavVal.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;

                txtNdb.AutoCompleteCustomSource = source;
                txtNdb.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                txtNdb.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
            }
        }
Example #30
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (radioMultiKey.Checked)
            {
                if (!headers.Contains(txtNutrNo.Text) || !headers.Contains(txtNutrDesc.Text) || !headers.Contains(txtNdb.Text) || !headers.Contains(txtFlavVal.Text))
                {
                    MessageBox.Show("Please fill everything out.  Not all the fields match.");
                    return;
                }

                string newRelDir = $"{Application.StartupPath}{slash}usr{slash}share{slash}rel{slash}multi{slash}{txtName.Text}";
                Directory.CreateDirectory(newRelDir);

                string unit   = "";
                string ndb    = "";
                string nutrNo = "";
                foreach (relFile r in relFiles)
                {
                    string f = r.file.Split(new char[] { '/', '\\' })[r.file.Split(new char[] { '/', '\\' }).Length - 1].Replace(".TXT", "");
                    Directory.CreateDirectory(newRelDir + slash + f);
                    for (int i = 0; i < r.headers.Length; i++)
                    {
                        column c = new column();
                        c.header = r.headers[i];
                        for (int j = 1; j < r.lines.Length; j++)
                        {
                            c.rows.Add(r.lines[j].Split('\t')[i]);
                        }
                        r.columns.Add(c);
                    }
                    foreach (column c in r.columns)
                    {
                        File.WriteAllLines(newRelDir + slash + f + slash + c.header + ".TXT", c.rows);
                        if (c.header == txtNutrNo.Text)
                        {
                            nutrNos = c.rows;
                        }
                        else if (c.header == txtFlavVal.Text)
                        {
                            flavVal = $"{slash}{f}{slash}{c.header}.TXT";
                        }
                        if (r.unit != "")
                        {
                            unit = r.unit;
                        }
                    }
                    nutrNos = nutrNos.ToArray().Distinct().ToList();
                    nutrNos.Sort();
                    File.WriteAllText(newRelDir + slash + "_dbInit.TXT", $"[ParentDB]{comboBox1.Text}\r\n[Values]{txtFlavVal.Text}.TXT\r\n[Units]{unit}\r\n[ParentKey]$NDBNo\r\n[ChildKey]$NutrNo\r\n[Fields]{txtNutrDesc.Text}.TXT");
                    txtOutput.Text = "Units: " + unit + txtOutput.Text;
                }

                files = Directory.GetFiles(newRelDir, "*.TXT", SearchOption.AllDirectories);
                foreach (string s in files)
                {
                    if (s.EndsWith(txtFlavVal.Text + ".TXT"))
                    {
                        ndb = s.Replace(txtFlavVal.Text + ".TXT", txtNdb.Text + ".TXT");
                    }
                    else if (s.EndsWith(txtNutrDesc.Text + ".TXT"))
                    {
                        nutrNo = s.Replace(txtNutrDesc.Text + ".TXT", txtNutrNo.Text + ".TXT");
                    }
                }
                ndb    = ndb.Replace(newRelDir, "").Replace(slash, "/");
                nutrNo = nutrNo.Replace(newRelDir, "").Replace(slash, "/");
                string text = File.ReadAllText(newRelDir + slash + "_dbInit.TXT");
                text = text.Replace("$NDBNo", ndb).Replace("$NutrNo", nutrNo);
                File.WriteAllText(newRelDir + slash + "_dbInit.TXT", text);
                MessageBox.Show($"Database created successfully! Go to the extended tab of the {comboBox1.Text} database to configure it");
                //this.Close();
            }
            else
            {
                if (!headers.Contains(txtNdb.Text) || !headers.Contains(txtFlavVal.Text))
                {
                    MessageBox.Show("Please fill everything out.  Not all the fields match.");
                    return;
                }

                string newRelDir = $"{Application.StartupPath}{slash}usr{slash}share{slash}rel{slash}single{slash}{txtName.Text}";

                Directory.CreateDirectory(newRelDir);

                for (int i = 0; i < relf.headers.Length; i++)
                {
                    List <string> c = new List <string>();
                    for (int j = 1; j < relf.lines.Length; j++)
                    {
                        c.Add(relf.lines[j].Split('\t')[i]);
                    }
                    File.WriteAllLines($"{newRelDir}{slash}{headers[i]}.TXT", c);
                }
            }
        }
Example #31
0
 ref Block8x8 blockRef = ref this.GetBlockReference(column, row);
Example #32
0
 Column(column, escape, alias);