Пример #1
0
 public static PDataType GetElementType(this PDataType type)
 {
     return(type switch
     {
         PDataType.IntegerArray => PDataType.Integer,
         PDataType.BooleanArray => PDataType.Boolean,
         PDataType.VarcharArray => PDataType.Varchar,
         PDataType.VarbinaryArray => PDataType.Varbinary,
         PDataType.BinaryArray => PDataType.Binary,
         PDataType.CharArray => PDataType.Char,
         PDataType.LongArray => PDataType.Long,
         PDataType.SmallintArray => PDataType.Smallint,
         PDataType.TinyintArray => PDataType.Tinyint,
         PDataType.FloatArray => PDataType.Float,
         PDataType.DoubleArray => PDataType.Double,
         PDataType.DecimalArray => PDataType.Decimal,
         PDataType.TimestampArray => PDataType.Timestamp,
         PDataType.UnsignedTimestampArray => PDataType.UnsignedTimestamp,
         PDataType.TimeArray => PDataType.Time,
         PDataType.UnsignedTimeArray => PDataType.UnsignedTime,
         PDataType.DateArray => PDataType.Date,
         PDataType.UnsignedDateArray => PDataType.UnsignedDate,
         PDataType.UnsignedLongArray => PDataType.UnsignedLong,
         PDataType.UnsignedIntArray => PDataType.UnsignedInt,
         PDataType.UnsignedSmallintArray => PDataType.UnsignedSmallint,
         PDataType.UnsignedTinyintArray => PDataType.UnsignedTinyint,
         PDataType.UnsignedFloatArray => PDataType.UnsignedFloat,
         PDataType.UnsignedDoubleArray => PDataType.UnsignedDouble,
         _ => throw new ArgumentOutOfRangeException()
     });
Пример #2
0
 public static bool IsArray(this PDataType type)
 {
     return
         (type == PDataType.IntegerArray ||
          type == PDataType.BooleanArray ||
          type == PDataType.VarcharArray ||
          type == PDataType.VarbinaryArray ||
          type == PDataType.BinaryArray ||
          type == PDataType.CharArray ||
          type == PDataType.LongArray ||
          type == PDataType.SmallintArray ||
          type == PDataType.TinyintArray ||
          type == PDataType.FloatArray ||
          type == PDataType.DoubleArray ||
          type == PDataType.DecimalArray ||
          type == PDataType.TimestampArray ||
          type == PDataType.UnsignedTimestampArray ||
          type == PDataType.TimeArray ||
          type == PDataType.UnsignedTimeArray ||
          type == PDataType.DateArray ||
          type == PDataType.UnsignedDateArray ||
          type == PDataType.UnsignedLongArray ||
          type == PDataType.UnsignedIntArray ||
          type == PDataType.UnsignedSmallintArray ||
          type == PDataType.UnsignedTinyintArray ||
          type == PDataType.UnsignedFloatArray ||
          type == PDataType.UnsignedDoubleArray);
 }
Пример #3
0
 public IList <String> getData(string rawValue, PDataType type, bool priKey)
 {
     //checkFormat data
     try
     {
         if (!checkDataFormat(rawValue))
         {
             throw new Exception("Wrong Format's Data!");
         }
         //fomat handle {x,y,z}
         if (priKey && rawValue.Contains(","))
         {
             return new List <string>()
                    {
                        rawValue.Split(',').ToList().FirstOrDefault().Trim()
                    }
         }
         ;
         return(rawValue.Contains(",") ? rawValue.Split(',').ToList().Select(p => p.Trim()).ToList() : new List <string>()
         {
             rawValue.Trim()
         });
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ContantCls.lblNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return(null);
     }
 }
Пример #4
0
 public static bool IsRealNumber(this PDataType type)
 {
     return
         (type == PDataType.Float ||
          type == PDataType.Double ||
          type == PDataType.Decimal ||
          type == PDataType.UnsignedFloat ||
          type == PDataType.UnsignedDouble);
 }
Пример #5
0
 public PAttribute(bool primaryKey, int id, string attributeName, PDataType type, string description, PSchema pSchema)
 {
     this.primaryKey = primaryKey;
     this.id         = id;
     AttributeName   = attributeName;
     Type            = type;
     Description     = description;
     Schema          = pSchema;
 }
Пример #6
0
 public static bool IsWholeNumber(this PDataType type)
 {
     return
         (type == PDataType.Long ||
          type == PDataType.Integer ||
          type == PDataType.Smallint ||
          type == PDataType.Tinyint ||
          type == PDataType.UnsignedLong ||
          type == PDataType.UnsignedInt ||
          type == PDataType.UnsignedSmallint ||
          type == PDataType.UnsignedTinyint);
 }
Пример #7
0
 public static bool IsNumeric(this PDataType type)
 {
     return
         (type == PDataType.Long ||
          type == PDataType.Integer ||
          type == PDataType.Smallint ||
          type == PDataType.Tinyint ||
          type == PDataType.Float ||
          type == PDataType.Double ||
          type == PDataType.Decimal ||
          type == PDataType.UnsignedLong ||
          type == PDataType.UnsignedInt ||
          type == PDataType.UnsignedSmallint ||
          type == PDataType.UnsignedTinyint ||
          type == PDataType.UnsignedFloat ||
          type == PDataType.UnsignedDouble);
 }
Пример #8
0
            public object getValuebyType(string rawValue, PDataType type)
            {
                var result = new Object();

                try
                {
                    switch (type.TypeName)
                    {
                    case "Int16": result = Convert.ToInt16(rawValue); break;

                    case "Int64": result = Convert.ToInt64(rawValue); break;

                    case "Int32": result = Convert.ToInt32(rawValue); break;

                    case "Byte": result = Convert.ToByte(rawValue); break;

                    case "Decimal": result = Convert.ToDecimal(rawValue); break;

                    case "String": result = Convert.ToString(rawValue); break;

                    case "DateTime": result = Convert.ToDateTime(rawValue); break;

                    case "Single": result = Convert.ToSingle(rawValue); break;

                    case "Double": result = Convert.ToDouble(rawValue); break;

                    case "Boolean": result = Convert.ToBoolean(rawValue); break;

                    case "Currency":; break;

                    case "Binary":; break;

                    default: break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Notification", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                finally
                {
                    result = type.CheckDataTypeOfVariables(rawValue) ? result : "Unknown Value";
                }
                return(result);
            }
Пример #9
0
 public static string ToSqlTypeName(this PDataType type)
 {
     return(PhoenixDataTypeUtility.GetSqlTypeName(type));
 }
Пример #10
0
 public static bool IsBinary(this PDataType type)
 {
     return(type == PDataType.Varbinary || type == PDataType.Binary);
 }
Пример #11
0
 //static byte[] IntToBytes(int paramInt)
 //{
 //    byte[] arrayOfByte = new byte[3];
 //    arrayOfByte[0] = (byte)(paramInt);
 //    arrayOfByte[1] = (byte)(paramInt >> 8);
 //    arrayOfByte[2] = (byte)(paramInt >> 16);
 //    return arrayOfByte;
 //}
 //static int BytesToInt(List<byte> paramInt)
 //{
 //    int val = (int)paramInt[0];
 //    val |= ((int)paramInt[1]) << 8;
 //    val |= ((int)paramInt[2]) << 16;
 //    return val;
 //}
 static ProtocolDataType GenericPack(PDataType DataType, byte nameType)
 {
     ProtocolDataType PDType = new ProtocolDataType();
     PDType.DataType = DataType;
     PDType.NameType = nameType;
     return PDType;
 }
Пример #12
0
 public ProtocolDataType(byte NameType, PDataType DataType, byte[] Data)
 {
     this.NameType = NameType;
     this.DataType = DataType;
     this.Data = Data;
 }
Пример #13
0
 // Constructor
 public PPacket(PDataType settingType, object data)
 {
     SettingType = settingType;
     Data        = data;
 }
Пример #14
0
        private string GetProbInterval(string valueOne, string valueTwo, string operaterStr)
        {
            ElemProb prop = null;

            int    indexOne, indexTwo, countValue;
            PTuple tuple = this.tuple;

            //string typenameOne;
            //string typenameTwo;


            try
            {
                // Biểu thức so sánh bằng giữa hai thuộc tính trên cùng một bộ
                if (operaterStr.Contains("equal_ig") || operaterStr.Contains("equal_in") || operaterStr.Contains("equal_me"))
                {
                    indexOne = IndexOf(valueOne);
                    indexTwo = IndexOf(valueTwo);
                    if (indexOne == -1 || indexTwo == -1)
                    {
                        return(string.Empty);
                    }

                    if (!Attributes[indexOne].Type.DataType.Equals(Attributes[indexTwo].Type.DataType))
                    {
                        //Attribute value does not match the data type !
                        MessageError = String.Format("Error :{0} and {1} must  the same data type", valueOne, valueTwo);
                        return(string.Empty);
                    }

                    var low = 0f;
                    var up  = 0f;
                    foreach (var valInAttr1 in tuple.valueSet[(valueOne)])
                    {
                        foreach (var valInAttr2 in tuple.valueSet[(valueTwo)])
                        {
                            if (EQUAL(valInAttr1.Trim(), valInAttr2.Trim(), Attributes[indexOne].Type.DataType))
                            {
                                switch (operaterStr)
                                {
                                case "equal_in":
                                    low += tuple.Ps.lowerBound * tuple.Ps.upperBound;
                                    up   = Math.Min(1, up + tuple.Ps.upperBound * tuple.Ps.upperBound);
                                    break;

                                case "equal_ig":
                                    low += Math.Min(0, tuple.Ps.lowerBound + tuple.Ps.lowerBound - 1);
                                    up   = Math.Min(1, up + Math.Min(tuple.Ps.upperBound, tuple.Ps.upperBound));
                                    break;

                                case "equal_me":
                                    low = 0;
                                    up  = Math.Min(1, up + 0); break;

                                default: break;
                                }
                            }
                        }
                    }
                }
                else
                if (SelectCondition.isCompareOperator(operaterStr)) // Biểu thức so sánh giữa một thuộc tính với một giá trị
                {
                    indexOne = this.IndexOf(valueOne);              // vị trí của thuộc tính trong ds các thuộc tính //what is THIS !?
                    if (indexOne == -1)
                    {
                        return(string.Empty);
                    }

                    if (valueTwo.Contains("'"))
                    {
                        int count = valueTwo.Split(new char[] { '\'' }).Length - 1;


                        if (valueTwo.Substring(0, 1) != "'")
                        {
                            MessageError = "Unclosed quotation mark before the character string " + valueTwo;
                            return(string.Empty);
                        }

                        if (valueTwo.Substring(valueTwo.Length - 1, 1) != "'")
                        {
                            MessageError = "Unclosed quotation mark after the character string " + valueTwo;
                            return(string.Empty);
                        }


                        if (count != 2)
                        {
                            MessageError = "Unclosed quotation mark at the character string " + valueTwo;
                            return(string.Empty);
                        }

                        valueTwo = valueTwo.Remove(0, 1);
                        valueTwo = valueTwo.Remove(valueTwo.Length - 1, 1);
                    }

                    PDataType dataType = new PDataType();
                    dataType.TypeName     = Attributes[indexOne].Type.TypeName;
                    dataType.DataType     = Attributes[indexOne].Type.DataType;
                    dataType.Domain       = Attributes[indexOne].Type.Domain;
                    dataType.DomainString = Attributes[indexOne].Type.DomainString;

                    if (!dataType.CheckDataTypeOfVariables(valueTwo))
                    {
                        MessageError = String.Format("Conversion failed when converting the varchar value {0} to data type {1}.", valueTwo, Attributes[indexOne].Type.DataType.ToString());
                        return(string.Empty);
                    }
                    countValue = tuple.valueSet[(valueOne)].Count;

                    prop = new ElemProb(0, 0);

                    foreach (var value in tuple.valueSet[(valueOne)])
                    {
                        if (this.Compare(value.ToString().Trim(), valueTwo.ToString(), operaterStr, Attributes[indexOne].Type.DataType.ToString())) //duyet tung value
                        {
                            try
                            {
                                prop.lowerBound += (1 / (float)countValue);
                                prop.upperBound += (1 / (float)countValue);
                            }
                            catch (Exception ex)
                            {
                                MessageError = ex.Message;
                            }
                            //break;
                        }
                    }
                    prop.lowerBound *= tuple.Ps.lowerBound;
                    prop.upperBound *= tuple.Ps.upperBound;
                }
                else                     // Biểu thức kết hợp giữa hai khoảng xác suất
                {
                    var prop1 = new ElemProb(valueOne);
                    var prop2 = new ElemProb(valueTwo);
                    switch (operaterStr)
                    {
                    case "⊗_ig": prop = new ElemProb(Math.Max(0, prop1.lowerBound + prop2.lowerBound - 1), Math.Min(prop1.upperBound, prop2.upperBound)); break;

                    case "⊗_in": prop = new ElemProb(prop1.lowerBound * prop2.lowerBound, prop1.upperBound * prop2.upperBound); break;

                    case "⊗_me": prop = new ElemProb(0, 0); break;

                    case "⊕_ig": prop = new ElemProb(Math.Max(prop1.lowerBound, prop2.lowerBound), Math.Min(1, prop1.upperBound + prop2.upperBound)); break;

                    case "⊕_in": prop = new ElemProb(prop1.lowerBound + prop2.lowerBound - (prop1.lowerBound * prop2.lowerBound), prop1.upperBound + prop2.upperBound - (prop1.upperBound * prop2.upperBound)); break;

                    case "⊕_me": prop = new ElemProb(Math.Min(1, prop1.lowerBound + prop2.lowerBound), Math.Min(1, prop1.upperBound + prop2.upperBound)); break;

                    default:
                        MessageError = "Incorrect syntax near 'where'.";
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageError = "Incorrect syntax near 'where'.";
                return(string.Empty);
            }

            //maxProb = 1 > maxProb ? maxProb : 1; // check maxProb
            if (prop is null)
            {
                return(String.Empty);
            }
            return(String.Format("[{0},{1}]", prop.lowerBound, prop.upperBound));
        }
Пример #15
0
 public static string GetSqlTypeName(PDataType type)
 {
     return(_typeNames[type]);
 }
Пример #16
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var attLs = new List <PAttribute>();

            if (String.IsNullOrEmpty(this.txtSchName.Text.ToString()))
            {
                MessageBox.Show("You must enter a schema name, please try again!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if ("select".Equals(this.txtSchName.Text.ToLower(), StringComparison.CurrentCultureIgnoreCase) ||
                "from".Equals(this.txtSchName.Text.ToLower(), StringComparison.CurrentCultureIgnoreCase) ||
                "where".Equals(this.txtSchName.Text.ToLower(), StringComparison.CurrentCultureIgnoreCase))
            {
                MessageBox.Show("Schema name is not valid ( not match with keyword 'select', 'from', 'where')", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            foreach (var item in StaticParams.currentDb.Schemas.ToList())
            {
                if (item.SchemaName.ToLower().Equals(this.txtSchName.Text.ToLower(), StringComparison.CurrentCultureIgnoreCase))
                {
                    MessageBox.Show("This schema name has already existed in the database, please try again !", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            if (!CheckValidatedDataGridView(attrs))
            {
                return;
            }

            //create schema
            PSchema schema = new PSchema();

            schema.id         = RawDatabaseService.Instance().getNextIdSch(); //important
            schema.SchemaName = this.txtSchName.Text.Trim();

            PAttribute attribute;

            //insert Schema and relative component in Db
            try
            {
                #region addAtrr
                foreach (SchemaModelView attr in attrs.ToList())
                {
                    attribute               = new PAttribute();
                    attribute.id            = RawDatabaseService.Instance().getNextIdAttr();
                    attribute.AttributeName = attr.attrName;
                    attribute.primaryKey    = attr.isPri;
                    attribute.Type          = new Domain.Unit.PDataType()
                    {
                        DomainString = attr.domain, DataType = attr.datatype, TypeName = attr.typeName
                    };
                    attribute.Description = attr.descs;
                    attribute.Schema      = schema;

                    RawDatabaseService.Instance().Insert(attribute); //=>csdl need id schema
                    //update full info schema
                    schema.Attributes.Add(attribute);
                }
                //Ps
                var datatype = new PDataType();
                datatype.TypeName = "String";
                datatype.GetDomain("[0  ...  32767] characters");
                datatype.GetDataType();
                var attrPs = new PAttribute()
                {
                    AttributeName = "Ps",
                    id            = RawDatabaseService.Instance().getNextIdAttr(),
                    Schema        = schema,
                    primaryKey    = false,
                    Description   = "Prob",
                    Type          = datatype
                };
                RawDatabaseService.Instance().Insert(attrPs);
                schema.Attributes.Add(attrPs);
                #endregion addAtrr


                //insert scheme in db
                RawDatabaseService.Instance().Insert(schema);

                //insert scheme in ram
                StaticParams.currentDb.Schemas.Add(schema);
                //commit
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (MessageBox.Show("Add successfully. Do you want add new schema ?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                this.txtSchName.Text = "";
                this.attrs.Clear();
                this.dtg.ItemsSource = attrs;
                this.dtg.Items.Refresh();
                this.txtSchName.Focus();
            }
            else
            {
                this.Close();
            }
        }