Exemplo n.º 1
0
        // TODO: 预先将AppInfo中值取出,加快速度
        // return:
        //      -1  出错
        //      0   未发生改变
        //      1   发生了改变
        int ModifyField998(ref string strMARC,
                           DateTime now,
                           out string strError)
        {
            strError = "";
            // int nRet = 0;
            bool bChanged = false;

            string strField998 = MarcUtil.GetField(strMARC,
                                                   "998");

            if (strField998 == null)
            {
                strError = "GetField() 998 error";
                return(-1);
            }

            if (String.IsNullOrEmpty(strField998) == true ||
                strField998.Length < 5)
            {
                strField998 = "998  ";
            }


            // state
            string strStateAction = Program.MainForm.AppInfo.GetString(
                "change_biblio_param",
                "state",
                "<不改变>");

            if (strStateAction != "<不改变>")
            {
                string strState = MarcUtil.GetSubfieldContent(strField998,
                                                              "s");

                if (strStateAction == "<增、减>")
                {
                    string strAdd = Program.MainForm.AppInfo.GetString(
                        "change_biblio_param",
                        "state_add",
                        "");
                    string strRemove = Program.MainForm.AppInfo.GetString(
                        "change_biblio_param",
                        "state_remove",
                        "");

                    string strOldState = strState;

                    if (String.IsNullOrEmpty(strAdd) == false)
                    {
                        StringUtil.SetInList(ref strState, strAdd, true);
                    }
                    if (String.IsNullOrEmpty(strRemove) == false)
                    {
                        StringUtil.SetInList(ref strState, strRemove, false);
                    }

                    if (strOldState != strState)
                    {
                        MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                        "s", strState);
                        bChanged = true;
                    }
                }
                else
                {
                    if (strStateAction != strState)
                    {
                        MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                        "s", strStateAction);
                        bChanged = true;
                    }
                }
            }


            // time
            string strTimeAction = Program.MainForm.AppInfo.GetString(
                "change_biblio_param",
                "opertime",
                "<不改变>");

            if (strTimeAction != "<不改变>")
            {
                string strTime = MarcUtil.GetSubfieldContent(strField998,
                                                             "u");
                DateTime time = new DateTime(0);
                if (strTimeAction == "<当前时间>")
                {
                    time = now;
                }
                else if (strTimeAction == "<清除>")
                {
                }
                else if (strTimeAction == "<指定时间>")
                {
                    string strValue = Program.MainForm.AppInfo.GetString(
                        "change_biblio_param",
                        "opertime_value",
                        "");
                    if (String.IsNullOrEmpty(strValue) == true)
                    {
                        strError = "当进行 <指定时间> 方式的修改时,所指定的时间值不能为空";
                        return(-1);
                    }
                    try
                    {
                        time = DateTime.Parse(strValue);
                    }
                    catch (Exception ex)
                    {
                        strError = "无法解析时间字符串 '" + strValue + "' :" + ex.Message;
                        return(-1);
                    }
                }
                else
                {
                    // 不支持
                    strError = "不支持的时间动作 '" + strTimeAction + "'";
                    return(-1);
                }

                string strOldTime = strTime;

                if (strTimeAction == "<清除>")
                {
                    strTime = "";
                }
                else
                {
                    strTime = time.ToString("u");
                }

                if (strOldTime != strTime)
                {
                    MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                    "u", strTime);
                    bChanged = true;
                }
            }


            // batchno
            string strBatchNoAction = Program.MainForm.AppInfo.GetString(
                "change_biblio_param",
                "batchNo",
                "<不改变>");

            if (strBatchNoAction != "<不改变>")
            {
                string strBatchNo = MarcUtil.GetSubfieldContent(strField998,
                                                                "a");

                if (strBatchNo != strBatchNoAction)
                {
                    MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                    "a", strBatchNoAction);
                    bChanged = true;
                }
            }

            if (bChanged == false)
            {
                return(0);
            }

            //
            MarcUtil.ReplaceField(ref strMARC,
                                  "998",
                                  0,
                                  strField998);

            return(1);
        }