Beispiel #1
0
        /// <summary>
        /// Method itry to drop and create table
        /// </summary>
        /// <param name="prefix">Project prefix</param>
        /// <param name="tableName">Table name</param>
        /// <param name="tableType">New columns types</param>
        /// <param name="columns">New table columns</param>
        /// <param name="drop">If true table with the same name will be drop</param>
        private static string tryCreateTable(string prefix, string tableName, string tableType, string columns, bool drop)
        {
            if (tableName != "" && tableType != "" && columns != "")
            {
                Result result;

                if (tableType == "DIMENSION")
                {
                    if (drop == true)
                    {
                        DimensionHandler.dropDimension(prefix, tableName);
                    }
                    result = DimensionHandler.addDimension(tableName, columns, prefix);
                    if (result.errormsg != "OK")
                    {
                        return("Import status: Cannot create table. Please check if old table contains foreign keys or if all required inforamtion are correct.");
                    }
                    return("OK");
                }
                else
                {
                    if (drop == true)
                    {
                        FactHandler.dropFact(prefix, tableName);
                    }
                    result = FactHandler.addFact(tableName, columns, prefix);
                    if (result.errormsg != "OK")
                    {
                        return("Import status: Cannot create table. Please check if old table exists or contains foreign keys or if all required inforamtion are correct.");
                    }
                    return("OK");
                }
                if (tableType == "FUNCTION")
                {
                    if (drop == true)
                    {
                        FunctionHandler.dropFunction(prefix + "_" + tableType + "_" + tableName);
                    }
                    result = FunctionHandler.addFunction(tableName, columns, prefix);
                    if (result.errormsg != "OK")
                    {
                        return("Import status: Cannot create table. Please check if old table exists or contains foreign keys or if all required inforamtion are correct.");
                    }
                    return("OK");
                }
            }
            return("Import status: Please check if csv contains all required information - table type, table name and columns name with types");
        }
        private bool CreateNewFact()
        {
            if (updating)
            {
                FactHandler.dropFact(Application.Current.Resources["ProjectPrefix"].ToString(), TxtTableName.Text.ToString().ToUpper());
            }

            string tmpStr     = "";
            bool   allFill    = true;
            bool   onlyNumber = true;

            foreach (ColumnBar2 tmp in ColumnList)
            {
                if (tmp.TxtColumnName.Text.ToString() == "" || tmp.TxtColumnType.Text.ToString() == "")
                {
                    allFill = false;
                }

                if (!(tmp.TxtColumnType.Text.ToString().Contains("number") || tmp.TxtColumnType.Text.ToString().Contains("number")))
                {
                    onlyNumber = false;
                }

                tmpStr = tmpStr + tmp.TxtColumnName.Text.ToString() + " " + tmp.TxtColumnType.Text.ToString() + " " + tmp.TxtColumnCons.Text.ToString() + ",";
            }

            tmpStr = tmpStr.Remove(tmpStr.Length - 1);

            if (TxtTableName.Text.ToString() == "")
            {
                allFill = false;
            }
            if (allFill && onlyNumber)
            {
                Result wynik = new Result();
                wynik = FactHandler.addFact(TxtTableName.Text, tmpStr, Application.Current.Resources["ProjectPrefix"].ToString());
                if (wynik.errormsg != "OK")
                {
                    textBlockError.Text = wynik.errormsg;
                }
                else
                {
                    DataSet testowy = FactHandler.getFacts(Application.Current.Resources["ProjectPrefix"].ToString());
                    Console.WriteLine(testowy.Tables["result"].ToString());
                    return(true);
                }
            }
            else
            {
                if (!allFill)
                {
                    MessageBox.Show("Fill all Textbox!!!");
                }
                if (!onlyNumber)
                {
                    MessageBox.Show("Column types can only be of type number");
                }
            }


            return(false);
        }