/// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.EndUser DataRowToModel(DataRow row)
 {
     Model.EndUser model = new Model.EndUser();
     if (row != null)
     {
         if (row["AutoID"] != null && row["AutoID"].ToString() != "")
         {
             model.AutoID = long.Parse(row["AutoID"].ToString());
         }
         if (row["EndUserName"] != null)
         {
             model.EndUserName = row["EndUserName"].ToString();
         }
         if (row["SimCardNo"] != null)
         {
             model.SimCardNo = row["SimCardNo"].ToString();
         }
         if (row["Identities"] != null)
         {
             model.Identities = row["Identities"].ToString();
         }
         if (row["LastModifyTime"] != null && row["LastModifyTime"].ToString() != "")
         {
             model.LastModifyTime = DateTime.Parse(row["LastModifyTime"].ToString());
         }
         if (row["IsValid"] != null && row["IsValid"].ToString() != "")
         {
             if ((row["IsValid"].ToString() == "1") || (row["IsValid"].ToString().ToLower() == "true"))
             {
                 model.IsValid = true;
             }
             else
             {
                 model.IsValid = false;
             }
         }
     }
     return model;
 }
Beispiel #2
0
 protected void SubmitBtn_Click(object sender, EventArgs e)
 {
     if (RCB_Identity.CheckedItems.Count == 0)
     {
         RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c1", "OpenAlert('身份选择不能为空!');", true);
         return;
     }
     RadTreeView regionTreeView = RadDropDownTree1.Controls[0] as RadTreeView;
     if (regionTreeView.SelectedNodes.Count==0)
     {
         RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c1", "OpenAlert('区域选择不能为空!');", true);
         return;
     }
     if (RTB_Name.Text.Trim().Equals(""))
     {
         RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c1", "OpenAlert('用户姓名不能为空!');", true);
         return;
     }
     if (RTB_SIM.Text.Trim().Equals(""))
     {
         RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c1", "OpenAlert('STB号不能为空!');", true);
         return;
     }
     Model.Log logModel = new Model.Log();
     logModel.OperationItem = "添加终端用户";
     logModel.OperationTime = DateTime.Now;
     logModel.Operator = user.UserInfo.UserID;
     logModel.Memo = "";
     Model.EndUser euModel = new Model.EndUser();
     euModel.EndUserName = RTB_Name.Text;
     euModel.SimCardNo = RTB_SIM.Text;
     euModel.LastModifyTime = DateTime.Now;
     euModel.IsValid = true;
     StringBuilder sb = new StringBuilder();
     foreach (RadComboBoxItem rcbi in RCB_Identity.CheckedItems)
     {
         sb.Append("|"+rcbi.Value + "|");
     }
     sb.Append("|" + regionTreeView.SelectedValue + "|");
     string identityStr = sb.ToString();
     logModel.OperationDetail = "姓名:"+RTB_Name.Text+"SIM:"+RTB_SIM.Text+"身份&区域:"+identityStr;
     euModel.Identities = identityStr;
     long autoid = 0;
     try
     {
         autoid = eu.Add(euModel);
         if (autoid > 0)
         {
             using (MongoDBServiceSoapClient mg = new MongoDBServiceSoapClient())
             {
                 MongoDBService.EndUser dc = new MongoDBService.EndUser();
                 bool IsAddMg = true;
                 string rtStr = "";
                 if (mg.SelectEnduserBySimCardNo(euModel.SimCardNo, out rtStr) == null)
                 {
                     IsAddMg = false;
                     dc.AutoID = autoid.ToString();
                     dc.EnduserName = euModel.EndUserName;
                     string[] identityArr = euModel.Identities.Split('|');
                     ArrayOfString aof = new ArrayOfString();
                     foreach (string id in identityArr)
                     {
                         if (id.Trim().Equals(""))
                         {
                             continue;
                         }
                         aof.Add(id);
                     }
                     dc.Identities = aof;
                     dc.IsValid = true;
                     dc.LastModifyTime = euModel.LastModifyTime;
                     dc.SimCardNo = euModel.SimCardNo;
                     IsAddMg = mg.InsertEnduser(dc, out rtStr);
                 }
                 if (!IsAddMg)
                 {
                     eu.Delete(autoid);
                     autoid = 0;
                 }
                 logModel.Memo += rtStr;
             }
         }
     }
     catch (Exception ex)
     {
         autoid = 0;
         logModel.Memo += ex.Message;
     }
     finally
     {
         log.Add(logModel);
         if (autoid > 0)
         {
             RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c", "OpenAlert('恭喜!用户添加成功!');", true);
         }
         else
         {
             RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c", "OpenAlert('抱歉!用户添加失败!');", true);
         }
     }
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.EndUser GetModel(long AutoID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AutoID,EndUserName,SimCardNo,Identities,LastModifyTime,IsValid from EndUser");
            strSql.Append(" where AutoID=@AutoID limit 1");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@AutoID", MySqlDbType.Int64)
            };
            parameters[0].Value = AutoID;

            Model.EndUser model = new Model.EndUser();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }