コード例 #1
0
ファイル: ImportGoods2.aspx.cs プロジェクト: kkwkk/ybyzt
    /// <summary>
    /// 获取商品编码并更新数据库最新单据值
    /// </summary>
    /// <returns></returns>
    public string GoodsCode(SqlTransaction Tran)
    {
        List <Hi.Model.SYS_SysCode> l = new Hi.BLL.SYS_SysCode().GetList("top 1 *", "isnull(dr,0)=0 and compId=" + this.CompID + " and codeName='P" + this.CompID + "'", " codevalue desc", Tran);

        if (l.Count > 0)
        {
            l[0].CodeValue  = (l[0].CodeValue.ToInt(0) + 1).ToString();
            l[0].ts         = DateTime.Now;
            l[0].modifyuser = this.UserID;
            new Hi.BLL.SYS_SysCode().Update(l[0], Tran);
            return(l[0].CodeName + l[0].CodeValue.PadLeft(6, '0'));
        }
        else
        {
            Hi.Model.SYS_SysCode model5 = new Hi.Model.SYS_SysCode();
            model5.CompID     = this.CompID;
            model5.CodeName   = "P" + this.CompID;
            model5.CodeValue  = "1";
            model5.ts         = DateTime.Now;
            model5.dr         = 0;
            model5.modifyuser = this.UserID;
            new Hi.BLL.SYS_SysCode().Add(model5, Tran);
            return("P" + this.CompID + "1".PadLeft(6, '0'));
        }
    }
コード例 #2
0
ファイル: SysCode.cs プロジェクト: kkwkk/ybyzt
    /// <summary>
    /// 获得最新Code
    /// </summary>
    /// <param name="Name"></param>
    /// <returns></returns>
    public static string GetNewCode(string strName)
    {
        string returnstr = "";

        try
        {
            List <Hi.Model.SYS_SysName> NameModel = new Hi.BLL.SYS_SysName().GetList("", "CompID=0 and Name='" + strName + "'", "");
            if (NameModel != null)
            {
                //string OrgCode = ConfigurationManager.AppSettings["OrgCode"] == null ? "" : ConfigurationManager.AppSettings["OrgCode"].ToString().Trim() + "-";
                //string value = NameModel[0].Value;
                string yyyy = DateTime.Today.Year.ToString().PadLeft(4, '0');
                string mm   = DateTime.Today.Month.ToString().PadLeft(2, '0');
                string dd   = DateTime.Today.Day.ToString().PadLeft(2, '0');

                string codeName = string.Empty;

                codeName = yyyy + mm + dd;

                List <Hi.Model.SYS_SysCode> CodeModel = new Hi.BLL.SYS_SysCode().GetList("", "CompID=0 and CodeName='" + codeName + "'", "");
                if (CodeModel.Count > 0)
                {
                    int    codeValue  = Convert.ToInt32(CodeModel[0].CodeValue);
                    int    newCode    = codeValue + 1;
                    string newCodeStr = "";

                    newCodeStr = codeName + "-" + newCode.ToString().PadLeft(6, '0');
                    //returnstr = OrgCode + value + "-" + newCodeStr;
                    returnstr = "MD-" + newCodeStr;

                    //修改最新值
                    SqlHelper.ExecuteSql(SqlHelper.LocalSqlServer, "update SYS_SysCode set CodeValue=" + newCode + " where CodeName='" + codeName + "'");
                }
                else
                {
                    string newCodeStr = "";
                    newCodeStr = codeName + "-000001";

                    //returnstr = OrgCode + value + "-" + newCodeStr;
                    returnstr = "MD-" + newCodeStr;
                    //插入数据
                    SqlHelper.ExecuteSql(SqlHelper.LocalSqlServer, "insert into SYS_SysCode(CompID,CodeName,CodeValue,ts,modifyuser) values(0,'" + codeName + "',1,'" + DateTime.Now + "',0)");
                }
            }
        }
        catch { }
        return(returnstr);
    }