예제 #1
0
        private static void AnswerSendMessage(Form handle, string sendString)
        {
#if (DEBUG)
            Console.WriteLine("{0}: Handle for answer window: {1} String: {2}", DateTime.Now.ToString("HH:mm:ss fff"), handle, sendString);
#endif
            if (SendAnswerMessageClass.ContainsKey(handle.Handle))
            {
                int    processID    = 0;
                IntPtr externHandle = SendAnswerMessageClass.Value(handle.Handle);
                SendAnswerMessageClass.Remove(handle.Handle);
#if (DEBUG)
                Console.WriteLine("{0}: Handle of answer window: {1}", DateTime.Now.ToString("HH:mm:ss fff"), externHandle);
#endif
                Lib.Win.Document.Win32.User32.GetWindowThreadProcessId(externHandle, ref processID);
                Lib.Win.Document.Win32.User32.AllowSetForegroundWindow(processID);
                Lib.Win.Document.Win32.User32.SetForegroundWindow(externHandle);

                SendMessage(externHandle, sendString);
            }
            else if (SendAnswerMessageClass.Contains(handle))
            {
                Common.SendAnswerParams sap = SendAnswerMessageClass.Value(handle);
                SendAnswerMessageClass.Remove(handle);
                SendAnswerMessageClass.PostAnswer(sap, sendString);
            }
        }
예제 #2
0
        private static void RestartSearch(Form handle, string xml)
        {
            var searchDialog = new XmlSearchForm(xml);

            if (SendAnswerMessageClass.ContainsKey(handle.Handle))
            {
                SendAnswerMessageClass.Add(SendAnswerMessageClass.Value(handle.Handle), searchDialog.Handle);
            }
            else
            {
                SendAnswerMessageClass.Value(handle).Form = searchDialog;
            }
            searchDialog.DialogEvent += optionsDialog_DialogEvent;
            searchDialog.Show();
        }
예제 #3
0
        private static void selectDocUniversalDialog_DialogEvent(object source, Kesco.Lib.Win.DialogEventArgs e)
        {
            var dialog = e.Dialog as Lib.Win.Document.Select.SelectDocUniversalDialog;

            if (dialog == null || dialog.Disposing || dialog.IsDisposed)
            {
                return;
            }

            switch (dialog.DialogResult)
            {
            case DialogResult.OK:
                AnswerSendMessage(dialog, dialog.DocID.ToString());
                break;

            case DialogResult.Retry:
            {
                var searchDialog = new XmlSearchForm(dialog.XML);
                if (SendAnswerMessageClass.ContainsKey(dialog.Handle))
                {
                    SendAnswerMessageClass.Add(SendAnswerMessageClass.Value(dialog.Handle), searchDialog.Handle);
                }
                else
                {
                    SendAnswerMessageClass.Value(dialog).Form = searchDialog;
                }
                searchDialog.DialogEvent += optionsDialog_DialogEvent;
                searchDialog.Show();
            }
            break;

            default:
                AnswerSendMessage(dialog, "0");
                break;
            }

            SendAnswerMessageClass.Remove(dialog.Handle);
        }
예제 #4
0
        private static void SearchTest(Form handle, string xml)
        {
            try
            {
                int count = Environment.DocData.FoundDocsCount();
                if (count > 0 && count < MainFormDialog.maxSearchResults)
                {
                    var dialog = new Lib.Win.Document.Select.SelectDocUniversalDialog(Environment.DocData.GetFoundDocsIDQuery(Environment.CurEmp.ID), xml);
                    dialog.DialogEvent += selectDocUniversalDialog_DialogEvent;
                    if (SendAnswerMessageClass.ContainsKey(handle.Handle))
                    {
                        SendAnswerMessageClass.Add(SendAnswerMessageClass.Value(handle.Handle), dialog.Handle);
                    }
                    else
                    {
                        SendAnswerMessageClass.Value(handle).Form = dialog;
                    }
                    dialog.Show();
                }
                else
                {
                    if (count >= MainFormDialog.maxSearchResults)
                    {
                        if (MessageBox.Show(
                                Environment.StringResources.GetString("HideForm.SearchTest.Message1") +
                                MainFormDialog.maxSearchResults.ToString() + System.Environment.NewLine +
                                Environment.StringResources.GetString("HideForm.SearchTest.Message2") +
                                System.Environment.NewLine + System.Environment.NewLine +
                                Environment.StringResources.GetString("Search.NotFound.Message2"),
                                Environment.StringResources.GetString("Warning"), MessageBoxButtons.YesNoCancel,
                                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            RestartSearch(handle, xml);
                        }
                        else
                        {
                            AnswerSendMessage(handle, "0");
                        }
                    }
                    else if (MessageBox.Show(Environment.StringResources.GetString("Search.NotFound.Message1")
                                             + System.Environment.NewLine + System.Environment.NewLine +
                                             Environment.StringResources.GetString("Search.NotFound.Message2"),
                                             Environment.StringResources.GetString("Search.NotFound.Title"),
                                             MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
                                             MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        RestartSearch(handle, xml);
                    }
                    else
                    {
                        AnswerSendMessage(handle, "0");
                    }
                }

                SendAnswerMessageClass.Remove(handle.Handle);
            }
            catch (Exception ex)
            {
                Lib.Win.Data.Env.WriteToLog(ex);
            }
        }
예제 #5
0
        public static void AnalyzeArgs(string args)
        {
            if (Program.MainFormDialog == null || Program.MainFormDialog.Disposing || Program.MainFormDialog.IsDisposed)
            {
                return;
            }
            try
            {
                bool getFromTray = Program.MainFormDialog != null && !MainFormDialog.toTray;
                args = args.Trim();
                if (args.Length == 0)
                {
                    if (getFromTray)
                    {
                        getFromTray = false;
                        Program.MainFormDialog.GetFromTray();
                    }
                }
                if (args.IndexOf("<") != 0)
                {
                    if (getFromTray)
                    {
                        getFromTray = false;
                        Program.MainFormDialog.GetFromTray();
                    }
                    string startString = args;
                    if (args.IndexOf("<") > 0)
                    {
                        startString = args.Substring(0, args.IndexOf("<"));
                        args        = args.Remove(0, args.Trim().IndexOf("<")).Trim();
                    }
                    if (Program.MainFormDialog != null && startString.Length > 0 && !MainFormDialog.toTray)
                    {
                        string fileName = Kesco.Lib.Win.Document.TextProcessor.ReplaceKesco(startString).TrimStart('\"').TrimEnd('\"');
                        if (File.Exists(fileName) || Directory.Exists(fileName))
                        {
                            if (Environment.General != null)
                            {
                                Environment.General.LoadOption <int>("Page", 0).Value = 0;
                            }
                            MainFormDialog.returnID       = 0;
                            MainFormDialog.returnFileName = fileName;
                            Environment.CmdManager.Commands["Return"].Execute();
                        }
                    }
                }
                if (args.IndexOf("<") == 0)
                {
                    var doc = new XmlDocument();
                    try
                    {
                        doc.LoadXml("<root>" + args.Replace("\\\"", "\"").Replace("\"\"\"", "&quot;") + "</root>");
                    }
                    catch
                    {
                        Lib.Win.Data.Env.WriteToLog("Bad xml\n" + args);
                        return;
                    }
                    for (int i = 0; i < doc.ChildNodes[0].ChildNodes.Count; i++)
                    {
                        XmlNode node = doc.ChildNodes[0].ChildNodes[i];

                        switch (node.Name.ToLower())
                        {
                        case "tray":
                            MainFormDialog.toTray = true;
                            break;

                        case "test":
                            break;

                        case "exit":
                            if (Program.MainFormDialog != null)
                            {
                                Environment.CmdManager.Commands["Exit"].Execute();
                            }
                            else
                            {
                                Application.Exit();
                            }
                            break;

                        //-- поиск подобных
                        case "checksimilar":
                            IntPtr wHandle     = IntPtr.Zero;
                            var    control     = "";
                            var    callbackKey = "";
                            var    callbackUrl = "";
                            if (node.Attributes["wndHandle"] != null &&
                                node.Attributes["wndHandle"].Value.Length > 0)
                            {
                                int h = 0;
                                if (int.TryParse(node.Attributes["wndHandle"].Value, out h) && h > 0)
                                {
                                    wHandle = new IntPtr(h);
                                }
                            }
                            else if (node.Attributes["callbackKey"] != null && !string.IsNullOrEmpty(node.Attributes["callbackKey"].Value))
                            {
                                control     = node.Attributes["control"].InnerText;
                                callbackKey = node.Attributes["callbackKey"].InnerText;
                                callbackUrl = node.Attributes["callbackUrl"].InnerText;
                            }
                            else
                            {
                                return;
                            }
                            int      typeID    = 0;
                            string   numberStr = "";
                            DateTime docDate   = DateTime.MinValue;
                            int      docID     = 0;

                            if (node.Attributes["type"] == null || !int.TryParse(node.Attributes["type"].Value, out typeID) || typeID < 1)
                            {
                                Console.WriteLine("{0}: {1}", DateTime.Now.ToString("HH:mm:ss fff"), (node.Attributes["type"] == null ? "type is null" : (" type bad : " + node.Attributes["type"].Value)));
                                if (wHandle != IntPtr.Zero)
                                {
                                    SendMessage(wHandle, "-1");
                                }
                                else if (!string.IsNullOrEmpty(callbackKey))
                                {
                                    SendAnswerMessageClass.PostAnswer(new Common.SendAnswerParams(control, callbackKey, callbackUrl, node.Name.ToLower()), "-1");
                                }
                                return;
                            }

                            if (node.Attributes["number"] != null && node.Attributes["number"].Value.Length > 0)
                            {
                                numberStr = node.Attributes["number"].Value;
                            }

                            if (node.Attributes["date"] != null)
                            {
                                if (!DateTime.TryParseExact(node.Attributes["date"].Value, "dd.MM.yyyy", null, DateTimeStyles.None, out docDate))
                                {
                                    Console.WriteLine("{0}: date bad: {1}", DateTime.Now.ToString("HH:mm:ss fff"), node.Attributes["date"].Value);
                                    if (wHandle != IntPtr.Zero)
                                    {
                                        SendMessage(wHandle, "-1");
                                    }
                                    else if (!string.IsNullOrEmpty(callbackKey))
                                    {
                                        SendAnswerMessageClass.PostAnswer(new Common.SendAnswerParams(control, callbackKey, callbackUrl, node.Name.ToLower()), "-1");
                                    }
                                    return;
                                }
                            }

                            if (node.Attributes["id"] == null || !int.TryParse(node.Attributes["id"].Value, out docID) || docID < 0)
                            {
                                Console.WriteLine("{0}: {1}", DateTime.Now.ToString("HH:mm:ss fff"), (node.Attributes["id"] == null ? "id null" : (" id bad: " + node.Attributes["id"].Value)));
                                if (wHandle != IntPtr.Zero)
                                {
                                    SendMessage(wHandle, "-1");
                                }
                                else if (!string.IsNullOrEmpty(callbackKey))
                                {
                                    SendAnswerMessageClass.PostAnswer(new Common.SendAnswerParams(control, callbackKey, callbackUrl, node.Name.ToLower()), "-1");
                                }
                                return;
                            }

                            string typeStr = "";
                            try
                            {
                                typeStr = Environment.DocTypeData.GetDocType(typeID, Environment.CurCultureInfo.TwoLetterISOLanguageName);
                            }
                            catch
                            {
                                Console.WriteLine("{0}: typeStr bad", DateTime.Now.ToString("HH:mm:ss fff"));
                                if (wHandle != IntPtr.Zero)
                                {
                                    SendMessage(wHandle, "-1");
                                }
                                else if (!string.IsNullOrEmpty(callbackKey))
                                {
                                    SendAnswerMessageClass.PostAnswer(new Common.SendAnswerParams(control, callbackKey, callbackUrl, node.Name.ToLower()), "-1");
                                }
                                return;
                            }

                            string personIDs = "";
                            if (node.Attributes["personids"] != null)
                            {
                                personIDs = node.Attributes["personids"].Value;
                            }
                            byte ѕоискѕоЋицам = 0;
                            if (node.Attributes["usepersonids"] != null)
                            {
                                ѕоискѕоЋицам = Convert.ToByte(node.Attributes["usepersonids"].Value);
                            }
                            bool returnEform = false;
                            if (node.Attributes["return"] != null)
                            {
                                returnEform = node.Attributes["return"].Value.Equals("1");
                            }
                            //-- запрос к базе

                            var selDocDialog = new Lib.Win.Document.Select.SelectDocDialog(typeID, typeStr, numberStr, docDate, personIDs, docID, false)
                            {
                                SearchType = ѕоискѕоЋицам, ReturnEform = returnEform
                            };
                            selDocDialog.DialogEvent += selDocDialog_DialogEvent;
                            selDocDialog.Show();
                            if (wHandle != IntPtr.Zero)
                            {
                                SendAnswerMessageClass.Add(wHandle, selDocDialog.Handle);
                            }
                            else if (!string.IsNullOrEmpty(callbackKey))
                            {
                                SendAnswerMessageClass.Add(control, callbackKey, callbackUrl, node.Name.ToLower(), selDocDialog);
                            }
                            selDocDialog.BringToFront();
                            selDocDialog.Activate();
                            break;

                        case "opendoc":
                            int  id    = 0;
                            int  imgID = -2;
                            bool force = false;
                            if (node.Attributes["id"] != null)
                            {
                                if (!int.TryParse(node.Attributes["id"].Value, out id))
                                {
                                    id = 0;
                                }
                            }
                            if (id > 0)
                            {
                                if (!Environment.DocData.IsDocAvailable(id))
                                {
                                    Kesco.Lib.Win.Error.ErrorShower.OnShowError(null,
                                                                                Environment.StringResources.GetString("Document") +
                                                                                Environment.StringResources.GetString("Num") + id.ToString() + " " +
                                                                                Environment.StringResources.GetString("NotAvailable"),
                                                                                Environment.StringResources.GetString("Warning"));
                                    break;
                                }
                                if (Program.MainFormDialog != null)
                                {
                                    if (Program.MainFormDialog.docControl.DocumentID == id)
                                    {
                                        Environment.RefreshDocs();
                                        Program.MainFormDialog.docControl.RefreshDoc();
                                    }
                                }
                                if (node.Attributes["imageid"] != null)
                                {
                                    if (!int.TryParse(node.Attributes["imageid"].Value, out imgID) || imgID < -2)
                                    {
                                        imgID = -2;
                                    }
                                }
                                if (node.Attributes["replicate"] != null)
                                {
                                    bool.TryParse(node.Attributes["replicate"].Value, out force);
                                }
                                if (node.Attributes["newwindow"] != null)
                                {
                                    if (node.Attributes["newwindow"].Value == "0")
                                    {
                                        if (getFromTray)
                                        {
                                            getFromTray = false;
                                            Program.MainFormDialog.GetFromTray();
                                        }
                                        if (Program.MainFormDialog != null)
                                        {
                                            MainFormDialog.returnID      = id;
                                            MainFormDialog.returnForce   = force;
                                            MainFormDialog.returnContext = null;
                                            Environment.CmdManager.Commands["Return"].Execute();
                                            break;
                                        }
                                    }
                                    else if (node.Attributes["newwindow"].Value == "1")
                                    {
                                        if (!Environment.OpenDocsContains(id) && Program.MainFormDialog != null &&
                                            MainFormDialog.curDocID == id)
                                        {
                                            Program.MainFormDialog.GetFromTray();
                                            Program.MainFormDialog.docControl.ImageID       = imgID;
                                            Program.MainFormDialog.docControl.ForceRelicate = force;
                                            break;
                                        }
                                    }
                                }
                                string zoom    = string.IsNullOrEmpty(Environment.ZoomString) ? "100%" : Environment.ZoomString;
                                bool   needInv = false;
                                if (Program.MainFormDialog != null)
                                {
                                    if (Program.MainFormDialog.docControl.ImageDisplayed &&
                                        !string.IsNullOrEmpty(Program.MainFormDialog.zoom))
                                    {
                                        zoom = Program.MainFormDialog.zoom;
                                    }
                                    needInv = Program.MainFormDialog.InvokeRequired;
                                }
                                if (!needInv)
                                {
                                    Environment.NewWindow(id, zoom, new Context(Misc.ContextMode.Catalog), imgID, 1, null, false, true);
                                }
                            }
                            else
                            {
                                if (node.Attributes["cmd"] != null)
                                {
                                    switch (node.Attributes["cmd"].Value.ToLower())
                                    {
                                    case "print":
                                        if (node.Attributes["ids"] != null)
                                        {
                                            PrintDocuments(Kesco.Lib.Win.Data.Business.V2.Entity.Str2Collection(node.Attributes["ids"].Value));
                                        }
                                        break;
                                    }
                                }
                            }
                            break;

                        case "path":
                            if (getFromTray)
                            {
                                getFromTray = false;
                                Program.MainFormDialog.GetFromTray();
                            }
                            if (Program.MainFormDialog != null)
                            {
                                if (node.Attributes["open"] != null)
                                {
                                    string path = node.Attributes["open"].Value.ToUpper();
                                    Program.MainFormDialog.folders.SelectCatalogNode(path, 0);
                                }
                            }
                            break;

                        case "search":
                            string xmlString =
                                Lib.Win.Data.DALC.Documents.Search.Options.GetXMLFromSearchElement((XmlElement)node);
                            var optionsDialog = new XmlSearchForm(xmlString)
                            {
                                StartPosition = FormStartPosition.CenterScreen
                            };
                            if (node.Attributes["wndHandle"] != null &&
                                !string.IsNullOrEmpty(node.Attributes["wndHandle"].Value))
                            {
                                int h = 0;
                                if (int.TryParse(node.Attributes["wndHandle"].Value, out h) && h > 0)
                                {
                                    SendAnswerMessageClass.Add(new IntPtr(h), optionsDialog.Handle);
                                    optionsDialog.DialogEvent += optionsDialog_DialogEvent;
                                }
                            }
                            else if (node.Attributes["callbackKey"] != null && !string.IsNullOrEmpty(node.Attributes["callbackKey"].Value))
                            {
                                control     = "";
                                callbackKey = "";
                                callbackUrl = "";
                                control     = node.Attributes["control"].InnerText;
                                callbackKey = node.Attributes["callbackKey"].InnerText;
                                callbackUrl = node.Attributes["callbackUrl"].InnerText;
                                if (string.IsNullOrEmpty(control) || string.IsNullOrEmpty(callbackUrl))
                                {
                                    break;
                                }
                                SendAnswerMessageClass.Add(control, callbackKey, callbackUrl, node.Name.ToLower(), optionsDialog);
                                optionsDialog.DialogEvent += optionsDialog_DialogEvent;
                            }
                            else
                            if (Program.MainFormDialog != null)
                            {
                                optionsDialog.DialogEvent += Program.MainFormDialog.SearchDialog_DialogEvent;
                            }
                            optionsDialog.Show();
                            optionsDialog.BringToFront();
                            optionsDialog.Activate();

                            break;

                        case "sendmessage":
                            if (node.Attributes["id"] != null &&
                                !string.IsNullOrEmpty(node.Attributes["id"].Value))
                            {
                                Console.WriteLine("{0}: {1}", DateTime.Now.ToString("HH:mm:ss fff"), node.InnerText);
                                docID = 0;
                                if (int.TryParse(node.Attributes["id"].Value, out docID) && docID > 0)
                                {
                                    if (!Environment.DocData.IsDocAvailable(docID))
                                    {
                                        Kesco.Lib.Win.Error.ErrorShower.OnShowError(null,
                                                                                    Environment.StringResources.GetString("Document") +
                                                                                    Environment.StringResources.GetString("Num") + docID.ToString() + " " +
                                                                                    Environment.StringResources.GetString("NotAvailable"),
                                                                                    Environment.StringResources.GetString("Warning"));
                                        break;
                                    }

                                    if (node.Attributes["opendoc"] != null && !string.IsNullOrEmpty(node.Attributes["opendoc"].Value))
                                    {
                                        bool open = false;
                                        if (bool.TryParse(node.Attributes["opendoc"].Value, out open)? open : "1".Equals(node.Attributes["opendoc"].Value))
                                        {
                                            if (!Environment.OpenDocsContains(docID))
                                            {
                                                string zoom    = string.IsNullOrEmpty(Environment.ZoomString) ? "100%" : Environment.ZoomString;
                                                bool   needInv = false;
                                                if (Program.MainFormDialog != null)
                                                {
                                                    if (Program.MainFormDialog.docControl.ImageDisplayed &&
                                                        !string.IsNullOrEmpty(Program.MainFormDialog.zoom))
                                                    {
                                                        zoom = Program.MainFormDialog.zoom;
                                                    }
                                                    needInv = Program.MainFormDialog.InvokeRequired;
                                                }
                                                if (!needInv)
                                                {
                                                    Environment.NewWindow(docID, zoom, new Context(Misc.ContextMode.Catalog), 0, 1, null, false, true);
                                                }
                                            }
                                        }
                                    }
                                    string messstr = "";
                                    if (node.Attributes["message"] != null)
                                    {
                                        messstr = node.Attributes["message"].Value ?? string.Empty;
                                    }

                                    string empIDsStr = "";
                                    if (node.Attributes["empids"] != null)
                                    {
                                        empIDsStr = node.Attributes["empids"].Value ?? string.Empty;
                                    }
                                    List <int> empIDs = new List <int>();
                                    if (empIDsStr.Length > 0 && Regex.IsMatch(empIDsStr, "^\\d[\\d,]+$"))
                                    {
                                        string[] empIDStrs = empIDsStr.Split(",".ToCharArray());
                                        if (empIDStrs.Length > 0)
                                        {
                                            empIDs.AddRange(empIDStrs.Select(int.Parse));
                                        }
                                    }
                                    var messageDialog = new Lib.Win.Document.Dialogs.SendMessageDialog(docID, messstr);

                                    if (node.Attributes["checkall"] != null &&
                                        node.Attributes["checkall"].Value == "1")
                                    {
                                        messageDialog.Check = true;
                                    }

                                    if (Program.MainFormDialog != null)
                                    {
                                        if (MainFormDialog.curDocID == docID)
                                        {
                                            if (Program.MainFormDialog.docGrid.IsSingle &&
                                                Program.MainFormDialog.IsNotRead())
                                            {
                                                Environment.CmdManager.Commands["MarkReadMessages"].Execute();
                                            }
                                            if (Program.MainFormDialog.docGrid.IsWorkFolder())
                                            {
                                                messageDialog.EmpID    = Program.MainFormDialog.curEmpID;
                                                messageDialog.FolderID = Program.MainFormDialog.curContext.ID;
                                            }
                                        }
                                        foreach (var dial in Environment.OpenDocs.Where(t => t.Key == docID).Select(t => t.Value as SubFormDialog).Where(dial => dial.docControl.ImageID == 0))
                                        {
                                            dial.docControl.RefreshEForm(true);
                                        }
                                    }

                                    messageDialog.Show();
                                    if (empIDs.Count > 0)
                                    {
                                        messageDialog.AddUsers(empIDs);
                                    }
                                    messageDialog.BringToFront();
                                    messageDialog.Activate();
                                }
                            }
                            break;

                        case "console":
                            if (node.Attributes["stop"] != null)
                            {
                                GuiConsole.ReleaseConsole();
                            }
                            else
                            {
                                GuiConsole.CreateConsole();
                                Console.WriteLine("{0}: {1}", DateTime.Now.ToString("HH:mm:ss fff"), args);
                            }
                            break;

                        case "senddocs":
                            if (node.Attributes["ids"] != null)
                            {
                                int    filesize = 0;
                                string email    = "";
                                if (node.Attributes["filesize"] != null)
                                {
                                    if (!int.TryParse(node.Attributes["filesize"].Value, out filesize) &&
                                        filesize < 1)
                                    {
                                        filesize = 0;
                                    }
                                }
                                if (node.Attributes["email"] != null)
                                {
                                    email = node.Attributes["email"].Value;
                                }
                            }
                            break;

                        case "printdocs":
                            if (node.Attributes["ids"] != null)
                            {
                                PrintDocuments(Kesco.Lib.Win.Data.Business.V2.Entity.Str2Collection(node.Attributes["ids"].Value));
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Lib.Win.Data.Env.WriteToLog(ex);
            }
        }