Esempio n. 1
0
        }                                       // 对应的数据元素名

        /*
         * <editor>
         * <field element="add1">
         * <caption lang="zh">新增字段1</caption>
         * </field>
         * <field element="add2">
         * <caption lang="zh">新增字段2</caption>
         * </field>
         * <field element="add3">
         * <caption lang="zh">新增字段3</caption>
         * </field>
         * </editor>
         * */
        // 根据 XML 构造列定义
        public static List <ColumnInfo> BuildColumnInfoList(string xml,
                                                            string lang = "zh")
        {
            List <ColumnInfo> results = new List <ColumnInfo>();

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(xml);

            int index = 0;
            var nodes = dom.DocumentElement.SelectNodes("field");

            foreach (XmlElement element in nodes)
            {
                ColumnInfo info = new ColumnInfo();
                results.Add(info);

                info.Caption     = DomUtil.GetCaption(lang, element);
                info.DataElement = element.GetAttribute("element");
                int nRet = DomUtil.GetIntegerParam(element,
                                                   "width",
                                                   100,
                                                   out int value,
                                                   out string strError);
                if (nRet == -1)
                {
                    throw new Exception($"获得 width 属性时出错: {strError}");
                }
                info.PixelWidth = value;
                info.Index      = index++;
            }

            return(results);
        }
Esempio n. 2
0
        public static int Build(XmlDocument dom,
                                out LabelParam label_param,
                                out string strError)
        {
            strError = "";
            int nRet = 0;

            label_param = new LabelParam();

            XmlNode label = dom.DocumentElement.SelectSingleNode("label");

            if (label != null)
            {
                // int nValue = 0;
                double fValue = 0;

                // width
                nRet = DomUtil.GetDoubleParam(label,
                                              "width",
                                              0,
                                              out fValue,
                                              out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                label_param.LabelWidth = fValue;

                // height
                nRet = DomUtil.GetDoubleParam(label,
                                              "height",
                                              0,
                                              out fValue,
                                              out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                label_param.LabelHeight = fValue;

                // lineSep
                nRet = DomUtil.GetDoubleParam(label,
                                              "lineSep",
                                              0,
                                              out fValue,
                                              out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                label_param.LineSep = fValue;

                {
                    DecimalPadding margins;
                    string         strPaddings = DomUtil.GetAttr(label, "paddings");
                    nRet = GetMarginValue(
                        strPaddings,
                        out margins,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "<label>元素paddings属性值格式错误: " + strError;
                        return(-1);
                    }
                    label_param.LabelPaddings = margins;
                }
#if NO
                try
                {
                    string strPaddings = DomUtil.GetAttr(label, "paddings");

                    string[] parts = strPaddings.Split(new char[] { ',' });
                    if (parts.Length > 0)
                    {
                        label_param.LabelPaddings.Left = Convert.ToInt32(parts[0]);
                    }
                    if (parts.Length > 1)
                    {
                        label_param.LabelPaddings.Top = Convert.ToInt32(parts[1]);
                    }
                    if (parts.Length > 2)
                    {
                        label_param.LabelPaddings.Right = Convert.ToInt32(parts[2]);
                    }
                    if (parts.Length > 3)
                    {
                        label_param.LabelPaddings.Bottom = Convert.ToInt32(parts[3]);
                    }
                }
                catch (Exception ex)
                {
                    strError = "<label>元素paddings属性值格式错误: " + ex.Message;
                    return(-1);
                }
#endif

                string strFont = DomUtil.GetAttr(label, "font");
                if (String.IsNullOrEmpty(strFont) == false)
                {
                    if (Global.IsVirtualBarcodeFont(ref strFont) == true)
                    {
                        label_param.IsBarcodeFont = true;
                    }

                    try
                    {
                        label_param.Font = Global.BuildFont(strFont);
                    }
                    catch (Exception ex)
                    {
                        strError = "<label>元素 font 属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }
            }


            XmlNode page = dom.DocumentElement.SelectSingleNode("page");
            if (page != null)
            {
                {
                    // int nValue = 0;
                    double fValue = 0;

                    // width
                    nRet = DomUtil.GetDoubleParam(page,
                                                  "width",
                                                  0,
                                                  out fValue,
                                                  out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    label_param.PageWidth = fValue;

                    // height
                    nRet = DomUtil.GetDoubleParam(page,
                                                  "height",
                                                  0,
                                                  out fValue,
                                                  out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    label_param.PageHeight = fValue;
                }

                {
                    DecimalPadding margins;
                    string         strMargins = DomUtil.GetAttr(page, "margins");
                    nRet = GetMarginValue(
                        strMargins,
                        out margins,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "<page>元素margins属性值格式错误: " + strError;
                        return(-1);
                    }
                    label_param.PageMargins = margins;
                }
#if NO
                try
                {
                    string   strMargins = DomUtil.GetAttr(page, "margins");
                    string[] parts      = strMargins.Split(new char[] { ',' });
                    if (parts.Length > 0)
                    {
                        label_param.PageMargins.Left = Convert.ToInt32(parts[0]);
                    }
                    if (parts.Length > 1)
                    {
                        label_param.PageMargins.Top = Convert.ToInt32(parts[1]);
                    }
                    if (parts.Length > 2)
                    {
                        label_param.PageMargins.Right = Convert.ToInt32(parts[2]);
                    }
                    if (parts.Length > 3)
                    {
                        label_param.PageMargins.Bottom = Convert.ToInt32(parts[3]);
                    }
                }
                catch (Exception ex)
                {
                    strError = "<page>元素margins属性值格式错误: " + ex.Message;
                    return(-1);
                }
#endif

                label_param.DefaultPrinter = DomUtil.GetAttr(page, "defaultPrinter");

#if NO
                bool bValue = false;
                nRet = DomUtil.GetBooleanParam(page,
                                               "landscape",
                                               false,
                                               out bValue,
                                               out strError);
                if (nRet == -1)
                {
                    strError = "<page> 元素的 landscape 属性错误: " + strError;
                    return(-1);
                }
                label_param.Landscape = bValue;
#endif
                int nValue = 0;
                DomUtil.GetIntegerParam(page,
                                        "rotate",
                                        0,
                                        out nValue,
                                        out strError);
                if (nRet == -1)
                {
                    strError = "<page> 元素的 rotate 属性错误: " + strError;
                    return(-1);
                }
                label_param.RotateDegree = nValue;
            }

            XmlNodeList nodes = dom.DocumentElement.SelectNodes("lineFormats/line");
            label_param.LineFormats = new List <LineFormat>();
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node    = nodes[i];
                string  strFont = DomUtil.GetAttr(node, "font");

                LineFormat format = new LineFormat();

                if (Global.IsVirtualBarcodeFont(ref strFont) == true)
                {
                    format.IsBarcodeFont = true;
                }

                if (string.IsNullOrEmpty(strFont) == false)
                {
                    try
                    {
                        format.Font = Global.BuildFont(strFont);
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素font属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }
                else
                {
                    format.Font = null; // 继承页面的字体
                }
                format.Align = DomUtil.GetAttr(node, "align");

                string strOffset = DomUtil.GetAttr(node, "offset");
                if (string.IsNullOrEmpty(strOffset) == false)
                {
                    try
                    {
                        double left  = 0;
                        double right = 0;
                        ParsetTwoDouble(strOffset,
                                        false,
                                        out left,
                                        out right);
                        format.OffsetX = left;
                        format.OffsetY = right;
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素offset属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }

                string strStart = DomUtil.GetAttr(node, "start");
                if (string.IsNullOrEmpty(strStart) == false)
                {
                    try
                    {
                        double left  = double.NaN;
                        double right = double.NaN;
                        ParsetTwoDouble(strStart,
                                        true,
                                        out left,
                                        out right);
                        format.StartX = left;
                        format.StartY = right;
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素start属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }

                string strSize = DomUtil.GetAttr(node, "size");
                if (string.IsNullOrEmpty(strSize) == false)
                {
                    try
                    {
                        double left  = double.NaN;
                        double right = double.NaN;
                        ParsetTwoDouble(strSize,
                                        true,
                                        out left,
                                        out right);
                        format.Width  = left;
                        format.Height = right;
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素size属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }

                format.ForeColor = DomUtil.GetAttr(node, "foreColor");
                format.BackColor = DomUtil.GetAttr(node, "backColor");

                label_param.LineFormats.Add(format);
            }

            return(0);
        }
Esempio n. 3
0
        // 为数据库属性集合中增补需要从xml文件中获得的其他属性
        int AppendDbProperties(out string strError)
        {
            strError = "";

            // 增补MaxResultCount
            if (this.CfgDom == null)
            {
                strError = "调用 GetBiblioDbProperties()以前,需要先初始化和装载CfgDom";
                return(-1);
            }

            Debug.Assert(this.CfgDom != null, "");

            for (int i = 0; i < this.BiblioDbProperties.Count; i++)
            {
                BiblioDbProperty prop = this.BiblioDbProperties[i];

                string strDbName = prop.DbName;

                XmlNode nodeDatabase = this.CfgDom.DocumentElement.SelectSingleNode("//databases/database[@name='" + strDbName + "']");
                if (nodeDatabase == null)
                {
                    continue;
                }

                // maxResultCount

                // 获得整数型的属性参数值
                // return:
                //      -1  出错。但是nValue中已经有了nDefaultValue值,可以不加警告而直接使用
                //      0   正常获得明确定义的参数值
                //      1   参数没有定义,因此代替以缺省参数值返回
                int nRet = DomUtil.GetIntegerParam(nodeDatabase,
                                                   "maxResultCount",
                                                   -1,
                                                   out prop.MaxResultCount,
                                                   out strError);
                if (nRet == -1)
                {
                    strError = "为数据库 '" + strDbName + "' 配置的<databases/database>元素的" + strError;
                    return(-1);
                }

                // alias
                prop.DbNameAlias = DomUtil.GetAttr(nodeDatabase, "alias");


                // addField901
                // 2007/12/16
                nRet = DomUtil.GetBooleanParam(nodeDatabase,
                                               "addField901",
                                               false,
                                               out prop.AddField901,
                                               out strError);
                if (nRet == -1)
                {
                    strError = "为数据库 '" + strDbName + "' 配置的<databases/database>元素的" + strError;
                    return(-1);
                }
            }

            return(0);
        }
Esempio n. 4
0
        // 装载配置文件dp2zserver.xml
        int LoadCfgDom(out string strError)
        {
            lock (this)
            {
                strError = "";
                int nRet = 0;

                string strCurrentDir = System.Reflection.Assembly.GetExecutingAssembly().Location;   //  Environment.CurrentDirectory;
                strCurrentDir = Path.GetDirectoryName(strCurrentDir);

                string strFileName = Path.Combine(strCurrentDir, "dp2zserver.xml");

                this.CfgDom = new XmlDocument();
                try
                {
                    this.CfgDom.Load(strFileName);
                }
                catch (Exception ex)
                {
                    strError = "将配置文件 '" + strFileName + "' 装载到 DOM 时出错: " + ex.Message;
                    return(-1);
                }

                // 取得网络参数
                XmlNode nodeNetwork = this.CfgDom.DocumentElement.SelectSingleNode("//network");
                if (nodeNetwork != null)
                {
                    // port

                    // 获得整数型的属性参数值
                    // return:
                    //      -1  出错。但是nValue中已经有了nDefaultValue值,可以不加警告而直接使用
                    //      0   正常获得明确定义的参数值
                    //      1   参数没有定义,因此代替以缺省参数值返回
                    nRet = DomUtil.GetIntegerParam(nodeNetwork,
                                                   "port",
                                                   210,
                                                   out this.m_port,
                                                   out strError);
                    if (nRet == -1)
                    {
                        strError = "<network>元素" + strError;
                        return(-1);
                    }

                    // maxSessions

                    // 获得整数型的属性参数值
                    // return:
                    //      -1  出错。但是nValue中已经有了nDefaultValue值,可以不加警告而直接使用
                    //      0   正常获得明确定义的参数值
                    //      1   参数没有定义,因此代替以缺省参数值返回
                    nRet = DomUtil.GetIntegerParam(nodeNetwork,
                                                   "maxSessions",
                                                   -1,
                                                   out this.m_nMaxThreads,
                                                   out strError);
                    if (nRet == -1)
                    {
                        strError = "<network>元素" + strError;
                        return(-1);
                    }
                }

                // 取出一些常用的指标

                // 1) 图书馆应用服务器URL
                // 2) 管理员用的帐户和密码
                XmlNode node = this.CfgDom.DocumentElement.SelectSingleNode("//libraryserver");
                if (node != null)
                {
                    this.LibraryServerUrl = DomUtil.GetAttr(node, "url");

                    this.ManagerUserName = DomUtil.GetAttr(node, "username");
                    string strPassword = DomUtil.GetAttr(node, "password");
                    this.ManagerPassword = DecryptPasssword(strPassword);

                    this.AnonymousUserName = DomUtil.GetAttr(node, "anonymousUserName");
                    strPassword            = DomUtil.GetAttr(node, "anonymousPassword");
                    this.AnonymousPassword = DecryptPasssword(strPassword);
                }
                else
                {
                    this.LibraryServerUrl = "";

                    this.ManagerUserName = "";
                    this.ManagerUserName = "";

                    this.AnonymousUserName = "";
                    this.AnonymousPassword = "";
                }

                // 准备通道
                this.Channel.Url = this.LibraryServerUrl;

                this.Channel.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin);
                this.Channel.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin);

                //

                XmlNode nodeDatabases = this.CfgDom.DocumentElement.SelectSingleNode("databases");
                if (nodeDatabases != null)
                {
                    // maxResultCount

                    // 获得整数型的属性参数值
                    // return:
                    //      -1  出错。但是nValue中已经有了nDefaultValue值,可以不加警告而直接使用
                    //      0   正常获得明确定义的参数值
                    //      1   参数没有定义,因此代替以缺省参数值返回
                    nRet = DomUtil.GetIntegerParam(nodeDatabases,
                                                   "maxResultCount",
                                                   -1,
                                                   out this.MaxResultCount,
                                                   out strError);
                    if (nRet == -1)
                    {
                        strError = "<databases>元素" + strError;
                        return(-1);
                    }
                }

                return(0);
            }
        }
Esempio n. 5
0
        // 根据XML定义初始化数组
        public int Initial(XmlNode nodeDef,
                           string strDirectory,
                           out string strError)
        {
            strError = "";

            this.Close();

            PathUtil.CreateDirIfNeed(strDirectory);     // 确保目录创建
            this.DataDirectory = strDirectory;

            m_lock.EnterWriteLock();
            try
            {
                this.Clear();

                // 创建一个缺省的栏目
                if (nodeDef == null)
                {
                    ChatRoom room = new ChatRoom();
                    room.Name = "default";
                    this.Add(room);

                    int nRet = room.Initial(PathUtil.MergePath(strDirectory, room.Name),
                                            out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    return(0);
                }

                int nValue = -1;
                // return:
                //      -1  出错。但是nValue中已经有了nDefaultValue值,可以不加警告而直接使用
                //      0   正常获得明确定义的参数值
                //      1   参数没有定义,因此代替以缺省参数值返回
                DomUtil.GetIntegerParam(nodeDef,
                                        "picMaxWidth",
                                        800,
                                        out nValue,
                                        out strError);
                this.PicMaxWidth = nValue;

                nValue = -1;
                // return:
                //      -1  出错。但是nValue中已经有了nDefaultValue值,可以不加警告而直接使用
                //      0   正常获得明确定义的参数值
                //      1   参数没有定义,因此代替以缺省参数值返回
                DomUtil.GetIntegerParam(nodeDef,
                                        "picMaxHeight",
                                        8000,
                                        out nValue,
                                        out strError);
                this.PicMaxHeight = nValue;

                XmlNodeList nodes = nodeDef.SelectNodes("chatRoom");
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node    = nodes[i];
                    string  strName = DomUtil.GetAttr(node, "name");
                    if (string.IsNullOrEmpty(strName) == true)
                    {
                        continue;
                    }

                    string strEditors = DomUtil.GetAttr(node, "editors");
                    string strGroups  = DomUtil.GetAttr(node, "groups");

                    ChatRoom room = null;

                    /*
                     * room = GetChatRoom(strName, false);
                     * if (room != null)
                     * {
                     *  strError = "名字为 '"+strName+"' 的栏目被重复定义了";
                     *  return -1;
                     * }
                     * */

                    room            = new ChatRoom();
                    room.Name       = strName;
                    room.EditorList = StringUtil.SplitList(strEditors);
                    room.GroupList  = StringUtil.SplitList(strGroups);
                    this.Add(room);

                    int nRet = room.Initial(PathUtil.MergePath(strDirectory, strName),
                                            out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }
                }
            }
            finally
            {
                m_lock.ExitWriteLock();
            }

            return(0);
        }