Exemple #1
0
        // result.Value:
        //      -1  出错
        //      0   没有必要转换
        //      1   已经转换
        public Result ConvertISSN(string strISSN,
                                  out List <string> issns)
        {
            issns = new List <string>();

            if (string.IsNullOrEmpty(this.ConvertStyle) == true)
            {
                issns.Add(strISSN);
                return(new Result());
            }

            // ISSN,强制转换为 8 数字形态 xxxx-xxxx
            bool bForce8 = StringUtil.IsInList("force8", this.ConvertStyle);

            int nRet = 0;

            if (bForce8)
            {
                // return:
                //      -1:出错;
                //      0:未修改校验位;
                //      1:修改了校验位
                nRet = IsbnSplitter.IssnInsertHyphen(
                    strISSN,
                    "force8",
                    out string strTarget,
                    out string strError);
                if (nRet == -1)
                {
                    return new Result {
                               Value = -1, ErrorInfo = strError
                    }
                }
                ;
                issns.Add(strTarget);
                return(new Result {
                    Value = nRet, ErrorInfo = strError
                });
            }

            if (issns.Count == 0)
            {
                issns.Add(strISSN);
            }

            return(new Result());
        }
    }
Exemple #2
0
    void HyphenISSN(bool bForce13)
    {
        string strError = "";
        string strISSN  = "";
        int    nRet     = 0;

        strISSN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("011", "a");

        if (strISSN.Trim() == "")
        {
            MessageBox.Show(this.DetailForm, "记录中不存在011$a子字段,因此无法进行规整");
            return;
        }

        string strResult = "";

        nRet = IsbnSplitter.IssnInsertHyphen(strISSN,
                                             bForce13 == true ? "force13,strict" : "force8,strict",
                                             out strResult,
                                             out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        if (nRet == 1)
        {
            DialogResult result = MessageBox.Show(this.DetailForm,
                                                  "原ISSN '" + strISSN + "'加工成 '" + strResult + "' 后发现校验位有变化。\r\n\r\n是否接受修改?",
                                                  "规整ISSN",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question,
                                                  MessageBoxDefaultButton.Button2);
            if (result != DialogResult.Yes)
            {
                return;
            }
        }

        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("011", "a", strResult);
        return;

ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }
Exemple #3
0
        // return:
        //      -1  出错
        //      0   没有必要转换
        //      1   已经转换
        public int ConvertISBN(string strISBN,
                               out List <string> isbns,
                               out string strError)
        {
            strError = "";
            isbns    = new List <string>();

            if (string.IsNullOrEmpty(this.ConvertStyle) == true)
            {
                isbns.Add(strISBN);
                return(0);
            }

            bool bForce13      = StringUtil.IsInList("force13", this.ConvertStyle);
            bool bForce10      = StringUtil.IsInList("force10", this.ConvertStyle);
            bool bAddHyphen    = StringUtil.IsInList("addhyphen", this.ConvertStyle);
            bool bRemoveHyphen = StringUtil.IsInList("removehyphen", this.ConvertStyle);
            bool bWildMatch    = StringUtil.IsInList("wild", this.ConvertStyle);

            // ISSN,强制转换为 8 数字形态 xxxx-xxxx
            // bool bForce8 = StringUtil.IsInList("force8", this.ConvertStyle);

            int nRet = 0;

#if REMOVED
            if (bForce8)
            {
                // return:
                //      -1:出错;
                //      0:未修改校验位;
                //      1:修改了校验位
                nRet = IsbnSplitter.IssnInsertHyphen(
                    strISBN,
                    "force8",
                    out string strTarget,
                    out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                isbns.Add(strTarget);
                return(nRet);
            }
#endif
            if (bWildMatch == true)
            {
                List <string> styles = new List <string>();
                styles.Add("remainverifychar,auto");
                styles.Add("remainverifychar,force13");
                styles.Add("remainverifychar,force10");

                foreach (string style in styles)
                {
                    string strTarget = "";
                    nRet = this.IsbnSplitter.IsbnInsertHyphen(
                        strISBN,
                        style,
                        out strTarget,
                        out strError);
                    if (nRet == -1)
                    {
                        continue;
                    }
                    isbns.Add(strTarget);
                }
                isbns.Add(strISBN); // 最原始的

                styles = new List <string>();
                styles.Add("remainverifychar,force13");
                styles.Add("remainverifychar,force10");

                foreach (string style in styles)
                {
                    string strTarget = "";
                    nRet = this.IsbnSplitter.IsbnInsertHyphen(
                        strISBN,
                        style,
                        out strTarget,
                        out strError);
                    if (nRet == -1)
                    {
                        continue;
                    }
                    isbns.Add(strTarget.Replace("-", ""));
                }
                isbns.Add(strISBN.Replace("-", ""));    // 最原始的去掉横线的

                // TODO: 是否要增加10位13位去掉校验位的,然后指明前方一致的?

                StringUtil.RemoveDupNoSort(ref isbns);
                return(1);
            }

            string strStyle = "remainverifychar";

            // 如果 bAddHyphen 和 bRemoveHyphen 都没有勾选,那么需要看字符串里面本来是否有横杠,有就保留,没有也不要加入
            if (bAddHyphen == false && bRemoveHyphen == false &&
                (bForce13 == true || bForce10 == true))
            {
                if (strISBN.IndexOf("-") == -1)
                {
                    bRemoveHyphen = true;
                }
                else
                {
                    bAddHyphen = true;
                }
            }

            if (bAddHyphen == true)
            {
                if (bForce10 == false && bForce13 == false)
                {
                    strStyle += ",auto";
                }
                else if (bForce13 == true)
                {
                    strStyle += ",force13";
                }
                else if (bForce10 == true)
                {
                    strStyle += ",force10";
                }
                else
                {
                    strError = "force10和force13不应同时具备";
                    return(-1);
                }

                string strTarget = "";
                nRet = this.IsbnSplitter.IsbnInsertHyphen(
                    strISBN,
                    strStyle,
                    out strTarget,
                    out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                isbns.Add(strTarget);
                return(1);
            }

            if (bRemoveHyphen == true)
            {
                if (bForce10 == false && bForce13 == false)
                {
                    strISBN = strISBN.Replace("-", "");
                    return(1);
                }
                else if (bForce13 == true)
                {
                    strStyle += ",force13";
                }
                else if (bForce10 == true)
                {
                    strStyle += ",force10";
                }
                else
                {
                    strError = "force10和force13不应同时具备";
                    return(-1);
                }

                string strTarget = "";
                nRet = this.IsbnSplitter.IsbnInsertHyphen(
                    strISBN,
                    strStyle,
                    out strTarget,
                    out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                isbns.Add(strTarget.Replace("-", ""));
                return(1);
            }

            if (isbns.Count == 0)
            {
                isbns.Add(strISBN);
            }

            return(0);
        }