private void btnMain_Click(object sender, RoutedEventArgs e)
        {
            if (this.cbx.SelectedItem is null)
            {
                MessageBox.Show("Please choose any item of Combobox", "Notification", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if ("opnsch".Equals(this.mode, StringComparison.CurrentCultureIgnoreCase))
            {
                Parameter.activeTabIdx = 0;
                Parameter.SchemaIndex  = this.cbx.SelectedIndex;
            }

            if ("opnrel".Equals(this.mode, StringComparison.CurrentCultureIgnoreCase))
            {
                Parameter.activeTabIdx  = 1;
                Parameter.RelationIndex = this.cbx.SelectedIndex;
            }

            if ("delsch".Equals(this.mode, StringComparison.CurrentCultureIgnoreCase))
            {
                try {
                    //delete schema
                    var schema = StaticParams.currentDb.Schemas.Where(p => p == this.cbx.SelectedItem as PSchema).FirstOrDefault();
                    //in Db
                    RawDatabaseService.Instance().Delete(schema);
                    //in Ram
                    StaticParams.currentDb.Schemas.Remove(schema);

                    //delete attr of schema
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            if ("delrel".Equals(this.mode, StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    var relation = StaticParams.currentDb.Relations.Where(p => p == this.cbx.SelectedItem as PRelation).FirstOrDefault();
                    //in DB
                    RawDatabaseService.Instance().Delete(relation);
                    //in Ram
                    StaticParams.currentDb.Relations.Remove(relation);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Infomation", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }

            this.Close();
        }
Beispiel #2
0
        public static IDbService GetDatabaseService()
        {
            //switch (ConfigurationSettings.AppSettings.Get("defaultDbService").ToString())
            switch (ConfigurationManager.AppSettings["defaultDbService"].ToString())
            {
            case "EF":
            case "Raw": return(RawDatabaseService.Instance());

            default:
                return(RawDatabaseService.Instance());
            }
        }
Beispiel #3
0
        private void dtg_CurrentCellChanged(object sender, EventArgs e)
        {
            this.ucEdit.btnClr.IsEnabled           = false;
            this.ucEdit.btnCommitEdit.IsEnabled    = false;
            this.ucEdit.btnApply.IsEnabled         = false;
            this.ucEdit.dtgCellContent.IsEnabled   = false;
            this.ucEdit.rtbxCellContent.IsReadOnly = true;

            var relation = new PRelation()
            {
                id = int.Parse(this.cbx.SelectedValue.ToString())
            };

            try
            {
                var    tupID    = (this.dtg.CurrentItem as DataRowView).Row.ItemArray[0].ToString().Trim();
                var    tuple    = RawDatabaseService.Instance().GetTuplebyId(ref relation, tupID);
                var    header   = this.dtg.CurrentCell.Column.Header.ToString().ToLower();
                String attrName = header;
                attrName = String.Format("{0}.{1}", relation.relationName, header);

                if (!header.Equals(ContantCls.emlementProb, StringComparison.CurrentCultureIgnoreCase))
                {
                    this.ucEdit.txtInfo.Content = attrName.ToUpper();
                    this.ucEdit.curTuple        = tuple;
                    this.ucEdit.setValCell(tuple.valueSet[attrName]);
                }
                else
                {
                    this.ucEdit.txtInfo.Content = attrName.ToUpper();
                    this.ucEdit.curTuple        = tuple;
                    this.ucEdit.setValCell(new List <String> {
                        tuple.Ps.ToString()
                    });
                }
                var att = relation.schema.Attributes.Where(p => p.AttributeName.Equals(header, StringComparison.CurrentCultureIgnoreCase)).First();
                this.ucEdit.pAttribute          = att;
                this.ucEdit.txtDataType.Content = att.Type.TypeName;
                this.ucEdit.chkPri.IsChecked    = att.primaryKey;
                this.ucEdit.pRelation           = relation;

                Parameter.currentColumn = this.dtg.CurrentCell.Column.DisplayIndex;
                Parameter.currentRow    = this.dtg.Items.IndexOf(this.dtg.CurrentItem);
            }
            catch { }
            this.ucEdit.rtbxCellContent.Visibility = Visibility.Visible;
            this.ucEdit.dtgCellContent.Visibility  = Visibility.Collapsed;
        }
Beispiel #4
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var schema = this.cbxSchName.SelectedItem as PSchema;

                if (RawDatabaseService.Instance().getRelByIdSch(schema).Count > 0)
                {
                    MessageBox.Show("The Schema are being used by another Relation, Fail to Edit!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                //build attrs
                var upAttrs = schema.Attributes.ToList();
                schema.SchemaName = this.txtName.Text.ToLower();
                for (int i = 0; i < upAttrs.Count; i++)
                {
                    //dont update Ps Attr
                    if (!upAttrs[i].AttributeName.Equals(ContantCls.emlementProb, StringComparison.CurrentCultureIgnoreCase))
                    {
                        upAttrs[i].AttributeName = attrs[i].attrName;
                        upAttrs[i].primaryKey    = attrs[i].isPri;
                        upAttrs[i].Type.TypeName = attrs[i].typeName;
                        upAttrs[i].Type.GetDomain(attrs[i].domain);
                        upAttrs[i].Type.GetDataType();
                        upAttrs[i].Schema = schema;
                    }
                    else
                    {
                        upAttrs.RemoveAt(i);
                    }
                }
                //update Attrs

                foreach (var item in upAttrs)
                {
                    RawDatabaseService.Instance().Update(item);
                }
                //update Sch
                RawDatabaseService.Instance().Update(schema);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 private void addingNewTuple()
 {
     if (StaticParams.currentRelation != null)
     {
         var addIdform = new addingTuples();
         addIdform.ShowDialog();
         var idList = addIdform.idTupleList;
         var pri    = StaticParams.currentRelation.schema.Attributes.Where(a => a.primaryKey).FirstOrDefault();
         var priAtr = $"{StaticParams.currentRelation.relationName.ToLower()}.{pri.AttributeName.ToLower()}";
         if (idList != null)
         {
             foreach (var id in idList)
             {
                 RawDatabaseService.Instance().insertEmptyTuple(StaticParams.currentRelation, pri, id.IDtuple);
             }
         }
         Parameter.activeTabIdx = 1;
         this.reloadDb();
     }
 }
Beispiel #6
0
        private void btnDel_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var rs = MessageBox.Show("Delete this Tuple?", "Notification", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (rs == MessageBoxResult.Yes)
            {
                var relation = new PRelation()
                {
                    id = int.Parse(this.cbx.SelectedValue.ToString())
                };
                var tupID = (this.dtg.SelectedItem as DataRowView).Row.ItemArray[0].ToString().Trim();
                var tuple = RawDatabaseService.Instance().GetTuplebyId(ref relation, tupID);
                try
                {
                    RawDatabaseService.Instance().DeleteTupleById(relation, tuple);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #7
0
        private bool checkExitID(string dtuple) //false: dosenot exist | true: existed
        {
            var rel = new Domain.Model.PRelation()
            {
                id = StaticParams.currentRelation.id
            };

            try
            {
                var tuple = RawDatabaseService.Instance().GetTuplebyId(ref rel, dtuple);
                foreach (var item in tuple.valueSet)
                {
                    if (item.Value.Count != 0)
                    {
                        return(true);
                    }
                }
            }
            catch {
                return(false);
            }
            return(false);
        }
Beispiel #8
0
        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            if (!rowBeingEdited)
            {
                var att = this.txtInfo.Content.ToString();

                if (att.Substring(att.IndexOf(".") + 1).Equals(ContantCls.emlementProb, StringComparison.CurrentCultureIgnoreCase))
                {
                    var strProb = new TextRange(this.rtbxCellContent.Document.ContentStart, this.rtbxCellContent.Document.ContentEnd).Text.Trim();
                    try
                    {
                        new ElemProb(strProb);
                    }
                    catch
                    {
                        return;
                    }
                }
                try
                {
                    String val = String.Empty;
                    if (this.rtbxCellContent.Visibility == Visibility.Visible)
                    {
                        val = new TextRange(this.rtbxCellContent.Document.ContentStart, this.rtbxCellContent.Document.ContentEnd).Text.Trim();
                        //val = String.Format("'{{ {0} }}", val);
                    }
                    if (this.dtgCellContent.Visibility == Visibility.Visible)
                    {
                        val = String.Join(" , ", valueList.Select(p => p.value.Trim()).ToArray());
                        //val = String.Format("'{{ {0} }}", val);
                    }
                    var datatype = this.pAttribute.Type;
                    if (datatype.CheckDataTypeOfVarLs(val))
                    {
                        //check elem trung nhau
                        removeDuplicateElements(ref val);


                        var attr = this.txtInfo.Content.ToString().Trim().ToLower();

                        //save
                        if (this.curTuple.valueSet.Keys.Contains(attr))
                        {
                            curTuple.valueSet[attr] = val.Split(',').Select(p => p.Trim()).ToList();
                        }
                        // Ps Attr
                        else
                        {
                            curTuple.Ps = new ElemProb(val);
                        }
                        try
                        {
                            RawDatabaseService.Instance().Update(curTuple, pRelation, attr);

                            Parameter.resetMainF    = true;
                            Parameter.activeTabIdx  = 1;
                            Parameter.RelationIndex = (int)pRelation.id - 1;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The value is invalid with its Datatype", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("the Value have not Edited yet!", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Beispiel #9
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (this.cbxSch.SelectedItem is null)
            {
                MessageBox.Show("Please choose any item of Combobox", "Notification", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            try
            {
                if (this.txtRelName.Text.Trim().Length <= 0)
                {
                    MessageBox.Show("You must enter a relation name, please try again !", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }


                if (this.txtRelName.Text.ToLower() == "select" || this.txtRelName.Text.ToLower() == "from" || this.txtRelName.Text.ToLower() == "where")
                {
                    MessageBox.Show("Relation name is not valid ( not match with keyword 'select', 'from', 'where')", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                foreach (var item in StaticParams.currentDb.Relations.ToList())
                {
                    if (item.relationName.Equals(this.txtRelName.Text.ToLower(), StringComparison.OrdinalIgnoreCase))
                    {
                        MessageBox.Show("This relation name has already existed in the database, please try again !", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }

                PSchema schema   = StaticParams.currentDb.Schemas.SingleOrDefault(c => c == this.cbxSch.SelectedItem);
                var     relation = new PRelation();
                relation.relationName = this.txtRelName.Text.ToLower();
                relation.id           = RawDatabaseService.Instance().getNextIdRl();
                relation.schema       = schema;

                try
                {
                    //in db
                    RawDatabaseService.Instance().Insert(relation);
                    //in ram
                    StaticParams.currentDb.Relations.Add(relation);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (MessageBox.Show("Add successfully.Do you want add a new relation name ?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    this.txtRelName.Focus();
                    this.txtRelName.Text = null;
                    this.Window_Loaded(sender, e);
                }
                else
                {
                    this.Close();
                }
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }
        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();
            }
        }