Exemplo n.º 1
0
        private async void ImportXml_Executed(object arg)
        {
            var file = PlatformManager.Instance.ShowImportXmlUI();

            if (file == null)
            {
                return;
            }

            try
            {
                using (var stream = File.OpenRead(file))
                {
                    var doc = await SIDocument.LoadXml(stream);

                    var docViewModel = new QDocument(doc, _storageContextViewModel)
                    {
                        Path = "", Changed = true, FileName = Path.GetFileNameWithoutExtension(file)
                    };

                    LoadMediaFromFolder(docViewModel, Path.GetDirectoryName(file));

                    DocList.Add(docViewModel);
                }
            }
            catch (Exception exc)
            {
                ShowError(exc);
            }
        }
Exemplo n.º 2
0
        public StatisticsViewModel(QDocument document)
        {
            _document = document;

            Create = new SimpleCommand(Create_Executed);
            Create_Executed();
        }
        public SelectThemesViewModel(QDocument document)
        {
            _document = document;
            Themes    = _document.Document.Package.Rounds.SelectMany(round => round.Themes).Select(theme => new SelectableTheme(theme)).ToArray();

            Select  = new SimpleCommand(Select_Executed);
            Select2 = new SimpleCommand(Select2_Executed);
        }
Exemplo n.º 4
0
        public ExportViewModel(QDocument source, ExportFormats format)
        {
            _source = source;
            _format = format;

            Save  = new SimpleCommand(Save_Executed);
            Print = new SimpleCommand(Print_Executed);

            BuildDocument();
        }
Exemplo n.º 5
0
        public MediaStorageViewModel(QDocument document, DataCollection collection, string header)
        {
            _document = document;
            _header   = header;
            _name     = collection.Name;

            FillFiles(collection);

            AddItem    = new SimpleCommand(AddItem_Executed);
            DeleteItem = new SimpleCommand(Delete_Executed);
        }
Exemplo n.º 6
0
        private void LoadMediaFromFolder(QDocument document, string folder)
        {
            // Загрузим файлы контента при наличии ссылок на них
            foreach (var round in document.Package.Rounds)
            {
                foreach (var theme in round.Themes)
                {
                    foreach (var question in theme.Questions)
                    {
                        foreach (var atom in question.Scenario)
                        {
                            if (atom.Model.IsLink)
                            {
                                var link = document.Document.GetLink(atom.Model);

                                var collection = document.Images;
                                switch (atom.Model.Type)
                                {
                                case AtomTypes.Audio:
                                    collection = document.Audio;
                                    break;

                                case AtomTypes.Video:
                                    collection = document.Video;
                                    break;
                                }

                                if (collection.Files.Any(f => f.Model.Name == link.Uri))
                                {
                                    continue;
                                }

                                var resFileName = Path.Combine(folder, link.Uri);
                                if (!File.Exists(resFileName))
                                {
                                    continue;
                                }

                                collection.AddFile(resFileName);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void Initialize()
        {
            if (_args.Length > 0)
            {
                OpenFile(_args[0]);
            }

            if (AppSettings.Default.AutoSave)
            {
                var tempDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "SIQuester"));
                if (!tempDir.Exists)
                {
                    return;
                }

                if (tempDir.EnumerateFiles().Any())
                {
                    try
                    {
                        if (PlatformManager.Instance.Confirm("Обнаружены файлы, которые не были корректно сохранены при последней работе с программой. Восстановить их?"))
                        {
                            foreach (var file in tempDir.EnumerateFiles())
                            {
                                var tmpName = Path.Combine(Path.GetTempPath(), "SIQuester", Guid.NewGuid().ToString());
                                File.Copy(file.FullName, tmpName);
                                OpenFile(tmpName, overridePath: QDocument.DecodePath(file.Name));
                            }
                        }
                        else
                        {
                            var files = tempDir.EnumerateFiles().ToArray();
                            foreach (var file in files)
                            {
                                file.Delete();
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        ShowError(exc);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void AddQuestion_Executed(object arg)
        {
            try
            {
                var document = OwnerRound.OwnerPackage.Document;
                var price    = Questions.Count == 0 ? AppSettings.Default.QuestionBase : -1;

                if (price == -1)
                {
                    var n = Questions.Count;
                    if (n > 1)
                    {
                        var add = Questions[1].Model.Price - Questions[0].Model.Price;
                        price = Math.Max(0, Questions[n - 1].Model.Price + add);
                    }
                    else if (n > 0)
                    {
                        price = Questions[0].Model.Price * 2;
                    }
                    else if (OwnerRound.Model.Type == RoundTypes.Final)
                    {
                        price = 0;
                    }
                    else
                    {
                        price = 100;
                    }
                }

                var question = QDocument.CreateQuestion(price);

                var questionViewModel = new QuestionViewModel(question);
                Questions.Add(questionViewModel);

                QDocument.ActivatedObject = questionViewModel.Scenario.FirstOrDefault();
                document.Navigate.Execute(questionViewModel);
            }
            catch (Exception exc)
            {
                PlatformSpecific.PlatformManager.Instance.Inform(exc.Message, true);
            }
        }
Exemplo n.º 9
0
        private void AddTheme_Executed(object arg)
        {
            try
            {
                var document = OwnerPackage.Document;

                var theme = new Theme {
                    Name = ""
                };
                var themeViewModel = new ThemeViewModel(theme);

                document.BeginChange();

                try
                {
                    Themes.Add(themeViewModel);
                    if (AppSettings.Default.CreateQuestionsWithTheme)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            var question = QDocument.CreateQuestion((i + 1) * AppSettings.Default.QuestionBase);
                            themeViewModel.Questions.Add(new QuestionViewModel(question));
                        }
                    }
                }
                finally
                {
                    document.CommitChange();
                }

                QDocument.ActivatedObject = themeViewModel;
                document.Navigate.Execute(themeViewModel);
            }
            catch (Exception exc)
            {
                PlatformSpecific.PlatformManager.Instance.Inform(exc.Message, true);
            }
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            UtilHelper.RegisterCssStyleSheet(Page, "~/Styles/IbnFramework/windows.css");
            UtilHelper.RegisterCssStyleSheet(Page, "~/Styles/IbnFramework/Theme.css");
            UtilHelper.RegisterCssStyleSheet(Page, "~/Styles/IbnFramework/ibn.css");

            UtilHelper.RegisterScript(Page, "~/Scripts/browser.js");
            UtilHelper.RegisterScript(Page, "~/Scripts/buttons.js");

            if (Request["Refresh"] != null && Request["Refresh"] == "1")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(),
                                                        string.Format("try {{window.moveTo(0,0);window.resizeTo(screen.availWidth,screen.availHeight);window.opener.top.frames['right'].location.href='{0}';}}", this.ResolveUrl("~/Apps/ReportManagement/Pages/UserReport.aspx")) +
                                                        "catch (e){}", true);
            }
            if (!Page.IsPostBack)
            {
                if (Request["Mode"] != null && bool.Parse(Request["Mode"].ToString()))
                {
                    int iTemplateId = -1;
                    using (IDataReader reader = Report.GetReport(ReportId))
                    {
                        if (reader.Read())
                        {
                            iTemplateId = (int)reader["TemplateId"];
                        }
                    }
                    if (iTemplateId > 0)
                    {
                        using (IDataReader rdr = Report.GetReportTemplate(iTemplateId))
                        {
                            if (rdr.Read())
                            {
                                txtTemplateTitle.Text = rdr["Name"].ToString();
                            }
                        }
                    }
                    //					btnSaveVis.Visible = true;		--[2006/01/17]
                    btnSaveVis.Visible = false;
                }
                else
                {
                    btnSaveVis.Visible = false;
                }
            }
            if (ReportId == -1)
            {
                return;
            }

            if (!Page.IsPostBack && (Request["Export"] == null || Request["Export"] != "2"))
            {
                byte[] bit_data = null;
                using (IDataReader reader_BLOB = Report.GetReportBinaryData(ReportId))
                {
                    if (reader_BLOB.Read())
                    {
                        bit_data = (byte[])reader_BLOB["ReportData"];
                    }
                }
                XmlDocument doc = new XmlDocument();
                doc.InnerXml = System.Text.Encoding.UTF8.GetString(bit_data);

                IBNReportTemplate repTemplate = null;
                using (IDataReader reader = Report.GetReport(ReportId))
                {
                    if (reader.Read())
                    {
                        _header.ReportCreated = (DateTime)reader["ReportCreated"];
                        _header.ReportCreator = CommonHelper.GetUserStatusPureName((int)reader["ReportCreator"]);
                        XmlDocument temp = new XmlDocument();
                        temp.InnerXml = "<IBNReportTemplate>" + doc.SelectSingleNode("Report/IBNReportTemplate").InnerXml + "</IBNReportTemplate>";
                        repTemplate   = new IBNReportTemplate(temp);
                        _header.Title = HttpUtility.HtmlDecode(repTemplate.Name);
                    }
                }

                #region Filters

                QObject qItem = null;
                switch (repTemplate.ObjectName)
                {
                case "Incident":                                //Incident
                    qItem = new QIncident();
                    break;

                case "Project":                                 //Project
                    qItem = new QProject();
                    break;

                case "ToDo":                                    //ToDo`s
                    qItem = new QToDo();
                    break;

                case "Event":                                   //Calendar Entries
                    qItem = new QCalendarEntries();
                    break;

                case "Document":                                        //Documents
                    qItem = new QDocument();
                    break;

                case "Directory":                               //Users
                    qItem = new QDirectory();
                    break;

                case "Task":                                    //Tasks
                    qItem = new QTask();
                    break;

                case "Portfolio":                                       //Portfolios
                    qItem = new QPortfolio();
                    break;

                default:
                    break;
                }
                _header.Filter = MakeFilterText(repTemplate, qItem);
                #endregion

                _header.BtnPrintVisible = false;
                bool   ShowEmpty  = repTemplate.ShowEmptyGroup;
                int    GroupCount = repTemplate.Groups.Count;
                string ViewType   = repTemplate.ViewType;

                string sPath = "";
                if (GroupCount == 0)
                {
                    sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupWithout.xslt";
                }
                else if (GroupCount == 1 && ShowEmpty)
                {
                    if (ViewType == "0")
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupOne.xslt";
                    }
                    else
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupOneCollapse.xslt";
                    }
                }
                else if (GroupCount == 1 && !ShowEmpty)
                {
                    if (ViewType == "0")
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupOneNoEmpty.xslt";
                    }
                    else
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupOneNoEmptyCollapse.xslt";
                    }
                }
                else if (GroupCount == 2 && ShowEmpty)
                {
                    if (ViewType == "0")
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupTwo.xslt";
                    }
                    else
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupTwoCollapse.xslt";
                    }
                }
                else if (GroupCount == 2 && !ShowEmpty)
                {
                    if (ViewType == "0")
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupTwoNoEmpty.xslt";
                    }
                    else
                    {
                        sPath = HttpRuntime.AppDomainAppPath + @"Reports\GroupTwoNoEmptyCollapse.xslt";
                    }
                }
                XslCompiledTransform _transform = new XslCompiledTransform();
                XsltSettings         set        = new XsltSettings(true, true);

                _transform.Load(sPath, set, null);

                StringWriter  sw = new StringWriter();
                XmlTextWriter w  = new XmlTextWriter(sw);
                _transform.Transform(doc, w);
                w.Close();
                lblXML.Text = HttpUtility.HtmlDecode(sw.ToString());
            }

            if (Request["Export"] != null && Request["Export"] == "2")
            {
                ExportXML();
            }
            if (Request["Export"] != null && Request["Export"] == "1")
            {
                ExportExcel();
            }
            btnSave.Text              = LocRM.GetString("tSave");
            btnSaveVis.Value          = LocRM.GetString("tSaveAsTemplate");
            btnExcel.Text             = LocRM.GetString("Export");
            btnXML.Text               = LocRM.GetString("XMLExport");
            lgdSaveTemplate.InnerText = LocRM.GetString("tSaveTemplate");
            cbSaveResult.Text         = LocRM.GetString("tSaveResult");
            cbOnlyForMe.Text          = LocRM.GetString("tOnlyForMe");
        }
Exemplo n.º 11
0
 public AuthorsStorageViewModel(QDocument document)
     : base("Авторы", document.Document.Authors)
 {
 }
Exemplo n.º 12
0
 public SourcesStorageViewModel(QDocument document)
     : base("Источники", document.Document.Sources)
 {
 }
Exemplo n.º 13
0
        /// <summary>
        /// Открытие существующего файла
        /// </summary>
        /// <param name="path">Имя файла</param>
        /// <param name="fileStream">Открытый для чтения файл</param>
        internal void OpenFile(string path, string search = null, string overridePath = null, Action onSuccess = null)
        {
            var savingPath = overridePath ?? path;

            Task <QDocument> loader() => Task.Run(() =>
            {
                FileStream stream = null;
                try
                {
                    stream = File.Open(path, FileMode.Open, FileAccess.ReadWrite);

                    // Раньше было read = false
                    // Но из-за этого при каждом открытии, даже если файл не изменялся, менялась дата его изменения
                    var doc = SIDocument.Load(stream);

                    var docViewModel = new QDocument(doc, _storageContextViewModel)
                    {
                        Path     = savingPath,
                        FileName = Path.GetFileNameWithoutExtension(savingPath)
                    };

                    if (search != null)
                    {
                        docViewModel.SearchText = search;
                    }

                    if (overridePath != null)
                    {
                        docViewModel.OverridePath = overridePath;
                        docViewModel.OriginalPath = path;
                        docViewModel.Changed      = true;
                    }

                    return(docViewModel);
                }
                catch (Exception exc)
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }

                    if (exc is FileNotFoundException)
                    {
                        AppSettings.Default.History.Remove(path);
                    }

                    if (exc is UnauthorizedAccessException && (new FileInfo(path).Attributes & FileAttributes.ReadOnly) > 0)
                    {
                        throw new Exception(Resources.FileIsReadOnly);
                    }

                    throw exc;
                }
            });

            DocList.Add(new DocumentLoaderViewModel(path, loader, () =>
            {
                AppSettings.Default.History.Add(savingPath);

                onSuccess?.Invoke();
            }));
        }
Exemplo n.º 14
0
 void MainViewModel_CurrentChanged(object sender, EventArgs e)
 {
     ActiveDocument = CollectionViewSource.GetDefaultView(DocList).CurrentItem as QDocument;
 }
Exemplo n.º 15
0
        public SendToGameDialogViewModel(QDocument document)
        {
            _document = document;

            Send = new SimpleCommand(Send_Executed);
        }
 public ExportHtmlViewModel(QDocument document)
 {
     _document = document;
     Export    = new SimpleCommand(Export_Executed);
 }
Exemplo n.º 17
0
        internal static void DoDrag(FrameworkElement host, QDocument active, InfoOwner item, InfoOwnerData itemData, Action beforeDrag = null, Action afterDrag = null)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            if (active == null)
            {
                throw new ArgumentNullException(nameof(active));
            }

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (itemData == null)
            {
                throw new ArgumentNullException(nameof(itemData));
            }

            itemData.GetFullData(active.Document, item);
            var dataObject = new DataObject(itemData);

            if (host.DataContext is RoundViewModel roundViewModel)
            {
                var packageViewModel = roundViewModel.OwnerPackage;
                if (packageViewModel == null)
                {
                    throw new ArgumentException(nameof(packageViewModel));
                }

                int index = packageViewModel.Rounds.IndexOf(roundViewModel);

                active.BeginChange();

                try
                {
                    var sb = new StringBuilder();
                    using (var writer = XmlWriter.Create(sb))
                    {
                        roundViewModel.Model.WriteXml(writer);
                    }

                    dataObject.SetData("siqround", "1");
                    dataObject.SetData(DataFormats.Serializable, sb);

                    var result = DragDrop.DoDragDrop(host, dataObject, DragDropEffects.Move);
                    if (result == DragDropEffects.Move)
                    {
                        if (packageViewModel.Rounds[index] != roundViewModel)
                        {
                            index++;
                        }

                        packageViewModel.Rounds.RemoveAt(index);
                        active.CommitChange();
                    }
                    else
                    {
                        active.RollbackChange();
                    }
                }
                catch (Exception exc)
                {
                    active.RollbackChange();
                    throw exc;
                }
            }
            else
            {
                if (host.DataContext is ThemeViewModel themeViewModel)
                {
                    roundViewModel = themeViewModel.OwnerRound;
                    if (roundViewModel == null)
                    {
                        throw new ArgumentException(nameof(roundViewModel));
                    }

                    int index = roundViewModel.Themes.IndexOf(themeViewModel);

                    active.BeginChange();

                    try
                    {
                        var sb = new StringBuilder();
                        using (var writer = XmlWriter.Create(sb))
                        {
                            themeViewModel.Model.WriteXml(writer);
                        }

                        dataObject.SetData("siqtheme", "1");
                        dataObject.SetData(DataFormats.Serializable, sb);

                        var result = DragDrop.DoDragDrop(host, dataObject, DragDropEffects.Move);
                        if (result == DragDropEffects.Move)
                        {
                            if (roundViewModel.Themes[index] != themeViewModel)
                            {
                                index++;
                            }

                            roundViewModel.Themes.RemoveAt(index);
                        }

                        active.CommitChange();
                    }
                    catch (Exception exc)
                    {
                        active.RollbackChange();
                        throw exc;
                    }
                }
                else
                {
                    var questionViewModel = host.DataContext as QuestionViewModel;
                    themeViewModel = questionViewModel.OwnerTheme;
                    if (themeViewModel == null)
                    {
                        throw new ArgumentException(nameof(themeViewModel));
                    }

                    var index = themeViewModel.Questions.IndexOf(questionViewModel);
                    active.BeginChange();

                    try
                    {
                        var sb = new StringBuilder();
                        using (var writer = XmlWriter.Create(sb))
                        {
                            questionViewModel.Model.WriteXml(writer);
                        }

                        dataObject.SetData("siqquestion", "1");
                        dataObject.SetData(DataFormats.Serializable, sb);

                        beforeDrag?.Invoke();

                        DragDropEffects result;
                        try
                        {
                            result = DragDrop.DoDragDrop(host, dataObject, DragDropEffects.Move);
                        }
                        catch (InvalidOperationException)
                        {
                            result = DragDropEffects.None;
                        }
                        finally
                        {
                            host.Opacity = 1.0;

                            afterDrag?.Invoke();
                        }

                        if (result == DragDropEffects.Move)
                        {
                            if (themeViewModel.Questions[index] != questionViewModel)
                            {
                                index++;
                            }

                            themeViewModel.Questions.RemoveAt(index);

                            if (AppSettings.Default.ChangePriceOnMove)
                            {
                                RecountPrices(themeViewModel);
                            }
                        }

                        active.CommitChange();
                    }
                    catch (Exception exc)
                    {
                        active.RollbackChange();
                        throw exc;
                    }
                }
            }
        }