项目需求:通过ISBN生成书号表

版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!


恰饭广告




需求描述:

通过ISBN号生成书号,生成规则为:“ISBN号去掉开头的978三位数,获取到一个10位的字符串,如果ISBN已经为10位就不需要去掉开头三位数,在此字符串后加入8位流水号,从00000001开始”。

源码:(可优化)

        private DataTable addBookId()
        {
            //ViewState["i"]为最新书号
            excel = excelToDt();
            int row = excel.Rows.Count;
            string a;
            if (ViewState["i"].ToString().Length>=18)
            {
                a = ViewState["i"].ToString().Substring(10, 8);
            }
            else
            {
                a = "0";
            }
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn("书号");
            dt.Columns.Add(dc);
            DataRow dataRow = null;
            string bookId;
            for (int i = 0; i < row; i++)
            {
                a=(Convert.ToInt32(a)+1).ToString();
                ViewState["i"] = a;
                string ss = a.PadLeft(8, '0');
                string isbn = excel.Rows[i]["ISBN"].ToString();
                int count = isbn.Length;
                if (count >= 13) //大于13位书号
                {
                    bookId = isbn.Substring(3, 10);
                    bookId = bookId + ss;
                }
                else
                {
                    bookId = isbn + ss;
                }
                dataRow = dt.NewRow();
                dataRow["书号"] = bookId;
                dt.Rows.Add(bookId);
            }
    
            DataRow dr_last = dataRow;
            last = dr_last["书号"].ToString();
            return UniteDataTable(dt, excel);
        }

原文链接:https://www.idaobin.com/archives/1995.html

让我恰个饭吧.ヘ( ̄ω ̄ヘ)

支付宝 ——————- 微信
图片加载中图片加载中



恰饭广告

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

7 × = 7