Exemple #1
0
        public DataCollection AddDataCollection(
            IEnumerable <IFreeDocument> source, string collectionName = null, bool isCover = false)
        {
            if (collectionName == null)
            {
                collectionName = GlobalHelper.Get("key_250") + DateTime.Now.ToShortTimeString();
            }

            var collection = DataCollections.FirstOrDefault(d => d.Name == collectionName);

            if (collection != null)
            {
                if (!isCover)
                {
                    foreach (var computeable in source)
                    {
                        collection.ComputeData.Add(computeable);
                    }
                    collection.OnPropertyChanged("Count");
                }
                else
                {
                    XLogSys.Print.Warn(collectionName + GlobalHelper.Get("key_251"));
                }
                return(collection);
            }
            var data = new DataCollection(source.ToList())
            {
                Name = collectionName
            };

            DataCollections.Add(data);
            return(data);
        }
Exemple #2
0
        public bool Delete(long p_id)
        {
            DataCollections _col = new DataCollections(TABLE_NAME);

            _col.Add(DataTypes.NVarchar, "Id", FieldTypes.Criterion, p_id, "=");
            return(dao.DoDelete(_col));
        }
Exemple #3
0
        private DataCollections GetObject()
        {
            DataCollections _col = new DataCollections(TABLE_NAME);

            _col.Add(DataTypes.Number, "ContestId", FieldTypes.DefaultValue, ContestId, "");
            return(_col);
        }
Exemple #4
0
        public DataTable LoadAll()
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("V_" + TABLE_NAME);

            col.Add(DataTypes.NVarchar, "*", FieldTypes.DefaultValue, "", "");
            return(dao.DoQuery(col, ref iResult));
        }
Exemple #5
0
        private DataCollections GetObject()
        {
            DataCollections _col = new DataCollections(TABLE_NAME);

            _col.Add(DataTypes.NVarchar, "Name", FieldTypes.DefaultValue, Name, "");
            _col.Add(DataTypes.Number, "MaximumPoints", FieldTypes.DefaultValue, MaximumPoints, "");
            _col.Add(DataTypes.Number, "TimeLimit", FieldTypes.DefaultValue, TimeLimit, "");
            _col.Add(DataTypes.Number, "MemoryLimit", FieldTypes.DefaultValue, MemoryLimit, "");
            _col.Add(DataTypes.Number, "SourceCodeSizeLimit", FieldTypes.DefaultValue, SourceCodeSizeLimit, "");
            _col.Add(DataTypes.NVarchar, "IsVisible", FieldTypes.DefaultValue, IsVisible, "");
            _col.Add(DataTypes.Number, "OrderBy", FieldTypes.DefaultValue, OrderBy, "");
            _col.Add(DataTypes.NVarchar, "Url", FieldTypes.DefaultValue, Url, "");
            _col.Add(DataTypes.NVarchar, "URL_Content", FieldTypes.DefaultValue, URL_Content, "");

            _col.Add(DataTypes.Number, "ProblemType", FieldTypes.DefaultValue, ProblemType, "");
            return(_col);
        }
Exemple #6
0
        public DataTable LoadByUserID(int filter)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("V_" + TABLE_NAME);

            col.Add(DataTypes.NVarchar, "*", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.NVarchar, "UserId", FieldTypes.Criterion, CGlobal.GetUserID(), "=");
            switch (filter)
            {
            case 1:     // dc phe duyet
                col.Add(DataTypes.Number, "IsAccepted", FieldTypes.Criterion, 1, "=");
                // col.FILTER = " DateAccept IS NOT NULL";
                col.ORDERBY = " ORDER BY DateAccept desc";
                break;

            case 2:     //chua phe duyet
                col.Add(DataTypes.Number, "IsAccepted", FieldTypes.Criterion, 0, "=");
                // col.FILTER = " DateAccept IS NULL";
                col.ORDERBY = " ORDER BY DateRequest desc";
                break;

            default:     // dang hoc
                col.Add(DataTypes.DateTime, "EndTime", FieldTypes.Criterion, DateTime.Now, ">");
                col.Add(DataTypes.DateTime, "StartTime", FieldTypes.Criterion, DateTime.Now, "<");
                // col.FILTER = " DateAccept IS NOT NULL";
                col.Add(DataTypes.Number, "IsAccepted", FieldTypes.Criterion, 1, "=");
                col.ORDERBY = " ORDER BY DateAccept desc";
                break;
            }

            return(dao.DoQuery(col, ref iResult));
        }
Exemple #7
0
        public long getPoint(long userID)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("Users");

            col.Add(DataTypes.Number, "Point", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.Number, "ID", FieldTypes.Criterion, userID, "=");
            DataTable dt = dao.DoQuery(col, ref iResult);

            try
            {
                return(long.Parse(dt.Rows[0][0].ToString()));
            }
            catch
            {
                throw;
            }
        }
Exemple #8
0
        public string GetPassword(long id)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections(TABLE_NAME);

            col.Add(DataTypes.NVarchar, "ContestPassword", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.Number, "ID", FieldTypes.Criterion, id, "=");
            DataTable dt = dao.DoQuery(col, ref iResult);

            try
            {
                return(dt.Rows[0]["ContestPassword"].ToString());
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
Exemple #9
0
        public DataTable LoadByStatus()
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("V_Submission_Status");

            col.Add(DataTypes.NVarchar, "*", FieldTypes.DefaultValue, "", "");

            col.ORDERBY = " ORDER BY TimeSubmiss DESC";
            return(dao.DoQuery(col, ref iResult));
        }
Exemple #10
0
        public long Insert()
        {
            DataCollections _col = new DataCollections(TABLE_NAME);

            _col.Add(DataTypes.Number, "NotificationID", FieldTypes.DefaultValue, NotificationID, "");
            if (UserID > 0)
            {
                _col.Add(DataTypes.Number, "UserID", FieldTypes.DefaultValue, UserID, "");
            }
            else if (ContestID > 0)
            {
                _col.Add(DataTypes.Number, "ContestID", FieldTypes.DefaultValue, ContestID, "");
            }
            else if (ProblemID > 0)
            {
                _col.Add(DataTypes.Number, "ProblemID", FieldTypes.DefaultValue, ProblemID, "");
            }
            return(dao.DoInsertReturnID(_col));
        }
Exemple #11
0
        public bool CheckIsAccepted(long contestID)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("MyContest");

            col.Add(DataTypes.Number, "IsAccepted", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.Number, "ContestId", FieldTypes.Criterion, contestID, "=");
            col.Add(DataTypes.Number, "UserId", FieldTypes.Criterion, CGlobal.GetUserID(), "=");
            DataTable dt = dao.DoQuery(col, ref iResult);

            try
            {
                return(Boolean.Parse(dt.Rows[0][0].ToString()));
            }
            catch
            {
                return(false);
            }
        }
Exemple #12
0
        public bool CheckIsAdmin(long id)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections(TABLE_NAME);

            col.Add(DataTypes.Number, "UserType", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.Number, "Id", FieldTypes.Criterion, id, "=");
            col.Add(DataTypes.Number, "IsEnable", FieldTypes.Criterion, 1, "=");
            DataTable dt = dao.DoQuery(col, ref iResult);

            try
            {
                return(int.Parse(dt.Rows[0][0].ToString()) > 1);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #13
0
        public long GetID(string uname, string pas)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections(TABLE_NAME);

            col.Add(DataTypes.Number, "ID", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.NVarchar, "UserName", FieldTypes.Criterion, uname, "=");
            col.Add(DataTypes.NVarchar, "Password", FieldTypes.Criterion, pas, "=");
            col.Add(DataTypes.Number, "IsEnable", FieldTypes.Criterion, 1, "=");
            DataTable dt = dao.DoQuery(col, ref iResult);

            try
            {
                return(int.Parse(dt.Rows[0][0].ToString()));
            }
            catch (Exception)
            {
                return(0);
            }
        }
Exemple #14
0
        public long getPoint(long contestID, long problemID, long userID)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections(TABLE_NAME);

            col.Add(DataTypes.Number, "MAX (Points)", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.Number, "UserID", FieldTypes.Criterion, userID, "=");
            col.Add(DataTypes.Number, "ProblemId", FieldTypes.Criterion, problemID, "=");
            col.Add(DataTypes.Number, "ContestId", FieldTypes.Criterion, contestID, "=");

            DataTable dt = dao.DoQuery(col, ref iResult);

            try
            {
                return(long.Parse(dt.Rows[0][0].ToString()));
            }
            catch
            {
                throw;
            }
        }
Exemple #15
0
        public void LoadToCombo(DevExpress.Web.Bootstrap.BootstrapComboBox objCombo, bool isAll, string code)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections(TABLE_NAME);

            col.Add(DataTypes.NVarchar, "*", FieldTypes.DefaultValue, "", "");
            col.Add(DataTypes.NVarchar, "code", FieldTypes.Criterion, code, "=");
            DataTable dt = dao.DoQuery(col, ref iResult);

            if (isAll)
            {
                DataRow dr = dt.NewRow();
                dr["value"] = "0";
                dr["text"]  = "";
                dt.Rows.InsertAt(dr, 0);
            }
            objCombo.DataSource = dt;
            objCombo.TextField  = "text";
            objCombo.ValueField = "value";
            objCombo.DataBind();
            objCombo.SelectedIndex = 0;
        }
Exemple #16
0
        public void LoadType(DevExpress.Web.Bootstrap.BootstrapComboBox objCombo)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("UserType");

            col.Add(DataTypes.NVarchar, "*", FieldTypes.DefaultValue, "", "");
            DataTable dt = dao.DoQuery(col, ref iResult);

            objCombo.DataSource = dt;
            objCombo.TextField  = "Name";
            objCombo.ValueField = "Id";
            objCombo.DataBind();
            objCombo.SelectedIndex = 0;
        }
Exemple #17
0
        public DataTable LoadBySearch(int caseToSearch)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("V_Users");

            col.Add(DataTypes.NVarchar, "*", FieldTypes.DefaultValue, "", "");
            switch (caseToSearch)
            {
            case 0:
                col.Add(DataTypes.Number, "IsEnable", FieldTypes.Criterion, 1, "=");
                break;

            case 1:
                col.Add(DataTypes.Number, "IsEnable", FieldTypes.Criterion, 0, "=");
                break;

            case 2:     // all
                break;

            default:
                break;
            }
            return(dao.DoQuery(col, ref iResult));
        }
Exemple #18
0
        public string GetMyNotiNotSeenByUser()
        {
            DataCollections col = new DataCollections("P_GetMyNotiNotSeenByUser");

            col.Add(DataTypes.Number, "@userid", FieldTypes.Criterion, CGlobal.GetUserID(), "=");
            DataTable dt = dao.exeSelectPro(col, "P_GetMyNotiNotSeenByUser");

            try
            {
                return(dt.Rows[0][0].ToString());
            }
            catch
            {
                return("0");
            }
        }
Exemple #19
0
        public long Insert()
        {
            DataCollections _col = new DataCollections(TABLE_NAME);

            _col.Add(DataTypes.Number, "UserID", FieldTypes.DefaultValue, CGlobal.GetUserID(), "");
            _col.Add(DataTypes.DateTime, "TimeSubmiss", FieldTypes.DefaultValue, DateTime.Now, "");

            _col.Add(DataTypes.Number, "ProblemId", FieldTypes.DefaultValue, ProblemId, "");
            _col.Add(DataTypes.Number, "CompilerID", FieldTypes.DefaultValue, CompilerID, "");
            _col.Add(DataTypes.Number, "ProcessType", FieldTypes.DefaultValue, 1, "");
            _col.Add(DataTypes.Number, "ContestId", FieldTypes.DefaultValue, ContestId, "");
            _col.Add(DataTypes.Number, "Points", FieldTypes.DefaultValue, 0, "");

            return(dao.DoInsertReturnID(_col));
        }
Exemple #20
0
        public DataTable LoadBySearchComponent(int type, long notiID)
        {
            int             iResult = 1;
            DataCollections col     = new DataCollections("V_" + TABLE_NAME);

            //col.Add(DataTypes.NVarchar, "*", FieldTypes.DefaultValue, "", "");
            //if (status >= 1 && status <= 3)
            //{
            //    col.Add(DataTypes.Number, "NotiType", FieldTypes.Criterion, status, "=");
            //}
            switch (type)
            {
            case 1:
                col.Add(DataTypes.NVarchar, "contestname", FieldTypes.DefaultValue, "", "");
                col.ORDERBY = " ORDER BY contestname";
                break;

            case 2:
                col.Add(DataTypes.NVarchar, "problemName", FieldTypes.DefaultValue, "", "");
                col.ORDERBY = " ORDER BY problemName";
                break;

            case 3:
                col.Add(DataTypes.NVarchar, "SendTo", FieldTypes.DefaultValue, "", "");
                col.ORDERBY = " ORDER BY SendTo";
                break;

            default:
                col.Add(DataTypes.NVarchar, "contestname", FieldTypes.DefaultValue, "", "");
                col.Add(DataTypes.NVarchar, "problemName", FieldTypes.DefaultValue, "", "");
                col.Add(DataTypes.NVarchar, "SendTo", FieldTypes.DefaultValue, "", "");
                col.ORDERBY = " ORDER BY CreatedOn DESC";
                break;
            }
            col.Add(DataTypes.Number, "NotificationID", FieldTypes.Criterion, notiID, "=");
            col.Add(DataTypes.Number, "CreatedBy", FieldTypes.Criterion, CGlobal.GetUserID(), "=");


            return(dao.DoQuery(col, ref iResult));
        }
Exemple #21
0
        private void LoadData()
        {
            FileOperation fileOperation = new FileOperation();

            if (!fileOperation.CheckFileExists(_filePath))
            {
                DataCollections.Add(new TableModel("", "", ""));

                try { fileOperation.CreateFile(_filePath); }
                catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); }

                try { fileOperation.SaveFile(_filePath, DataCollections); }
                catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); }
            }

            if (ApplicationDeployment.IsNetworkDeployed)
            {
                try { _filePath = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]; }
                catch { _filePath = Environment.CurrentDirectory + "\\keys.pdk"; }
            }

            DataCollections = new FileOperation().OpenFile(_filePath);
        }
Exemple #22
0
 public void AddDataCollection(DataCollection collection)
 {
     DataCollections.Add(collection);
 }
Exemple #23
0
        public override bool Init()
        {
            if (MainDescription.IsUIForm)
            {
                DataCollections = new SafeObservable <DataCollection>();
                dockableManager = MainFrmUI as IDockableManager;

                var view        = PluginProvider.GetObjectInstance <ICustomView>("系统状态视图");
                var userControl = view as UserControl;
                if (userControl != null)
                {
                    userControl.DataContext = MainFrmUI;
                    dockableManager.AddDockAbleContent(FrmState.Mini, view, "系统状态视图");
                }
            }

            else
            {
                DataCollections = new ObservableCollection <DataCollection>();
            }

            processManager = MainFrmUI.PluginDictionary["模块管理"] as IProcessManager;


            commands = new List <ICommand>();
            var dbaction = new BindingAction();

            dbaction.ChildActions.Add(new Command("配置连接",
                                                  obj =>
            {
                Window w = PropertyGridFactory.GetPropertyWindow(obj);
                w.ShowDialog();
            },
                                                  obj => obj != null));
            dbaction.ChildActions.Add(
                new Command("刷新", obj => RefreshConnect(obj as IDataBaseConnector), obj => obj != null));
            dbaction.ChildActions.Add(
                new Command("执行查询", obj =>
            {
                var query          = new QueryEntity();
                query.Connector    = obj as IDataBaseConnector;
                query.GetQueryFunc = d =>
                {
                    if (d == null)
                    {
                        return;
                    }
                    if (d.Any() == false)
                    {
                        return;
                    }

                    AddDataCollection(d, GetNewName());
                };
                propertyGridWindow.SetObjectView(query);
            }, obj => obj != null));
            dbaction.ChildActions.Add(
                new Command("删除连接", obj =>
            {
                if (MessageBox.Show("确定要删除该连接吗?", "提示信息", MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes)
                {
                    var con = obj as DBConnectorBase;
                    _dbConnections.Remove(con);
                }
            }, obj => obj != null));
            var dataaction = new BindingAction();


            var tableAction = new BindingAction();

            tableAction.ChildActions.Add(new Command(
                                             "查看",
                                             async obj =>
            {
                var items = obj as TableInfo;
                List <IFreeDocument> dataAll = null;
                try
                {
                    dataAll = await
                              GetDataFromDB(items.Connector, items.Name, true,
                                            items.Connector is FileManager ? -1 : 200);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("文件打开失败" + ex.Message);
                    return;
                }


                if (dataAll == null || dataAll.Count == 0)
                {
                    XLogSys.Print.Warn("没有在表中的发现可用的数据");
                    return;
                }
                if (items.Connector is FileManager)
                {
                    string file = (items.Connector as FileManager).LastFileName;
                    var name    = Path.GetFileNameWithoutExtension(file);
                    AddDataCollection(dataAll, name);
                    return;
                }
                var excel = PluginProvider.GetObjectInstance <IDataViewer>("可编辑列表");
                if (excel == null)
                {
                    return;
                }
                object view = excel.SetCurrentView(dataAll.Select(d => d as IFreeDocument).ToList());

                if (ControlExtended.DockableManager != null)
                {
                    ControlExtended.DockableManager.AddDockAbleContent(
                        FrmState.Custom, view, items.Name);
                }
            },
                                             obj => obj != null));
            tableAction.ChildActions.Add(new Command(
                                             "添加到数据集",
                                             async obj =>
            {
                var items = obj as TableInfo;
                List <IFreeDocument> datas = await GetDataFromDB(items.Connector, items.Name, true);
                if (datas == null)
                {
                    return;
                }
                AddDataCollection(datas, items.Name);
            },
                                             obj => obj != null));
            tableAction.ChildActions.Add(new Command(
                                             "添加虚拟数据集",
                                             obj =>
            {
                var con = obj as TableInfo;
                ReadCollection(con.Connector, con.Name, true);
            },
                                             obj => obj != null));
            tableAction.ChildActions.Add(new Command(
                                             "删除表",
                                             obj =>
            {
                var items = obj as TableInfo;

                DropTable(items.Connector, items.Name);
            },
                                             obj => obj != null));
            tableAction.ChildActions.Add(new Command(
                                             "查看属性",
                                             obj =>
            {
                Window w = PropertyGridFactory.GetPropertyWindow(obj);
                w.ShowDialog();
            },
                                             obj => obj != null));
            tableAction.ChildActions.Add(new Command(
                                             "执行查询",
                                             obj =>
            {
                var query          = new QueryEntity();
                query.TableInfo    = obj as TableInfo;
                query.Connector    = query.TableInfo.Connector;
                query.GetQueryFunc = d =>
                {
                    if (d == null)
                    {
                        return;
                    }
                    if (d.Any() == false)
                    {
                        return;
                    }

                    AddDataCollection(d, GetNewName());
                };
                propertyGridWindow.SetObjectView(query);
            }, obj => obj != null));


            var visitData = new BindingAction("浏览方式");

            IEnumerable <Command> visitCommands = PluginProvider.GetPluginCollection(typeof(IDataViewer)).Select(
                d =>
            {
                var comm     = new Command(d.Name);
                comm.Execute = d2 =>
                {
                    var data = d2 as DataCollection;

                    if (data.Count == 0)
                    {
                        MessageBox.Show("不存在任何数据", "提示信息");
                        return;
                    }


                    ControlExtended.UIInvoke(() =>
                    {
                        var view = PluginProvider.GetObjectInstance <IDataViewer>(d.Name);

                        object r = view.SetCurrentView(data.ComputeData);

                        if (ControlExtended.DockableManager != null)
                        {
                            ControlExtended.DockableManager.AddDockAbleContent(
                                FrmState.Float, r, data.Name + " " + d.Name);
                        }
                    });
                };
                return(comm);
            });

            visitData.Execute = obj => visitCommands.FirstOrDefault(d => d.Text == "可编辑列表").Execute(obj);
            foreach (Command visitCommand in visitCommands)
            {
                visitData.ChildActions.Add(visitCommand);
            }

            dataaction.ChildActions.Add(new Command(
                                            "数据清洗", obj =>
            {
                DataCollection collection = GetCollection(obj);
                if (collection == null)
                {
                    return;
                }

                var plugin        = processManager.GetOneInstance("SmartETLTool", true, true) as SmartETLTool;
                dynamic generator = PluginProvider.GetObjectByType <IColumnProcess>("TableGE");
                generator.TableSelector.SelectItem = collection;
                plugin.CurrentETLTools.Add(generator);
                plugin.RefreshSamples(true);
                ControlExtended.DockableManager.ActiveModelContent(plugin);
            }, obj => true, "new"));
            dataaction.ChildActions.Add(new Command(
                                            "拷贝", obj =>
            {
                DataCollection collection = GetCollection(obj);
                if (collection == null)
                {
                    return;
                }
                DataCollection n = collection.Clone(true);
                n.Name           = GetNewName(collection.Name);
                DataCollections.Add(n);
            }, obj => true, "page_new"));
            var saveData = new Command("另存为", d =>
            {
                DataCollection collection = GetCollection(d);
                if (collection == null)
                {
                    return;
                }
                var ofd = new SaveFileDialog {
                    Filter = FileConnector.GetDataFilter(), DefaultExt = "*"
                };

                ofd.FileName = collection.Name + ".xlsx";
                if (ofd.ShowDialog() == true)
                {
                    string filename = ofd.FileName;
                    SaveFile(collection.Name, filename);
                }
            }, obj => true, "save");

            dataaction.ChildActions.Add(saveData);
            dataaction.ChildActions.Add(visitData);
            dataaction.ChildActions.Add(new Command(
                                            "新建",
                                            obj =>
                                            DataCollections.Add(new DataCollection(new List <IFreeDocument>())
            {
                Name = GetNewName("新建数据集")
            }), obj => true, "box"));
            dataaction.ChildActions.Add(new Command(
                                            "配置", obj =>
            {
                DataCollection collection = GetCollection(obj);
                if (collection != null)
                {
                    propertyGridWindow.SetObjectView(collection);
                }
            }, obj => true, "settings"));
            dataaction.ChildActions.Add(new Command(
                                            "删除", obj =>
            {
                DataCollection collection = GetCollection(obj);
                if (collection != null)
                {
                    DataCollections.Remove(collection);
                }
            }, obj => true, "delete"));

            var convert = new BindingAction("转换表类型");

            dataaction.ChildActions.Add(convert);
            convert.ChildActions.Add(new Command("转为非虚拟数据集", obj =>
            {
                DataCollection coll = GetCollection(obj);
                if (coll.Count > 500000)
                {
                    if (
                        MessageBox.Show("本集合数据量较大,转换可能会占用较高的内存和导致程序崩溃,确定继续吗?", "提示信息", MessageBoxButton.YesNoCancel) !=
                        MessageBoxResult.Yes)
                    {
                        return;
                    }
                }
                var docuts = new List <IFreeDocument>();
                var task   = TemporaryTask.AddTempTask("转为非虚拟数据集", coll.ComputeData, d =>
                {
                    if (d != null)
                    {
                        docuts.Add(d as IFreeDocument);
                    }
                }, result =>
                {
                    var collection = new DataCollection(docuts)
                    {
                        Name = coll.Name + '1'
                    };
                    AddDataCollection(collection);
                    this.DataCollections.Remove(coll);
                });
                processManager.CurrentProcessTasks.Add(task);
            }));
            var insertdb = new BindingAction("保存到数据库");

            insertdb.SetChildActionSource(() =>
            {
                return(_dbConnections.Select(dataBaseConnector => new Command(dataBaseConnector.Name, obj =>
                {
                    var data = obj as DataCollection;
                    processManager.CurrentProcessTasks.Add(TemporaryTask.AddTempTask(data.Name + "插入到数据库", dataBaseConnector.InserDataCollection(data), result => dataBaseConnector.RefreshTableNames(), count: data.Count / 1000));
                })).Cast <ICommand>().ToList());
            });


            dataaction.ChildActions.Add(insertdb);
            var otherDataAction = new BindingAction();

            otherDataAction.ChildActions.Add(new Command("清空数据", obj => CleanData(), obj => DataCollections.Count > 0));


            commands.Add(dbaction);
            commands.Add(tableAction);
            commands.Add(dataaction);
            commands.Add(otherDataAction);
            var dblistAction = new BindingAction("数据库管理");

            var addnew = new BindingAction("增加新连接");

            dblistAction.ChildActions.Add(addnew);
            foreach (XFrmWorkAttribute item in PluginProvider.GetPluginCollection(typeof(IDataBaseConnector)))
            {
                addnew.ChildActions.Add(new Command(item.Name)
                {
                    Execute = obj =>
                    {
                        var con  = PluginProvider.GetObjectInstance(item.MyType) as DBConnectorBase;
                        con.Name = item.Name;

                        _dbConnections.Add(con);
                    }
                });
            }
            commands.Add(dblistAction);


            dockableManager = MainFrmUI as IDockableManager;
            if (processManager?.CurrentProject != null)

            {
                LoadDataConnections();
            }
            processManager.OnCurrentProjectChanged += (s, e) => LoadDataConnections();

            ConfigUI = PropertyGridFactory.GetInstance(_dbConnections.FirstOrDefault());


            propertyGridWindow = MainFrmUI.PluginDictionary["属性配置器"] as XFrmWorkPropertyGrid;
            var changed = DataCollections as INotifyCollectionChanged;

            changed.CollectionChanged += (s, e) => OnDataSourceChanged(new EventArgs());

            return(true);
        }
Exemple #24
0
        public override bool Init()
        {
            if (MainDescription.IsUIForm)
            {
                DataCollections = new SafeObservable <DataCollection>();
                dockableManager = MainFrmUI as IDockableManager;
                var views = "223:Mini 794:Middle";
                foreach (var item in views.Split(' '))
                {
                    var item2   = item.Split(':');
                    var name    = item2[0];
                    var control = FrmState.Mini;
                    Enum.TryParse(item2[1], out control);
                    var itemName = "key_" + name;
                    itemName = GlobalHelper.Get(itemName);
                    var view        = PluginProvider.GetObjectInstance <ICustomView>(GlobalHelper.Get(itemName));
                    var userControl = view as UserControl;
                    if (userControl != null)
                    {
                        if (name == "223")
                        {
                            dynamic dcontrol = userControl;
                            dataListBox = dcontrol.dataListBox as ListBox;
                        }
                        userControl.DataContext = MainFrmUI;
                        dockableManager.AddDockAbleContent(control, view, itemName);
                    }
                }
            }

            else
            {
                DataCollections = new ObservableCollection <DataCollection>();
            }

            processManager = MainFrmUI.PluginDictionary["DataProcessManager"] as IProcessManager;


            commands = new List <ICommand>();
            var dbaction = new BindingAction();

            dbaction.ChildActions.Add(new Command(GlobalHelper.Get("key_224"),
                                                  obj =>
            {
                var w = PropertyGridFactory.GetPropertyWindow(obj);
                w.ShowDialog();
            },
                                                  obj => obj != null, "edit"));
            dbaction.ChildActions.Add(
                new Command(GlobalHelper.Get("key_142"), obj => RefreshConnect(obj as IDataBaseConnector),
                            obj => obj != null, "refresh"));
            dbaction.ChildActions.Add(
                new Command(GlobalHelper.Get("key_213"), obj =>
            {
                var query          = new QueryEntity();
                query.Connector    = obj as IDataBaseConnector;
                query.GetQueryFunc = d =>
                {
                    if (d == null)
                    {
                        return;
                    }
                    if (d.Any() == false)
                    {
                        return;
                    }

                    AddDataCollection(d, GetNewName());
                };
                PropertyGridFactory.GetPropertyWindow(query).ShowDialog();
            }, obj => obj != null, "magnify"));
            dbaction.ChildActions.Add(
                new Command(GlobalHelper.Get("key_225"), obj =>
            {
                if (
                    MessageBox.Show(GlobalHelper.Get("key_226"), GlobalHelper.Get("key_99"),
                                    MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes)
                {
                    var con = obj as DBConnectorBase;
                    _dbConnections.Remove(con);
                }
            }, obj => obj != null, "delete"));
            var dataaction = new BindingAction();


            var tableAction = new BindingAction();

            tableAction.ChildActions.Add(new Command(
                                             GlobalHelper.Get("view"),
                                             async obj =>
            {
                var items = obj as TableInfo;
                List <IFreeDocument> dataAll = null;
                try
                {
                    dataAll = await
                              GetDataFromDB(items.Connector, items.Name, true,
                                            items.Connector is FileManager ? -1 : 200);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(GlobalHelper.Get("key_228") + ex.Message);
                    return;
                }


                if (dataAll == null || dataAll.Count == 0)
                {
                    XLogSys.Print.Warn(GlobalHelper.Get("key_229"));
                    return;
                }
                if (items.Connector is FileManager)
                {
                    var file = (items.Connector as FileManager).LastFileName;
                    var name = Path.GetFileNameWithoutExtension(file);
                    AddDataCollection(dataAll, name, isCover: true);
                    return;
                }
                var excel = PluginProvider.GetObjectInstance <IDataViewer>(GlobalHelper.Get("key_230"));
                if (excel == null)
                {
                    return;
                }
                var view = excel.SetCurrentView(dataAll.Select(d => d).ToList());

                if (ControlExtended.DockableManager != null)
                {
                    ControlExtended.DockableManager.AddDockAbleContent(
                        FrmState.Custom, view, items.Name);
                }
            },
                                             obj => obj != null));
            tableAction.ChildActions.Add(new Command(
                                             GlobalHelper.Get("key_231"),
                                             async obj =>
            {
                var items = obj as TableInfo;
                var datas = await GetDataFromDB(items.Connector, items.Name, true);
                if (datas == null)
                {
                    return;
                }
                AddDataCollection(datas, items.Name);
            },
                                             obj => obj != null, "add"));
            tableAction.ChildActions.Add(new Command(
                                             GlobalHelper.Get("key_232"),
                                             obj =>
            {
                var con = obj as TableInfo;
                ReadCollection(con.Connector, con.Name, true);
            },
                                             obj => obj != null, "layer_add"));
            tableAction.ChildActions.Add(new Command(
                                             GlobalHelper.Get("key_233"),
                                             obj =>
            {
                var items = obj as TableInfo;

                DropTable(items.Connector, items.Name);
            },
                                             obj => obj != null, "delete"));
            tableAction.ChildActions.Add(new Command(
                                             GlobalHelper.Get("key_234"),
                                             obj =>
            {
                var w = PropertyGridFactory.GetPropertyWindow(obj);
                w.ShowDialog();
            },
                                             obj => obj != null, "edit"));
            tableAction.ChildActions.Add(new Command(
                                             GlobalHelper.Get("key_213"),
                                             obj =>
            {
                var query          = new QueryEntity();
                query.TableInfo    = obj as TableInfo;
                query.Connector    = query.TableInfo.Connector;
                query.GetQueryFunc = d =>
                {
                    if (d == null)
                    {
                        return;
                    }
                    if (d.Any() == false)
                    {
                        return;
                    }

                    AddDataCollection(d, GetNewName());
                };
                PropertyGridFactory.GetPropertyWindow(query).ShowDialog();
            }, obj => obj != null, "magnify"));


            var visitData = new BindingAction(GlobalHelper.Get("key_235"));

            var visitCommands = PluginProvider.GetPluginCollection(typeof(IDataViewer)).Select(
                d =>
            {
                var comm     = new Command(d.Name);
                comm.Execute = d2 =>
                {
                    var data = d2 as DataCollection;

                    if (data.Count == 0)
                    {
                        MessageBox.Show(GlobalHelper.Get("key_236"), GlobalHelper.Get("key_99"));
                        return;
                    }


                    ControlExtended.UIInvoke(() =>
                    {
                        var view = PluginProvider.GetObjectInstance <IDataViewer>(d.Name);

                        var r = view.SetCurrentView(data.ComputeData);

                        if (ControlExtended.DockableManager != null)
                        {
                            var window = new Window {
                                Title = data.Name + " " + d.Name
                            };
                            window.WindowState = WindowState.Maximized;
                            window.Content     = r;
                            window.Activate();
                            window.ShowDialog();
                        }
                    });
                };
                return(comm);
            });

            visitData.Execute =
                obj => visitCommands.FirstOrDefault(d => d.Text == GlobalHelper.Get("key_230")).Execute(obj);
            foreach (var visitCommand in visitCommands)
            {
                visitData.ChildActions.Add(visitCommand);
            }

            dataaction.ChildActions.Add(new Command(
                                            GlobalHelper.Get("smartetl_name"), obj =>
            {
                var collection = GetSelectedCollection(obj).FirstOrDefault();
                if (collection == null)
                {
                    return;
                }

                var plugin = processManager.GetOneInstance("SmartETLTool", true, true, true) as SmartETLTool;

                dynamic generator = PluginProvider.GetObjectByType <IColumnProcess>("TableGE");
                generator.Father  = plugin;

                generator.TableSelector.SelectItem = collection.Name;
                plugin.CurrentETLTools.Add(generator);
                plugin.ETLMount++;
                plugin.Init();

                //plugin.RefreshSamples(true);
                ControlExtended.DockableManager.ActiveModelContent(plugin);
            }, obj => true, "new"));

            var saveData = new Command(GlobalHelper.Get("key_237"), d =>
            {
                var collection = GetSelectedCollection(d).FirstOrDefault();
                if (collection == null)
                {
                    return;
                }
                var ofd = new SaveFileDialog {
                    Filter = FileConnector.GetDataFilter(), DefaultExt = "*"
                };

                ofd.FileName = collection.Name + ".xlsx";
                if (ofd.ShowDialog() == true)
                {
                    var filename = ofd.FileName;
                    SaveFile(collection.Name, filename);
                }
            }, obj => true, "save");

            dataaction.ChildActions.Add(saveData);
            dataaction.ChildActions.Add(visitData);
            dataaction.ChildActions.Add(new Command(
                                            GlobalHelper.Get("key_238"),
                                            obj =>
            {
                if (obj != null)
                {
                    foreach (var collection in GetSelectedCollection(obj))
                    {
                        if (collection == null)
                        {
                            return;
                        }
                        var n  = collection.Clone(true);
                        n.Name = GetNewName(collection.Name);
                        DataCollections.Add(n);
                    }
                }
                else
                {
                    DataCollections.Add(new DataCollection(new List <IFreeDocument>())
                    {
                        Name = GetNewName(GlobalHelper.Get("key_239"))
                    });
                }
                ;
            }, obj => true, "add"));
            dataaction.ChildActions.Add(new Command(
                                            GlobalHelper.Get("key_240"), obj =>
            {
                var collection = GetSelectedCollection(obj).ToList();

                if (!collection.Any())
                {
                    return;
                }
                PropertyGridFactory.GetPropertyWindow(collection.FirstOrDefault()).ShowDialog();
            }, obj => true, "settings"));
            dataaction.ChildActions.Add(new Command(
                                            GlobalHelper.Get("key_169"), obj =>
            {
                foreach (var collection  in GetSelectedCollection(obj))
                {
                    if (collection != null)
                    {
                        DataCollections.Remove(collection);
                    }
                }
            }, obj => true, "delete"));

            var convert = new BindingAction(GlobalHelper.Get("key_241"));

            dataaction.ChildActions.Add(convert);
            convert.ChildActions.Add(new Command(GlobalHelper.Get("key_242"), obj =>
            {
                var coll = GetSelectedCollection(obj).FirstOrDefault();
                if (coll == null)
                {
                    return;
                }
                if (coll.Count > 500000)
                {
                    if (
                        MessageBox.Show(GlobalHelper.Get("key_243"), GlobalHelper.Get("key_99"),
                                        MessageBoxButton.YesNoCancel) !=
                        MessageBoxResult.Yes)
                    {
                        return;
                    }
                }
                var docuts = new List <IFreeDocument>();
                var task   = TemporaryTask <FreeDocument> .AddTempTaskSimple(GlobalHelper.Get("key_242"), coll.ComputeData, d =>
                {
                    if (d != null)
                    {
                        docuts.Add(d);
                    }
                }, result =>
                {
                    var collection = new DataCollection(docuts)
                    {
                        Name = coll.Name + '1'
                    };
                    AddDataCollection(collection);
                    DataCollections.Remove(coll);
                });
                processManager.CurrentProcessTasks.Add(task);
            }));
            var insertdb = new BindingAction(GlobalHelper.Get("key_244"));

            insertdb.SetChildActionSource(() =>
            {
                return(_dbConnections.Select(dataBaseConnector => new Command(dataBaseConnector.Name, obj =>
                {
                    var data = obj as DataCollection;
                    processManager.CurrentProcessTasks.Add(
                        TemporaryTask <FreeDocument> .AddTempTaskSimple(data.Name + GlobalHelper.Get("key_245"),
                                                                        dataBaseConnector.InserDataCollection(data), null, continueAction: (a) => dataBaseConnector.RefreshTableNames(),
                                                                        count: data.Count / 1000));
                }, obj => dataBaseConnector.IsUseable, icon: "database")).Cast <ICommand>().ToList());
            });


            dataaction.ChildActions.Add(insertdb);
            var otherDataAction = new BindingAction();

            otherDataAction.ChildActions.Add(new Command(GlobalHelper.Get("key_132"), obj => CleanData(),
                                                         obj => DataCollections.Count > 0,
                                                         "clear"));


            commands.Add(dbaction);
            commands.Add(tableAction);
            commands.Add(dataaction);
            commands.Add(otherDataAction);
            var dblistAction = new BindingAction(GlobalHelper.Get("key_246"));

            var addnew = new BindingAction(GlobalHelper.Get("key_247"))
            {
                Icon = "add"
            };

            dblistAction.ChildActions.Add(addnew);
            foreach (var item in PluginProvider.GetPluginCollection(typeof(IDataBaseConnector)))
            {
                addnew.ChildActions.Add(new Command(item.Name)
                {
                    Execute = obj =>
                    {
                        var con  = PluginProvider.GetObjectInstance(item.MyType) as DBConnectorBase;
                        con.Name = item.Name;

                        _dbConnections.Add(con);
                    },
                    Icon = "connect"
                });
            }
            commands.Add(dblistAction);


            dockableManager = MainFrmUI as IDockableManager;
            if (processManager?.CurrentProject != null)

            {
                LoadDataConnections(processManager.CurrentProject.DBConnections);
            }

            if (MainDescription.IsUIForm)
            {
                ConfigUI = PropertyGridFactory.GetInstance(_dbConnections.FirstOrDefault());
            }

            var changed = DataCollections as INotifyCollectionChanged;

            changed.CollectionChanged += (s, e) => OnDataSourceChanged(new EventArgs());

            return(true);
        }
Exemple #25
0
 private void AddRow()
 {
     DataCollections.Add(new TableModel("", "", ""));
 }
Exemple #26
0
        private DataCollections GetObject()
        {
            DataCollections _col = new DataCollections("Users");

            _col.Add(DataTypes.Number, "UserType", FieldTypes.DefaultValue, UserType, "");
            _col.Add(DataTypes.NVarchar, "UserName", FieldTypes.DefaultValue, UserName, "");
            _col.Add(DataTypes.NVarchar, "Password", FieldTypes.DefaultValue, Password, "");
            _col.Add(DataTypes.NVarchar, "FullName", FieldTypes.DefaultValue, FullName, "");
            _col.Add(DataTypes.NVarchar, "Class", FieldTypes.DefaultValue, Class, "");
            _col.Add(DataTypes.NVarchar, "UserCode", FieldTypes.DefaultValue, UserCode, "");
            _col.Add(DataTypes.NVarchar, "Email", FieldTypes.DefaultValue, Email, "");
            _col.Add(DataTypes.DateTime, "DateOfBirth", FieldTypes.DefaultValue, DateOfBirth, "");
            _col.Add(DataTypes.NVarchar, "Phone", FieldTypes.DefaultValue, Phone, "");
            _col.Add(DataTypes.NVarchar, "IsEnable", FieldTypes.DefaultValue, IsEnable, "");
            _col.Add(DataTypes.Number, "OrderBy", FieldTypes.DefaultValue, OrderBy, "");
            return(_col);
        }