/// <summary> /// Save contact users /// </summary> private void SaveContactUser() { if (this.ContactId == 0) { return; } try { LPWeb.BLL.ContactUsers contactUsers = new LPWeb.BLL.ContactUsers(); //Remove contact user string sRemoveUserIDs = this.hdnRemoveUserID.Value; string[] removeUserIDArray = sRemoveUserIDs.Split(','); foreach (string sUserID in removeUserIDArray) { int iUserID = 0; if (!Int32.TryParse(sUserID, out iUserID)) { continue; } contactUsers.Delete(iUserID, this.ContactId); } //Add contact user string sAddUserIDs = this.hdnContactUserID.Value; string[] AddUserIDArray = sAddUserIDs.Split(','); foreach (string sUserID in AddUserIDArray) { int iUserID = 0; if (!Int32.TryParse(sUserID, out iUserID)) { continue; } LPWeb.Model.ContactUsers userModel = contactUsers.GetModel(iUserID, this.ContactId); if (userModel != null) { contactUsers.Update(userModel); } else { userModel = new LPWeb.Model.ContactUsers(); userModel.UserId = iUserID; userModel.ContactId = this.ContactId; userModel.Enabled = true; userModel.Created = DateTime.Now; contactUsers.Add(userModel); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// 获得数据列表 /// </summary> public List <LPWeb.Model.ContactUsers> DataTableToList(DataTable dt) { List <LPWeb.Model.ContactUsers> modelList = new List <LPWeb.Model.ContactUsers>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { LPWeb.Model.ContactUsers model; for (int n = 0; n < rowsCount; n++) { model = new LPWeb.Model.ContactUsers(); if (dt.Rows[n]["UserId"].ToString() != "") { model.UserId = int.Parse(dt.Rows[n]["UserId"].ToString()); } if (dt.Rows[n]["ContactId"].ToString() != "") { model.ContactId = int.Parse(dt.Rows[n]["ContactId"].ToString()); } if (dt.Rows[n]["Enabled"].ToString() != "") { if ((dt.Rows[n]["Enabled"].ToString() == "1") || (dt.Rows[n]["Enabled"].ToString().ToLower() == "true")) { model.Enabled = true; } else { model.Enabled = false; } } if (dt.Rows[n]["Created"].ToString() != "") { model.Created = DateTime.Parse(dt.Rows[n]["Created"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(LPWeb.Model.ContactUsers model) { dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public void Add(LPWeb.Model.ContactUsers model) { dal.Add(model); }