示例#1
0
文件: UtilityForm.cs 项目: gvhung/dp2
        private void comboBox_xmlFile_encoding_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strEncoding = this.comboBox_xmlFile_encoding.Text;

            string      strError = "";
            XmlDocument dom      = new XmlDocument();

            try
            {
                dom.LoadXml(this.textBox_xmlEditor_content.Text);
            }
            catch (Exception ex)
            {
                strError = "XML格式不合法: " + ex.Message;
                goto ERROR1;
            }

            if (DomUtil.GetDomEncodingString(dom) != this.comboBox_xmlFile_encoding.Text)
            {
                bool bRet = DomUtil.SetDomEncodingString(dom, this.comboBox_xmlFile_encoding.Text);
                if (bRet == true)
                {
                    this.textBox_xmlEditor_content.Text = DomUtil.GetIndentXml(dom);
                }
            }

            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
示例#2
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (String.IsNullOrEmpty(this.textBox_xml.Text.Trim()) == true)
            {
                strError = "XML代码不能为空";
                goto ERROR1;
            }

            // 校验看看XML是否正确
            string strOutXml = "";
            int    nRet      = DomUtil.GetIndentXml(this.textBox_xml.Text,
                                                    out strOutXml,
                                                    out strError);

            if (nRet == -1)
            {
                goto ERROR1;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
示例#3
0
        private void textBox_cardFile_cardFilename_TextChanged(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.textBox_cardFile_cardFilename.Text) == true)
            {
                this.textBox_cardFile_cardFilename.Text = "";
                return;
            }

            string strError   = "";
            string strContent = "";
            // 能自动识别文件内容的编码方式的读入文本文件内容模块
            // return:
            //      -1  出错
            //      0   文件不存在
            //      1   文件存在
            //      2   读入的内容不是全部
            int nRet = Global.ReadTextFileContent(this.textBox_cardFile_cardFilename.Text,
                                                  100 * 1024, // 100K
                                                  out strContent,
                                                  out strError);

            if (nRet == 1 || nRet == 2)
            {
                bool   bExceed = nRet == 2;
                string strXml  = "";
                if (this.checkBox_cardFile_indent.Checked == true)
                {
                    nRet = DomUtil.GetIndentXml(strContent,
                                                out strXml,
                                                out strError);
                    if (nRet == -1)
                    {
                        if (bExceed == false)
                        {
                            MessageBox.Show(this, strError);
                        }
                        strXml = strContent;
                    }
                }
                else
                {
                    strXml = strContent;
                }

                this.textBox_cardFile_content.Text =
                    (bExceed == true ? "文件尺寸太大,下面只显示了开头部分...\r\n" : "") + strXml;
            }
            else
            {
                this.textBox_cardFile_content.Text = "";
            }
        }
示例#4
0
        private void toolStripButton_formatXml_Click(object sender, EventArgs e)
        {
            string strOutXml = "";
            string strError  = "";
            int    nRet      = DomUtil.GetIndentXml(this.textBox_content.Text, out strOutXml, out strError);

            if (nRet == -1)
            {
                MessageBox.Show(strError);
            }
            else
            {
                this.textBox_content.Text = strOutXml;
            }
        }
示例#5
0
        public static string GetIndentXml(string strXml)
        {
            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strXml);
            }
            catch // (Exception ex)
            {
                return(strXml);
            }

            return(DomUtil.GetIndentXml(dom.DocumentElement));
        }
示例#6
0
        private void toolStripButton_indentXmlText_Click(object sender, EventArgs e)
        {
            if (this.toolStripButton_indentXmlText.Checked == true)
            {
                string strError  = "";
                string strOutXml = "";
                int    nRet      = DomUtil.GetIndentXml(this.textBox_xml.Text,
                                                        out strOutXml,
                                                        out strError);
                if (nRet == -1)
                {
                    MessageBox.Show(this, strError);
                    return;
                }

                this.textBox_xml.Text = strOutXml;
            }
        }
示例#7
0
文件: UtilityForm.cs 项目: gvhung/dp2
        private void checkBox_xmlEditor_indent_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBox_xmlEditor_indent.Checked == true)
            {
                string strError = "";
                string strXml   = "";
                int    nRet     = DomUtil.GetIndentXml(this.textBox_xmlEditor_content.Text,
                                                       true,
                                                       out strXml,
                                                       out strError);
                if (nRet == -1)
                {
                    MessageBox.Show(this, strError);
                    return;
                }

                this.textBox_xmlEditor_content.Text = strXml;
            }
        }
示例#8
0
文件: ChatRoom.cs 项目: gvhung/dp2
        // 获得栏目的XML定义
        public int GetDef(
            out string strXml,
            out string strError)
        {
            strXml   = "";
            strError = "";

            XmlDocument dom = new XmlDocument();

            dom.LoadXml("<chatRoomDef />");

            m_lock.EnterReadLock();
            try
            {
                foreach (ChatRoom room in this)
                {
                    XmlNode node = dom.CreateElement("chatRoom");
                    dom.DocumentElement.AppendChild(node);
                    DomUtil.SetAttr(node, "name", room.Name);
                    DomUtil.SetAttr(node, "editors", StringUtil.MakePathList(room.EditorList));
                    DomUtil.SetAttr(node, "groups", StringUtil.MakePathList(room.GroupList));
                }

                DomUtil.SetAttr(dom.DocumentElement, "picMaxWidth", this.PicMaxWidth.ToString());
                DomUtil.SetAttr(dom.DocumentElement, "picMaxHeight", this.PicMaxHeight.ToString());
            }
            finally
            {
                m_lock.ExitReadLock();
            }

            // strXml = dom.DocumentElement.OuterXml;
            strXml = DomUtil.GetIndentXml(dom.DocumentElement);

            return(0);
        }
示例#9
0
        // 同步读者权限XML定义和读者/图书类型编辑界面
        int SynchronizeRightsTableAndTypes()
        {
            string strError = "";

            if (this.m_nRightsTableXmlVersion == this.m_nRightsTableTypesVersion)
            {
                return(0);
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(this.textBox_loanPolicy_rightsTableDef.Text);
            }
            catch (Exception ex)
            {
                strError = "读者权限XML代码格式有误: " + ex.Message;
                goto ERROR1;
            }


            // XML代码更新
            if (this.m_nRightsTableXmlVersion > this.m_nRightsTableTypesVersion)
            {
                // RightsXmlToTypes(dom);
                ListLibraryCodes(dom);
                this.m_nRightsTableTypesVersion = this.m_nRightsTableXmlVersion;
                return(0);
            }

            // types编辑界面更新
            if (this.m_nRightsTableXmlVersion < this.m_nRightsTableTypesVersion)
            {
                // types编辑界面 --> DOM中的<readerTypes>和<bookTypes>部分
                // 调用前dom中应当已经装入了权限XML代码
                TypesToRightsXml(ref dom);

                // 刷新XML文本框
                string strXml = "";
                int    nRet   = DomUtil.GetIndentXml(dom.DocumentElement.OuterXml,
                                                     out strXml,
                                                     out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                if (this.textBox_loanPolicy_rightsTableDef.Text != strXml)
                {
                    // this.textBox_loanPolicy_rightsTableDef.Text = strXml;
                    SetText(this.textBox_loanPolicy_rightsTableDef,
                            strXml);
                }

                this.m_nRightsTableXmlVersion = this.m_nRightsTableTypesVersion;
                return(0);
            }

            return(0);

ERROR1:
            MessageBox.Show(this, strError);
            return(-1);
        }
示例#10
0
        int ListRightsTables(out string strError)
        {
            strError = "";

            if (this.LoanPolicyDefChanged == true)
            {
                // 警告尚未保存
                DialogResult result = MessageBox.Show(this,
                                                      "当前窗口内读者流通权限定义被修改后尚未保存。若此时刷新窗口内容,现有未保存信息将丢失。\r\n\r\n确实要刷新? ",
                                                      "ManagerForm",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button2);
                if (result != DialogResult.Yes)
                {
                    return(0);
                }
            }

            /*
             * // 2008/10/12 new add
             * if (this.LoanPolicyDefChanged == true)
             * {
             *  // 警告尚未保存
             *  DialogResult result = MessageBox.Show(this,
             *      "当前窗口内有读者流通权限定义被修改后尚未保存。若此时重新装载读者流通权限定义,现有未保存信息将丢失。\r\n\r\n确实要重新装载? ",
             *      "ManagerForm",
             *      MessageBoxButtons.YesNo,
             *      MessageBoxIcon.Question,
             *      MessageBoxDefaultButton.Button2);
             *  if (result == DialogResult.No)
             *      return 0;
             * }*/

            string strRightsTableXml  = "";
            string strRightsTableHtml = "";
            //string strReaderTypesXml = "";
            //string strBookTypesXml = "";

            // 获得流通读者权限相关定义
            int nRet = GetRightsTableInfo(out strRightsTableXml,
                                          out strRightsTableHtml,
                                          //out strReaderTypesXml,
                                          //out strBookTypesXml,
                                          out strError);

            if (nRet == -1)
            {
                return(-1);
            }

            strRightsTableXml = "<rightsTable>" + strRightsTableXml + "</rightsTable>";

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strRightsTableXml);
            }
            catch (Exception ex)
            {
                strError = "strRightsTableXml装入XMLDOM时发生错误:" + ex.Message;
                return(-1);
            }

            /*
             * // readertypes
             * this.textBox_loanPolicy_readerTypes.Text = "";
             * {
             *  XmlNodeList nodes = dom.DocumentElement.SelectNodes("readerTypes/item");
             *  string strText = "";
             *  for (int i = 0; i < nodes.Count; i++)
             *  {
             *      if (String.IsNullOrEmpty(strText) == false)
             *          strText += "\r\n";
             *      strText += nodes[i].InnerText;
             *  }
             *  this.textBox_loanPolicy_readerTypes.Text = strText;
             * }
             *
             * // booktypes
             * this.textBox_loanPolicy_bookTypes.Text = "";
             * {
             *  XmlNodeList nodes = dom.DocumentElement.SelectNodes("bookTypes/item");
             *  string strText = "";
             *  for (int i = 0; i < nodes.Count; i++)
             *  {
             *      if (String.IsNullOrEmpty(strText) == false)
             *          strText += "\r\n";
             *      strText += nodes[i].InnerText;
             *  }
             *  this.textBox_loanPolicy_bookTypes.Text = strText;
             * }
             * */

            // 在listview中列出馆代码
            ListLibraryCodes(dom);

            // RightsXmlToTypes(dom);

            /*
             * // TODO: 为了让XML源代码不至于让人误会(想要去编辑<readerTypes>和<bookTypes>),是否要把这两个元素去掉?
             * {
             *  XmlNodeList nodes = dom.DocumentElement.SelectNodes("readerTypes | bookTypes");
             *  for (int i = 0; i < nodes.Count; i++)
             *  {
             *      XmlNode node = nodes[i];
             *      node.ParentNode.RemoveChild(node);
             *  }
             * }*/

            string strXml = "";

            nRet = DomUtil.GetIndentXml(dom.DocumentElement.OuterXml,
                                        out strXml,
                                        out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            this.textBox_loanPolicy_rightsTableDef.Text = strXml;
            SetRightsTableHtml(strRightsTableHtml);


            this.LoanPolicyDefChanged = false;

            this.m_nRightsTableHtmlVersion  = 0;
            this.m_nRightsTableXmlVersion   = 0;
            this.m_nRightsTableTypesVersion = 0;

            return(1);
        }
示例#11
0
        // 列出读者借阅权限定义
        // 需要在 ListCalendars() 以后调用
        int NewListRightsTables(out string strError)
        {
            strError = "";
            int nRet = 0;

            if (this.LoanPolicyDefChanged == true)
            {
                // 警告尚未保存
                DialogResult result = MessageBox.Show(this,
                                                      "当前窗口内读者流通权限定义被修改后尚未保存。若此时刷新窗口内容,现有未保存信息将丢失。\r\n\r\n确实要刷新? ",
                                                      "ManagerForm",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button2);
                if (result != DialogResult.Yes)
                {
                    return(0);
                }
            }

            List <string> calendar_Names = null;

            // 装入全部日历名
            nRet = GetCalendarNames(out calendar_Names,
                                    out strError);
            if (nRet == -1)
            {
                return(-1);
            }


            string strRightsTableXml = "";

            // 获得流通读者权限相关定义
            nRet = GetRightsTableInfo(out strRightsTableXml,
                                      out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            strRightsTableXml = "<rightsTable>" + strRightsTableXml + "</rightsTable>";

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strRightsTableXml);
            }
            catch (Exception ex)
            {
                strError = "strRightsTableXml装入XMLDOM时发生错误:" + ex.Message;
                return(-1);
            }

#if NO
            // 在listview中列出馆代码
            ListLibraryCodes(dom);
#endif

            string strXml = "";
            nRet = DomUtil.GetIndentXml(dom.DocumentElement.OuterXml,
                                        out strXml,
                                        out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            this.textBox_newLoanPolicy_xml.Text = strXml;

            this.loanPolicyControlWrapper1.LoanPolicyControl.CalendarList = calendar_Names;
            m_nCalendarVersion = 0;

            string strLibraryCodeList = GetLibraryCodeList();
#if NO
            if (this.Channel != null)
            {
                strLibraryCodeList = this.Channel.LibraryCodeList;
            }

            // 2014/5/27
            if (Global.IsGlobalUser(strLibraryCodeList) == true)
            {
                strLibraryCodeList = StringUtil.MakePathList(this.MainForm.GetAllLibraryCode());
            }
#endif

            nRet = this.loanPolicyControlWrapper1.LoanPolicyControl.SetData(
                strLibraryCodeList,
                strXml,
                out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            this.LoanPolicyDefChanged = false;

            this.m_nRightsTableXmlVersion   = 0;
            this.m_nRightsTableTypesVersion = 0;

            return(1);
        }
示例#12
0
        // 针对读者记录中的 borrow 元素中 overflow (尚未超期)的,重新计算是否超额。如果不超额的,修改为正常的借期
        // parameters:
        //      now 当前时间。本地时间格式。这是用来判断是否超期的依据
        // return.Value:
        //      -1  出错
        //      0   成功
        //      1   有警告信息,在 strError 中返回
        internal AdjustOverflowResult AdjustOverflow(
            XmlDocument readerdom,
            DateTime now,
            StringBuilder debugInfo)
        {
            List <ItemModifyInfo> modifies = new List <ItemModifyInfo>();

            int nRet = BuildBorrowItemInfo(readerdom,
                                           now,
                                           out List <BorrowItemInfo> items,
                                           out string strError);

            if (nRet == -1)
            {
                return new AdjustOverflowResult
                       {
                           Value     = -1,
                           ErrorInfo = strError,
                           Modifies  = modifies
                       }
            }
            ;

            // 没有任何在借事项
            if (items.Count == 0)
            {
                return new AdjustOverflowResult
                       {
                           Value    = 0,
                           Modifies = modifies
                       }
            }
            ;

            int overflow_count = BorrowItemInfo.CountOverflow(items);

            // 没有超额事项可供调整
            if (overflow_count == 0)
            {
                return new AdjustOverflowResult
                       {
                           Value    = 0,
                           Modifies = modifies
                       }
            }
            ;

            // 获得总的最大可借数
            // return:
            //      -1  出错
            //      其他  最大可借册数
            int totalMax = GetTotalMax(
                readerdom,
                out strError);

            if (totalMax == -1)
            {
                return new AdjustOverflowResult
                       {
                           Value     = -1,
                           ErrorInfo = strError,
                           Modifies  = modifies
                       }
            }
            ;

            List <string> warnings = new List <string>();

            var groups = BorrowItemInfo.GroupByBookType(items);

            // 对每种图书类型,尝试修正到本类型的最大许可外借数
            foreach (var group in groups)
            {
                string bookType = group[0].BookType;

                // 获得特定图书类型的最大可借数
                // return:
                //      -1  出错
                //      其他  此类型图书的最大可借册数
                int typeMax = GetTypeMax(
                    readerdom,
                    bookType,
                    out strError);
                if (typeMax == -1)
                {
                    warnings.Add(strError);
                    continue;   // 放弃这一类型的处理,继续处理其他类型
                }

                while (true)
                {
                    // 统计数组中,正常借阅(非超额)的数量
                    int count = BorrowItemInfo.CountNormal(group);
                    if (count < typeMax)
                    {
                        // 尝试从中改掉一个 overflow
                        // return:
                        //      true 成功改掉一个
                        //      false   没能改掉。(原因可能是因为没有可以改动状态的 overflow 元素了)
                        var item = BorrowItemInfo.DecOverflow(group);
                        if (item == null)
                        {
                            break;
                        }

                        // 检查总册数是否超额。如果超额,刚才的改动需要 undo
                        int totalCount = BorrowItemInfo.CountNormal(items);
                        if (totalCount > totalMax)
                        {
                            item.ModifyAction = null;   // Undo
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            // 开始修改 borrow 元素
            foreach (var item in items)
            {
                if (item.ModifyAction != "removeOverflow")
                {
                    continue;
                }

                string strOldBorrowInfo = item.Element.OuterXml;

                // 获得一册书的借阅参数
                nRet = GetBorrowParam(
                    readerdom,
                    item.BookType,
                    item.BorrowDate,
                    out string borrowPeriod,
                    out string denyPeriod,
                    out string returningDate,
                    out strError);
                if (nRet == -1)
                {
                    warnings.Add(strError);
                    continue;
                }

                item.Element.SetAttribute("borrowPeriod",
                                          borrowPeriod);

                if (string.IsNullOrEmpty(denyPeriod) == false)
                {
                    item.Element.SetAttribute("denyPeriod",
                                              denyPeriod);
                }
                else
                {
                    item.Element.RemoveAttribute("denyPeriod");
                }

                item.Element.SetAttribute("returningDate",
                                          returningDate);

                // 删除 overflow 属性
                item.Element.RemoveAttribute("overflow");

                modifies.Add(new ItemModifyInfo
                {
                    LibraryCode   = DomUtil.GetElementText(readerdom.DocumentElement, "libraryCode"),
                    PatronBarcode = DomUtil.GetElementText(readerdom.DocumentElement, "barcode"),
                    BorrowID      = item.Element.GetAttribute("borrowID"),
                    ItemBarcode   = item.Barcode,
                    BorrowDate    = item.Element.GetAttribute("borrowDate"),
                    BorrowPeriod  = borrowPeriod,
                    DenyPeriod    = denyPeriod,
                    ReturningDate = returningDate,
                    OldBorrowInfo = strOldBorrowInfo,
                });
            }

            /*
             * // 修改涉及到的册记录
             * if (modifies.Count > 0 && sessioninfo != null)
             * {
             *  foreach (var info in modifies)
             *  {
             *      nRet = ModifyItemRecord(
             * sessioninfo,
             * info,
             * out strError);
             *      if (nRet == -1)
             *      {
             *          warnings.Add($"修改册记录 {info.ItemBarcode} 过程中出错: {strError}");
             *          debugInfo?.Append($"{warnings[warnings.Count - 1]}");
             *      }
             *  }
             * }
             */

            if (warnings.Count > 0)
            {
                strError = StringUtil.MakePathList(warnings, "; ");
                return(new AdjustOverflowResult
                {
                    Value = 1,
                    ErrorInfo = strError,
                    Modifies = modifies
                });
            }

            return(new AdjustOverflowResult
            {
                Value = 0,
                Modifies = modifies
            });
        }

#if NO
        // 针对读者记录中的 borrow 元素中 overflow (尚未超期)的,重新计算是否超额。如果不超额的,修改为正常的借期
        // return:
        //      -1  出错
        //      0   成功
        //      1   有警告信息,在 strError 中返回
        int AdjustOverflow(
            SessionInfo sessioninfo,
            XmlDocument readerdom,
            StringBuilder debugInfo,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            debugInfo.AppendLine($"用于调整的读者记录: {DomUtil.GetIndentXml(readerdom)}");

            List <string>         warnings = new List <string>();
            List <ItemModifyInfo> items    = new List <ItemModifyInfo>();

            string libraryCode = DomUtil.GetElementText(readerdom.DocumentElement, "libraryCode");
            string readerType  = DomUtil.GetElementText(readerdom.DocumentElement, "readerType");

            // List<XmlElement> overflows = new List<XmlElement>();

            debugInfo?.AppendLine($"libraryCode='{libraryCode}'");
            debugInfo?.AppendLine($"readerType='{readerType}'");

            var nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");

            foreach (XmlElement borrow in nodes)
            {
                debugInfo?.AppendLine($"=== 对 borrow 元素进行处理: {borrow.OuterXml}");
                if (borrow.HasAttribute("overflow") == false)
                {
                    debugInfo?.AppendLine("没有 overflow 属性,跳过处理");
                    continue;
                }

                string no = borrow.GetAttribute("no");
                if (string.IsNullOrEmpty(no) == false)
                {
                    if (Int32.TryParse(no, out int value) == true)
                    {
                        if (value > 0)
                        {
                            debugInfo?.AppendLine("续借的情况跳过处理");
                            continue;   // 续借的情况不考虑
                        }
                    }
                    else
                    {
                        warnings.Add($"续借次数 '{no}' 格式错误");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                        continue;
                    }
                }

                string itemBarcode = borrow.GetAttribute("barcode");
                if (string.IsNullOrEmpty(itemBarcode))
                {
                    itemBarcode = "@refid:" + borrow.GetAttribute("refID");
                }

                debugInfo?.AppendLine($"条码号='{itemBarcode}'");

                try
                {
                    // 获得借阅开始时间
                    string borrowDate = borrow.GetAttribute("borrowDate");

                    debugInfo?.AppendLine($"borrowDate='{borrowDate}'");

                    DateTime borrowTime = DateTimeUtil.FromRfc1123DateTimeString(borrowDate).ToLocalTime();

                    // 看看是否已经超期。已经超期的不处理
                    {
                        string returningDate = borrow.GetAttribute("returningDate");

                        debugInfo?.AppendLine($"returningDate='{returningDate}'");

                        DateTime returningTime = DateTimeUtil.FromRfc1123DateTimeString(returningDate).ToLocalTime();

                        string period = borrow.GetAttribute("borrowPeriod");

                        debugInfo?.AppendLine($"borrowPeriod='{period}'");

                        nRet = LibraryApplication.ParsePeriodUnit(period,
                                                                  out long lPeriodValue,
                                                                  out string strPeriodUnit,
                                                                  out strError);
                        if (nRet == -1)
                        {
                            debugInfo?.AppendLine($"ParsePeriodUnit('{period}') 出错:{strError}。只好把时间单位当作 day 来处理");
                            strPeriodUnit = "day";
                            // continue;
                        }

                        DateTime now = DateTime.Now;
                        // 正规化时间
                        nRet = DateTimeUtil.RoundTime(strPeriodUnit,
                                                      ref now,
                                                      out strError);
                        if (nRet == -1)
                        {
                            warnings.Add($"正规化时间出错(1)。strPeriodUnit={strPeriodUnit}");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }

                        nRet = DateTimeUtil.RoundTime(strPeriodUnit,
                                                      ref returningTime,
                                                      out strError);
                        if (nRet == -1)
                        {
                            warnings.Add($"正规化时间出错(2)。strPeriodUnit={strPeriodUnit}");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }

                        if (returningTime < now)
                        {
                            debugInfo?.AppendLine($"已经超期,跳过处理 (returningTime={returningTime.ToString()}, now={now.ToString()})");
                            continue;
                        }
                    }

                    string bookType = borrow.GetAttribute("type");

                    debugInfo?.AppendLine($"bookType='{bookType}'");

                    // 假设要首次借阅这一册,是否会超额?
                    {
                        // 从读者信息中,找出该读者以前已经借阅过的同类图书的册数
                        int nThisTypeCount = readerdom.DocumentElement.SelectNodes("borrows/borrow[@type='" + bookType + "']").Count;

                        nRet = this.GetLoanParam(
                            //null,
                            libraryCode,
                            readerType,
                            bookType,
                            "可借册数",
                            out string strParamValue,
                            out MatchResult _,
                            out strError);
                        if (nRet == -1)
                        {
                            warnings.Add($"获得 馆代码 '{ libraryCode }' 中 读者类型 '{ readerType }' 针对图书类型 '{ bookType }' 的 可借册数 参数时发生错误: {strError}");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }
                        if (nRet < 4)
                        {
                            warnings.Add($"馆代码 '{ libraryCode}' 中 读者类型 '{ readerType }' 针对图书类型 '{ bookType }' 的 可借册数 参数无法获得: {strError}");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }

                        if (Int32.TryParse(strParamValue, out int thisTypeMax) == false)
                        {
                            warnings.Add($"馆代码 '{ libraryCode}' 中 读者类型 '{ readerType }' 针对图书类型 '{ bookType }' 的 可借册数 参数 '{strParamValue}' 格式错误");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }

                        // 依然超额了。不修改
                        if (nThisTypeCount > thisTypeMax)
                        {
                            debugInfo?.AppendLine($"特定类型的图书超额了,跳过处理。nThisTypeCount={nThisTypeCount}, thisTypeMax={thisTypeMax}, bookType={bookType}, readerType={readerType}");
                            continue;
                        }

                        // 看 可借总册数
                        nRet = this.GetLoanParam(
//null,
                            libraryCode,
                            readerType,
                            "",
                            "可借总册数",
                            out strParamValue,
                            out MatchResult _,
                            out strError);
                        if (nRet == -1)
                        {
                            warnings.Add($"获得 馆代码 '{ libraryCode }' 中 读者类型 '{ readerType }' 的 可借总册数 参数时发生错误: {strError}");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }
                        if (nRet < 3)
                        {
                            warnings.Add($"馆代码 '{ libraryCode}' 中 读者类型 '{ readerType }' 的 可借总册数 参数无法获得: {strError}");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }
                        if (Int32.TryParse(strParamValue, out int max) == false)
                        {
                            warnings.Add($"馆代码 '{ libraryCode}' 中 读者类型 '{ readerType }' 的 可借总册数 参数 '{strParamValue}' 格式错误");
                            debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                            continue;
                        }

                        // 从读者信息中,找出该读者已经借阅过的册数
                        int count = readerdom.DocumentElement.SelectNodes("borrows/borrow").Count;
                        // 依然超额了。不修改
                        if (count > max)
                        {
                            debugInfo?.AppendLine($"全部图书超额了,跳过处理。count={count}, max={max}, readerType={readerType}");
                            continue;
                        }
                    }


                    // return:
                    //      reader和book类型均匹配 算4分
                    //      只有reader类型匹配,算3分
                    //      只有book类型匹配,算2分
                    //      reader和book类型都不匹配,算1分
                    nRet = this.GetLoanParam(
                        libraryCode,
                        readerType,
                        bookType,
                        "借期",
                        out string strBorrowPeriodList,
                        out MatchResult matchresult,
                        out strError);
                    if (nRet == -1)
                    {
                        warnings.Add($"获得 馆代码 '{ libraryCode }' 中 读者类型 '{ readerType }' 针对图书类型 '{ bookType }' 的 借期 参数时发生错误: {strError}");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                        continue;
                    }
                    if (nRet < 4)  // nRet == 0
                    {
                        warnings.Add($"馆代码 '{ libraryCode}' 中 读者类型 '{ readerType }' 针对图书类型 '{ bookType }' 的 借期 参数无法获得: {strError}");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                        continue;
                    }

                    string[] aPeriod = strBorrowPeriodList.Split(new char[] { ',' });
                    if (aPeriod.Length == 0)
                    {
                        warnings.Add($"'{strBorrowPeriodList}' Split error");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                        continue;
                    }

                    string borrowPeriod = aPeriod[0];
                    if (string.IsNullOrEmpty(borrowPeriod))
                    {
                        warnings.Add($"期限字符串 '{strBorrowPeriodList}' 中第一部分 '{borrowPeriod}' 为空");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                        continue;
                    }

                    nRet = ParseBorrowPeriod(borrowPeriod,
                                             out string strThisBorrowPeriod,
                                             out string strThisDenyPeriod,
                                             out strError);
                    if (nRet == -1)
                    {
                        warnings.Add($"ParseBorrowPeroid() '{borrowPeriod}' error");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                        continue;
                    }


                    // 计算应还书时间
                    nRet = ComputeReturningDay(
                        borrowTime,
                        strThisBorrowPeriod,
                        out DateTime this_return_time,
                        out strError);
                    if (nRet == -1)
                    {
                        warnings.Add($"ComputeReturningDay() error. borrowTime='{borrowTime}', strThisBorrowPeriod='{strThisBorrowPeriod}'");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                        continue;
                    }

                    borrow.SetAttribute("borrowPeriod",
                                        strThisBorrowPeriod);
                    // 2016/6/7
                    if (string.IsNullOrEmpty(strThisDenyPeriod) == false)
                    {
                        borrow.SetAttribute("denyPeriod",
                                            strThisDenyPeriod);
                    }
                    else
                    {
                        borrow.RemoveAttribute("denyPeriod");
                    }

                    string strReturningDate = DateTimeUtil.Rfc1123DateTimeStringEx(this_return_time.ToLocalTime());
                    borrow.SetAttribute("returningDate",
                                        strReturningDate);

                    // 删除 overflow 属性
                    borrow.RemoveAttribute("overflow");

                    items.Add(new ItemModifyInfo
                    {
                        ItemBarcode   = itemBarcode,
                        BorrowPeriod  = strThisBorrowPeriod,
                        DenyPeriod    = strThisDenyPeriod,
                        ReturningDate = strReturningDate
                    });
                }
                catch (Exception ex)
                {
                    warnings.Add($"册记录 {itemBarcode} 处理过程出现异常: {ex.Message}");
                    debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                }
            }

            // 修改涉及到的册记录
            if (items.Count > 0)
            {
                foreach (var info in items)
                {
                    nRet = ModifyItemRecord(
                        sessioninfo,
                        info,
                        out strError);
                    if (nRet == -1)
                    {
                        warnings.Add($"修改册记录 {info.ItemBarcode} 过程中出错: {strError}");
                        debugInfo?.Append($"{warnings[warnings.Count - 1]}");
                    }
                }
            }


            if (warnings.Count > 0)
            {
                strError = StringUtil.MakePathList(warnings, "; ");
                return(1);
            }

            return(0);
        }
示例#13
0
文件: UtilityForm.cs 项目: gvhung/dp2
        private void button_xmlEditor_load_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title    = "请指定要打开的XML文件名";
            dlg.FileName = this.textBox_xmlEditor_xmlFilename.Text;
            // dlg.InitialDirectory =
            dlg.Filter           = "XML文件 (*.xml)|*.xml|All files (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            this.textBox_xmlEditor_xmlFilename.Text = dlg.FileName;

            string   strError   = "";
            string   strContent = "";
            Encoding encoding   = null;
            // 能自动识别文件内容的编码方式的读入文本文件内容模块
            // return:
            //      -1  出错
            //      0   文件不存在
            //      1   文件存在
            //      2   读入的内容不是全部
            int nRet = FileUtil.ReadTextFileContent(this.textBox_xmlEditor_xmlFilename.Text,
                                                    100 * 1024, // 100K
                                                    out strContent,
                                                    out encoding,
                                                    out strError);

            if (nRet == 1 || nRet == 2)
            {
                bool   bExceed = nRet == 2;
                string strXml  = "";
                if (this.checkBox_xmlEditor_indent.Checked == true)
                {
                    nRet = DomUtil.GetIndentXml(strContent,
                                                true,
                                                out strXml,
                                                out strError);
                    if (nRet == -1)
                    {
                        if (bExceed == false)
                        {
                            MessageBox.Show(this, strError);
                        }
                        strXml = strContent;
                    }
                }
                else
                {
                    strXml = strContent;
                }

                this.textBox_xmlEditor_content.Text =
                    (bExceed == true ? "文件尺寸太大,下面只显示了开头部分...\r\n" : "") + strXml;
                if (bExceed == true)
                {
                    MessageBox.Show(this, "文件尺寸太大,下面只显示了开头部分");
                }

                this.m_bExceedMode = bExceed;
            }
            else
            {
                this.textBox_xmlEditor_content.Text = "";
                this.m_bExceedMode = false;
            }

            if (encoding == null)
            {
                this.comboBox_xmlFile_encoding.Text = "";
            }
            else
            {
                this.comboBox_xmlFile_encoding.Text = encoding.BodyName;
            }

            SetExceedMode();
        }
示例#14
0
 void UpdateXmlTextDisplay()
 {
     this.textBox_userRecord.Text = DomUtil.GetIndentXml(this.UserRecDom);
 }
示例#15
0
        // 保存修改
        private void button_OK_Click(object sender, System.EventArgs e)
        {
            string strError = "";
            long   lRet     = 0;

            if (this.UserName == "")
            {
                MessageBox.Show(this, "用户名不能为空。");
                goto ERROR1;
            }

            // 兑现本次树上修改
            if (treeView_resRightTree.Changed == true)
            {
                treeView_resRightTree.FinishRightsParam();
            }


            // MessageBox.Show(this, DomUtil.GetIndentXml(this.UserRecDom));

            RmsChannel channel = MainForm.Channels.GetChannel(this.ServerUrl);

            if (channel == null)
            {
                strError = "Channels.GetChannel 异常";
                goto ERROR1;
            }



            // UserRecPath为空表示为新创建账户,需要查重
            if (this.UserRecPath == "")
            {
                // 查重
                // return:
                //      -1  出错
                //      其他   检索命中的记录数。只要大于1,就表示有多于一条的存在。
                lRet = SearchUserNameDup(
                    this.UserName,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                if (lRet >= 1)
                {
                    strError = "用户名 '" + this.UserName + "' 已经存在,无法创建新的用户记录。";
                    goto ERROR1;
                }
            }

            // 旧版本的<rightsItem>需要去掉
            XmlNode node = this.UserRecDom.DocumentElement.SelectSingleNode("rightsItem");

            if (node != null)
            {
                node.ParentNode.RemoveChild(node);
            }

            string strXml        = DomUtil.GetIndentXml(this.UserRecDom);
            string strOutputPath = "";

            byte[] baOutputTimeStamp;

            lRet = channel.DoSaveTextRes(
                this.UserRecPath == "" ?
                (Defs.DefaultUserDb.Name + "/" + "?") : this.UserRecPath,
                strXml,
                false,          // bInlucdePreamble
                "",             // style
                this.TimeStamp, // baTimeStamp,
                out baOutputTimeStamp,
                out strOutputPath,
                out strError);
            if (lRet == -1)
            {
                goto ERROR1;
            }

            this.TimeStamp = baOutputTimeStamp;

            treeView_resRightTree.Changed = false;

            // MessageBox.Show("帐户记录保存成功。");

            // 保存成功后再查重一次
            lRet = SearchUserNameDup(
                this.UserName,
                out strError);
            if (lRet == -1)
            {
                goto ERROR1;
            }
            if (lRet > 1)
            {
                strError = "警告:用户名 '" + this.UserName + "' 目前存在" + Convert.ToString(lRet) + "条记录。这是不正常的情况,会引起这个用户名无法登录,请尽快修正。";
                MessageBox.Show(this, strError);
            }


            this.DialogResult = DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(strError);
            return;
        }