Example #1
0
        // 进行检查
        // return:
        //      -1  函数运行出错
        //      0   检查没有发现错误
        //      1   检查发现了错误
        public int Check(out string strError)
        {
            strError = "";
            int nRet = 0;

            bool bStrict = true;    // 是否严格检查

            // 检查是否每行都输入了价格、份数
            for (int i = 0; i < this.Items.Count; i++)
            {
                Item item = this.Items[i];

                // 只检查新规划的事项
                if ((item.State & ItemState.ReadOnly) != 0)
                    continue;
                // 跳过未曾修改过的事项
                if ((item.State & ItemState.New) == 0
                    && (item.State & ItemState.Changed) == 0)
                    continue;

                // 进行检查
                // return:
                //      -1  函数运行出错
                //      0   检查没有发现错误
                //      1   检查发现了错误
                nRet = item.location.Check(out strError);
                if (nRet != 0)
                {
                    strError = "第 " + (i + 1).ToString() + " 行: 去向 格式有问题: " + strError;
                    return 1;
                }

                // 2009/11/9
                string strTotalPrice = "";

                try
                {
                    strTotalPrice = item.TotalPrice;
                }
                catch (Exception ex)
                {
                    strError = "获取item.TotalPrice时出错: " + ex.Message;
                    return -1;
                }

                if (String.IsNullOrEmpty(strTotalPrice) == true)
                {
                    if (String.IsNullOrEmpty(item.Price) == true)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入价格";
                        return 1;
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(item.StateString) == true
                        && String.IsNullOrEmpty(item.Price) == false)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 当输入了价格 ('"+item.Price+"') 时,必须把总价格设置为空 (但现在为 '"+strTotalPrice+"')";
                        return 1;
                    }
                }

                if (this.ArriveMode == false)   // 2009/2/4
                {
                    // 订购模式
                    if (String.IsNullOrEmpty(item.CopyString) == true)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入复本数";
                        return 1;
                    }
                }
                else
                {
                    // 验收模式

                    // 不一定每一行都要验收

                    // TODO: 是否检查一下至少有一行验收了?不太好检查。

                }

                if (this.SeriesMode == true)
                {
                    if (String.IsNullOrEmpty(item.RangeString) == true)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入时间范围";
                        return 1;
                    }

                    if (item.RangeString.Length != (2*8 + 1))
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入完整的时间范围";
                        return 1;
                    }

                    // return:
                    //      -1  error
                    //      0   succeed
                    nRet = VerifyDateRange(item.RangeString,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: " + strError;
                        return 1;
                    }

                    if (String.IsNullOrEmpty(item.IssueCountString) == true)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入期数";
                        return 1;
                    }


                }


                if (bStrict == true)
                {
                    if (String.IsNullOrEmpty(item.Source) == true
                        && item.Seller != "交换" && item.Seller != "赠")
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入经费来源";
                        return 1;
                    }

                    // 2009/2/15
                    if (item.Seller == "交换" || item.Seller == "赠")
                    {
                        if (String.IsNullOrEmpty(item.Source) == false)
                        {
                            strError = "第 " + (i + 1).ToString() + " 行: 如果渠道为 交换 或 赠,则经费来源必须为空";
                            return 1;
                        }
                    }

                    if (String.IsNullOrEmpty(item.Seller) == true)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入渠道";
                        return 1;
                    }
                    /*
                    if (String.IsNullOrEmpty(item.CatalogNo) == true)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入书目号";
                        return 1;
                    }
                     * */
                    if (String.IsNullOrEmpty(item.Class) == true)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 尚未输入类别";
                        return 1;
                    }
                }
            }

            if (bStrict == true)
            {
                // 检查 渠道 + 经费来源 + 价格 3元组是否有重复
                for (int i = 0; i < this.Items.Count; i++)
                {
                    Item item = this.Items[i];

                    // 只检查新规划的事项
                    if ((item.State & ItemState.ReadOnly) != 0)
                        continue;


                    // 2009/2/4 只检查新输入的订购事项
                    if (String.IsNullOrEmpty(item.StateString) == false)
                        continue;

                    string strLocationString = item.location.Value;
                    LocationCollection locations = new LocationCollection();
                    nRet = locations.Build(strLocationString, out strError);
                    if (nRet == -1)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行: 去向字符串 '"+strLocationString+"' 格式错误: " + strError;
                        return -1;
                    }
                    string strUsedLibraryCodes = StringUtil.MakePathList(locations.GetUsedLibraryCodes());

                    // 检查馆代码是否在管辖范围内
                    // 只检查修改过的事项
                    if (IsChangedItem(item) == true
                        && this.VerifyLibraryCode != null)
                    {
                        VerifyLibraryCodeEventArgs e = new VerifyLibraryCodeEventArgs();
                        e.LibraryCode = strUsedLibraryCodes;
                        this.VerifyLibraryCode(this, e);
                        if (string.IsNullOrEmpty(e.ErrorInfo) == false)
                        {
                            strError = "第 " + (i + 1).ToString() + " 行: 去向错误: " + e.ErrorInfo;
                            return -1;
                        }
                    }

                    for (int j = i + 1; j < this.Items.Count; j++)
                    {
                        Item temp_item = this.Items[j];

                        // 只检查新规划的事项
                        if ((temp_item.State & ItemState.ReadOnly) != 0)
                            continue;
                        // 跳过未曾修改过的事项
                        if (IsChangedItem(temp_item) == false)
                            continue;

                        // 2009/2/4 只检查新输入的订购事项
                        if (String.IsNullOrEmpty(temp_item.StateString) == false)
                            continue;

                        string strTempLocationString = temp_item.location.Value;
                        LocationCollection temp_locations = new LocationCollection();
                        nRet = temp_locations.Build(strTempLocationString, out strError);
                        if (nRet == -1)
                        {
                            strError = "第 " + (j + 1).ToString() + " 行: 去向字符串 '" + strTempLocationString + "' 格式错误: " + strError;
                            return -1;
                        }
                        string strTempUsedLibraryCodes = StringUtil.MakePathList(temp_locations.GetUsedLibraryCodes());

                        if (this.CheckDupItem == true)
                        {
                            if (this.SeriesMode == false)
                            {
                                // 对图书检查四元组
                                if (item.Seller == temp_item.Seller
                                    && item.Source == temp_item.Source
                                    && item.Price == temp_item.Price
                                    && strUsedLibraryCodes == strTempUsedLibraryCodes)
                                {
                                    strError = "第 " + (i + 1).ToString() + " 行 和 第 " + (j + 1) + " 行之间 渠道/经费来源/价格/去向(中所含的馆代码) 四元组重复,需要将它们合并为一行";
                                    return 1;
                                }
                            }
                            else
                            {
                                // 对期刊检查五元组
                                if (item.Seller == temp_item.Seller
                                    && item.Source == temp_item.Source
                                    && item.Price == temp_item.Price
                                    && item.RangeString == temp_item.RangeString
                                    && strUsedLibraryCodes == strTempUsedLibraryCodes)
                                {
                                    strError = "第 " + (i + 1).ToString() + " 行 和 第 " + (j + 1) + " 行之间 渠道/经费来源/时间范围/价格/去向(中所含的馆代码) 五元组重复,需要将它们合并为一行";
                                    return 1;
                                }
                            }
                        }

                    }
                }
            }

            return 0;
        }