Пример #1
0
 public static void Execute(string modulesDir, IMHost host, string script, ModuleFinishedHandler callBack)
 {
     List<MCallData> lst = Parse(script);
     foreach(MCallData m in lst)
     {
         m.Execute(modulesDir, host, callBack);
     }
 }
Пример #2
0
        public void Execute(string modulesDir, IMHost host, ModuleFinishedHandler callBack)
        {
            if (modulesDir == "")
                throw new Exception("Путь к хранилищу модулей не задан!");
            MConnect connect = new MConnect(Path.Combine(modulesDir, this.ModuleName));
            IModule module = connect.GetModuleInterface(this.ModuleParams);
            module.Execute(this.Commands, host);

            callBack(module);
        }
Пример #3
0
        public FFormat(int left, int top, IPObject formatObject, string template, IMHost host, IMValueGetter overloads)
        {
            InitializeComponent();

            _left = left;
            _top = top;

            _formatObject = formatObject;
            _template = template;
            _host = host;
            _overloads = overloads;

            backgroundWorkerFormat.WorkerSupportsCancellation = true;
        }
Пример #4
0
        public bool Execute(string commands, IMHost host)
        {
            try
            {
                if (_printer != null)
                {
                    string[] aCommands = commands.Split('\n');
                    foreach (string line in aCommands)
                    {
                        string cmdLine = line.Trim();
                        if (cmdLine == string.Empty)
                            continue;
                        MCustomizedPrinterCommand cmd = new MCustomizedPrinterCommand(cmdLine);
                        if (cmd.Code != null)
                        {
                            string expr = cmd.GetParamStr("hideif", "");
                            if (expr != "")
                            {
                                string[] parts = expr.Split('=');
                                if (parts.Count() == 2)
                                {
                                    if (parts[0].Trim() == parts[1].Trim())
                                        continue;
                                }
                            }
                            switch (cmd.Code.ToUpper())
                            {
                                case "LBL":
                                    string lblText = cmd.GetParamStr("text");
                                    if (lblText != "")
                                    {
                                        try
                                        {
                                            _printer.WriteText(
                                                new System.Drawing.RectangleF(
                                                    cmd.GetParamPercent("x")
                                                    , cmd.GetParamPercent("y")
                                                    , cmd.GetParamPercent("width", 100)
                                                    , cmd.GetParamPercent("height", 100)
                                                    )
                                                , cmd.GetParamAlign("halign", -1)
                                                , cmd.GetParamAlign("valign", -1)
                                                , lblText
                                                , cmd.GetParamLimited("angle", -360, 360, 0)
                                            );
                                        }
                                        catch (Exception ex)
                                        {
                                            throw new Exception(ex.Message + "\nПараметры LBL: x(%), y(%), width(%), height(%), halign(int<-1..1>), valign(int<-1..1>), text(string), angle(float<-360.0..360.0>)", ex);
                                        }
                                    }
                                    break;

                                case "FNT":
                                    try
                                    {
                                        _printer.SetFont(cmd.GetParamStr("name"), cmd.GetParamFloatPositive("size"));
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception(ex.Message + "\nПараметры FNT: name(string), size(float)", ex);
                                    }
                                    break;

                                case "PAGE":
                                    try
                                    {
                                        Fields fields = cmd.GetParamFields("fields", "0");
                                        _printer.NewPage(cmd.GetParamIntPositive("width"),
                                            cmd.GetParamIntPositive("height"),
                                            fields.left,
                                            fields.top,
                                            fields.right,
                                            fields.bottom,
                                            cmd.GetParamFloat("originy", 0.0F));
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception(ex.Message + "\nПараметры PAGE: width(int, мм), height(int, мм), fields(intList, мм)");
                                    }
                                    break;

                                case "BAR":
                                    try
                                    {
                                        string barText = cmd.GetParamStr("text");
                                        if (barText != "")
                                        {
                                            _printer.WriteBarcode(
                                                new System.Drawing.PointF(
                                                    cmd.GetParamPercent("x")
                                                    , cmd.GetParamPercent("y")
                                                )
                                                , cmd.GetParamPercent("height")
                                                , cmd.GetParamAlign("halign", -1)
                                                , cmd.GetParamAlign("valign", -1)
                                                , barText
                                            );
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception(ex.Message + "\nПараметры BAR: text, x, y, height, halign, valign");
                                    }
                                    break;

                                default:
                                    throw new Exception("Неизвестный параметр " + cmd.Code);
                            }
                        }
                    }

                    _printer.Print();

                    return true;
                }
                else
                {
                    throw new Exception("Принтер не назначен!");
                }
            }
            catch (Exception e)
            {
                AddProblem(e.Message);

                return false;
            }
        }
Пример #5
0
        public static string FormatObject(IPObject obj, string template, IMHost host, IMValueGetter overloads, BackgroundWorker worker, PNavigationInfo navInfo)
        {
            List<PTemplateAttr> attrs;
            List<PTemplateCollection> fcollects;

            _parse(template, out attrs, out fcollects);

            template = template.Replace("%id%", obj.Id.ToString());
            foreach (var attr in attrs)
            {
                string val = "";
                string moduleName = attr.Module.Trim().ToLower();
                string attrName = attr.Name;

                bool valFound = false;

                if (moduleName == "")
                {
                    if (overloads != null)
                        valFound = overloads.QueryValue(attrName, false, out val);
                    if (!valFound)
                        valFound = obj.GetAttr(attr.Name, true, out val);
                }
                else if (moduleName == "host")
                {
                    if (host != null)
                        valFound = host.QueryValue(attr.Name, false, out val);
                }
                else
                {
                    valFound = _queryToModule(moduleName, attrName, out val);
                }
                if (!valFound)
                    val = "<" + attr.ToString() + ">";

                template = template.Replace(attr.OperatorText, val);
            }

            foreach (var fcollect in fcollects)
            {
                IPCollection coll = obj.GetCollection(fcollect.collectionName);
                if (coll != null)
                {
                    string val = "";
                    int cnt = coll.Count;
                    for (int i = 0; i < cnt; i++)
                    {
                        IPObject cobj = coll.GetObject(i);

                        string tmp = "";
                        if (cobj.GetAttr(fcollect.templateName, true, out tmp))
                        {
                            if (worker != null && worker.CancellationPending)
                                return "";

                            bool navAdded = false;
                            if (fcollect.navigatorLevelCaption != "")
                            {
                                if (navInfo != null)
                                {
                                    navInfo.captions.Add(fcollect.navigatorLevelCaption);
                                    navInfo.levels.Add(fcollect.collectionName);
                                    navAdded = true;
                                }
                            }
                            val += FormatObject(cobj, tmp, host, overloads, worker, navInfo);

                            // теперь, если уровень навигации добавлялся - нужно сбросить переменную, чтоб в этом цикле не добавить соседние подходящие коллекции
                            if (navAdded)
                                navInfo = null;
                        }
                        else
                            val += "<!" + fcollect.templateName + "!>";
                        val += (fcollect.endsWithNewLine ? "\n" : "");
                    }
                    template = template.Replace(fcollect.OperatorText, val);
                }
            } // ToDo: может надо else что-нибудь вывести? Коллекция не найдена

            return template;
        }