/// <summary>
 /// 得到一个对象实体
 /// </summary>
 public SchSystem.Model.ServUserForExt DataRowToModel(DataRow row)
 {
     SchSystem.Model.ServUserForExt model = new SchSystem.Model.ServUserForExt();
     if (row != null)
     {
         if (row["AutoId"] != null && row["AutoId"].ToString() != "")
         {
             model.AutoId = int.Parse(row["AutoId"].ToString());
         }
         if (row["UserForId"] != null && row["UserForId"].ToString() != "")
         {
             model.UserForId = int.Parse(row["UserForId"].ToString());
         }
         if (row["Fcode"] != null)
         {
             model.Fcode = row["Fcode"].ToString();
         }
         if (row["NapeCode"] != null)
         {
             model.NapeCode = row["NapeCode"].ToString();
         }
         if (row["NapeCodes"] != null)
         {
             model.NapeCodes = row["NapeCodes"].ToString();
         }
     }
     return(model);
 }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(SchSystem.Model.ServUserForExt model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ServUserForExt(");
            strSql.Append("UserForId,Fcode,NapeCode,NapeCodes)");
            strSql.Append(" values (");
            strSql.Append("@UserForId,@Fcode,@NapeCode,@NapeCodes)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserForId", SqlDbType.Int,      4),
                new SqlParameter("@Fcode",     SqlDbType.VarChar, 20),
                new SqlParameter("@NapeCode",  SqlDbType.VarChar, 10),
                new SqlParameter("@NapeCodes", SqlDbType.VarChar, 200)
            };
            parameters[0].Value = model.UserForId;
            parameters[1].Value = model.Fcode;
            parameters[2].Value = model.NapeCode;
            parameters[3].Value = model.NapeCodes;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SchSystem.Model.ServUserForExt model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ServUserForExt set ");
            strSql.Append("UserForId=@UserForId,");
            strSql.Append("Fcode=@Fcode,");
            strSql.Append("NapeCode=@NapeCode,");
            strSql.Append("NapeCodes=@NapeCodes");
            strSql.Append(" where AutoId=@AutoId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserForId", SqlDbType.Int,       4),
                new SqlParameter("@Fcode",     SqlDbType.VarChar,  20),
                new SqlParameter("@NapeCode",  SqlDbType.VarChar,  10),
                new SqlParameter("@NapeCodes", SqlDbType.VarChar, 200),
                new SqlParameter("@AutoId",    SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserForId;
            parameters[1].Value = model.Fcode;
            parameters[2].Value = model.NapeCode;
            parameters[3].Value = model.NapeCodes;
            parameters[4].Value = model.AutoId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SchSystem.Model.ServUserForExt GetModel(int AutoId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 AutoId,UserForId,Fcode,NapeCode,NapeCodes from ServUserForExt ");
            strSql.Append(" where AutoId=@AutoId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AutoId", SqlDbType.Int, 4)
            };
            parameters[0].Value = AutoId;

            SchSystem.Model.ServUserForExt model = new SchSystem.Model.ServUserForExt();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
 public static Com.DataPack.DataRsp <string> UserOrderAddSave(List <string> arr)
 {
     Com.DataPack.DataRsp <string> rsp = new Com.DataPack.DataRsp <string>();
     if (Com.Session.userid == null)
     {
         rsp.code = "expire";
         rsp.msg  = "你现在登录已过期,请重新登录!";
     }
     else
     {
         string orderpackagestr = "";
         try
         {
             SchSystem.BLL.ServUserFor   sufBll   = new SchSystem.BLL.ServUserFor();
             SchSystem.Model.ServUserFor sufModel = new SchSystem.Model.ServUserFor();
             foreach (string str in arr)
             {
                 string[] strarr = str.Split('#');
                 if (strarr[0] == "account")
                 {
                     sufModel.UserName = strarr[1];
                 }
                 else if (strarr[0] == "additional")
                 {
                     sufModel.RecUser = strarr[1];
                 }
                 else if (strarr[0] == "usersource")
                 {
                     sufModel.FromType = strarr[1];
                 }
                 else if (strarr[0] == "tagsorderpackage")
                 {
                     sufModel.ServiceId = strarr[1];
                 }
                 else if (strarr[0] == "orderlength")
                 {
                     sufModel.ServMonth = int.Parse(strarr[1]);
                 }
                 else if (strarr[0] == "payamount")
                 {
                     sufModel.FeeM = int.Parse(strarr[1]);
                 }
                 else if (strarr[0] == "note")
                 {
                     sufModel.DoNote = strarr[1];
                 }
                 else if (strarr[0] == "orderpackagestr")
                 {
                     orderpackagestr = strarr[1];
                 }
             }
             bool Exists = sufBll.Exists(sufModel.UserName, sufModel.ServiceId);
             if (Exists)
             {
                 rsp.code = "success";
                 rsp.msg  = "该套餐已存在,请到续费处续费";
             }
             else
             {
                 int result = sufBll.ProcAdd(sufModel.UserName, sufModel.RecUser, sufModel.FromType, sufModel.ServiceId, sufModel.ServMonth, sufModel.FeeM, sufModel.DoNote);
                 if (result > 0)
                 {
                     SchSystem.BLL.ServUserForExt   sufeBll   = new SchSystem.BLL.ServUserForExt();
                     SchSystem.Model.ServUserForExt sufeModel = new SchSystem.Model.ServUserForExt();
                     if (!string.IsNullOrEmpty(orderpackagestr))
                     {
                         string[] orderpackagearr    = orderpackagestr.Split('$');
                         int      orderpackagearrLen = orderpackagearr.Length;
                         for (int i = 0; i < orderpackagearrLen; i++)//遍歷實體(記錄)
                         {
                             string[] ordpackarr    = orderpackagearr[i].Split('|');
                             int      ordpackarrlen = ordpackarr.Length;
                             sufeModel.UserForId = result;        //遍歷屬性(字段):對應的訂購ID
                             sufeModel.Fcode     = ordpackarr[0]; //遍歷屬性(字段):功能碼
                             sufeModel.NapeCode  = ordpackarr[1]; //遍歷屬性(字段):下拉列表代碼
                             sufeModel.NapeCodes = ordpackarr[2]; //遍歷屬性(字段):對應的下拉列表代碼串
                             if ((sufeModel.NapeCodes).ToString() != "null")
                             {
                                 sufeBll.Add(sufeModel);
                             }
                         }
                     }
                     rsp.code = "success";
                     rsp.msg  = "添加成功";
                 }
                 else
                 {
                     rsp.code = "error";
                     rsp.msg  = "操作失败";
                 }
             }
         }
         catch (Exception ex)
         {
             rsp.code = "excepError";
             rsp.msg  = ex.Message;
         }
     }
     return(rsp);
 }