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); } } }
//同步 protected void Button1_Click(object sender, EventArgs e) { int selectCount = RGrid_EndUserList.SelectedItems.Count; if (selectCount == 0) { RadScriptManager.RegisterStartupScript(Page, GetType(), "c3", "OpenAlert('抱歉!您未选择任何项!!');", true); return; } Model.Log logModel = new Model.Log(); logModel.OperationItem = "批量同步终端用户"; logModel.Operator = user.UserInfo.UserID; logModel.OperationTime = DateTime.Now; int totCount = selectCount; StringBuilder notExist = new StringBuilder(""); bool isSyncMgUp = false; bool isSyncMgIn = false; try { StringBuilder sb = new StringBuilder("【"); StringBuilder sbU = new StringBuilder("【"); StringBuilder sbI = new StringBuilder("【"); List<MongoDBService.EndUser> euUpList = new List<MongoDBService.EndUser>(); List<MongoDBService.EndUser> euInList = new List<MongoDBService.EndUser>(); using (MongoDBServiceSoapClient mg = new MongoDBServiceSoapClient()) { foreach (GridDataItem item in RGrid_EndUserList.MasterTableView.Items) { if ((item["CheckboxSelectColumn"].Controls[0] as CheckBox).Checked) { String autoid = item["AutoID"].Text; sb.Append(autoid + " "); if (!eu.Exists(long.Parse(autoid))) { continue; } Model.EndUser euModel = eu.GetModel(long.Parse(autoid)); MongoDBService.EndUser dc = new MongoDBService.EndUser(); dc.AutoID = euModel.AutoID.ToString(); dc.EnduserName = euModel.EndUserName; string[] identityArr = euModel.Identities.Split('|'); ArrayOfString aof = new ArrayOfString(); foreach (string id in identityArr) { if (id.Equals("")) { continue; } aof.Add(id); } dc.Identities = aof; dc.IsValid = euModel.IsValid; dc.LastModifyTime = euModel.LastModifyTime; dc.SimCardNo = euModel.SimCardNo; string rtStrx = ""; if (mg.SelectEnduserBySimCardNo(euModel.SimCardNo, out rtStrx) != null) { sbU.Append(autoid + " "); euUpList.Add(dc); } else { sbI.Append(autoid + " "); euInList.Add(dc); } } } string info0 = ""; string info1 = ""; isSyncMgUp = true; if (euUpList.Count > 0) { string rtStr = ""; isSyncMgUp = false; isSyncMgUp = mg.UpdateEndusers(euUpList.ToArray(), out rtStr); if (isSyncMgUp) { info0 = "同步成功(更新)列表[" + euUpList.Count + "]:" + sbU.ToString(); } else { info0 = "同步成功(更新)列表[" + euUpList.Count + "]:无"; } logModel.Memo += "同步更新返回:" + rtStr; } isSyncMgIn = true; if (euInList.Count > 0) { string rtStr = ""; isSyncMgIn = false; isSyncMgIn = mg.InsertEndusers(euInList.ToArray(), out rtStr); if (isSyncMgIn) { info0 = "同步成功(新增)列表[" + euUpList.Count + "]:" + sbU.ToString(); } else { info0 = "同步成功(新增)列表[" + euUpList.Count + "]:无"; } logModel.Memo += "同步新增返回:" + rtStr; ; } sb.Append("】"); sbU.Append("】"); sbI.Append("】"); logModel.OperationDetail = "同步请求列表[" + totCount + "]:" + sb.ToString() + info0 + info1; } } catch (Exception ex) { logModel.Memo = "异常:" + ex.Message; } finally { if (isSyncMgUp && isSyncMgIn) { logModel.Memo = "成功"; log.Add(logModel); RadScriptManager.RegisterStartupScript(Page, GetType(), "c2", "OpenAlert('恭喜!同步成功!');", true); } else { logModel.Memo += "失败"; log.Add(logModel); RadScriptManager.RegisterStartupScript(Page, GetType(), "c3", "OpenAlert('抱歉!同步未完全成功!');", true); } } }
protected void RGrid_EndUserList_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "Del") { string AutoID = Convert.ToString(e.CommandArgument); bool isDelete = false; Model.Log logModel = new Model.Log(); logModel.OperationItem = "删除终端用户"; logModel.Operator = user.UserInfo.UserID; logModel.OperationTime = DateTime.Now; Model.EndUser euModel = eu.GetModel(long.Parse(AutoID)); try { if (euModel != null) { logModel.OperationDetail = "用户姓名:" + euModel.EndUserName + " - STB号:" + euModel.SimCardNo + " - 身份:" + euModel.Identities; using (MongoDBServiceSoapClient mg = new MongoDBServiceSoapClient()) { string rtStr = ""; bool isDeleteMg = true; if (mg.SelectEnduserBySimCardNo(euModel.SimCardNo, out rtStr) != null) { isDeleteMg = false; isDeleteMg = mg.DeleteEnduser(euModel.SimCardNo, out rtStr); } if (isDeleteMg) { isDelete = eu.Delete(long.Parse(AutoID)); } logModel.Memo += rtStr; } } } catch (Exception ex) { logModel.Memo = "异常:" + ex.Message; } finally { if (euModel != null) { log.Add(logModel); if (isDelete) { List<Model.EndUser> endUserList = (List<Model.EndUser>)ViewState["EndUserList"]; endUserList.RemoveAll(rt => rt.AutoID == long.Parse(AutoID)); RGrid_EndUserList.DataSource = endUserList; RGrid_EndUserList.Rebind(); RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "cc1", "OpenAlert('恭喜用户删除成功。');", true); } else { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "cc2", "OpenAlert('抱歉!用户删除失败。');", true); } } else { List<Model.EndUser> endUserList = (List<Model.EndUser>)ViewState["EndUserList"]; endUserList.RemoveAll(rt => rt.AutoID == long.Parse(AutoID)); RGrid_EndUserList.DataSource = endUserList; RGrid_EndUserList.DataBind(); ViewState["EndUserList"] = endUserList; RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "cc2", "OpenAlert('抱歉!用户删除失败。该用户已不存在!!');", true); } } } if (e.CommandName == "Sync") { string AutoID = Convert.ToString(e.CommandArgument); bool isSyncMg = false; Model.Log logModel = new Model.Log(); logModel.OperationItem = "同步终端用户"; logModel.Operator = user.UserInfo.UserID; logModel.OperationTime = DateTime.Now; Model.EndUser euModel = eu.GetModel(long.Parse(AutoID)); try { if (euModel != null) { logModel.OperationDetail = "用户姓名:" + euModel.EndUserName + " - STB号:" + euModel.SimCardNo + " - 身份:" + euModel.Identities; MongoDBService.EndUser dc = new MongoDBService.EndUser(); { dc.AutoID = euModel.AutoID.ToString(); dc.EnduserName = euModel.EndUserName; string[] identityArr = euModel.Identities.Split('|'); ArrayOfString aof = new ArrayOfString(); foreach (string id in identityArr) { if (id.Equals("")) { continue; } aof.Add(id); } dc.Identities = aof; dc.IsValid = euModel.IsValid; dc.LastModifyTime = euModel.LastModifyTime; dc.SimCardNo = euModel.SimCardNo; using (MongoDBServiceSoapClient mg = new MongoDBServiceSoapClient()) { string rtStr = ""; if (mg.SelectEnduserBySimCardNo(euModel.SimCardNo, out rtStr) != null) { isSyncMg = mg.UpdateEnduser(dc, out rtStr); } else { isSyncMg = mg.InsertEnduser(dc, out rtStr); } logModel.Memo += rtStr; } } } } catch (Exception ex) { logModel.Memo = "异常:" + ex.Message; } finally { if (euModel != null) { log.Add(logModel); if (isSyncMg) { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "cc1", "OpenAlert('恭喜用户同步成功。');", true); } else { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "cc2", "OpenAlert('抱歉!用户同步失败。');", true); } } else { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "cc2", "OpenAlert('抱歉!用户同步失败。该用户本地已不存在!!');", true); } } } }
protected void Bt_Modify_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; } Model.Log logModel = new Model.Log(); logModel.OperationItem = "修改终端用户"; logModel.OperationTime = DateTime.Now; logModel.Operator = user.UserInfo.UserID; logModel.Memo = ""; Model.EndUser euModel = eu.GetModel(AutoID); if (euModel == null) { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c", "OpenAlert('抱歉!该用户已不存在!');", true); return; } euModel.EndUserName = RTB_Name.Text; euModel.SimCardNo = RTB_SIM.Text; euModel.LastModifyTime = DateTime.Now; euModel.IsValid = RCB_Enable.SelectedValue=="1" ? true : false; 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; bool isUpdate = false; try { using (MongoDBServiceSoapClient mg = new MongoDBServiceSoapClient()) { MongoDBService.EndUser dc = new MongoDBService.EndUser(); dc.AutoID = euModel.AutoID.ToString(); dc.EnduserName = euModel.EndUserName; string[] identityArr = euModel.Identities.Split('|'); ArrayOfString aof = new ArrayOfString(); foreach (string id in identityArr) { if (id.Equals("")) { continue; } aof.Add(id); } dc.Identities = aof; dc.IsValid = euModel.IsValid; dc.LastModifyTime = euModel.LastModifyTime; dc.SimCardNo = euModel.SimCardNo; string rtStr = ""; if (mg.UpdateEnduser(dc, out rtStr)) { isUpdate = eu.Update(euModel); } } } catch (Exception ex) { logModel.Memo += ex.Message; } finally { if (euModel != null) { log.Add(logModel); if (isUpdate) { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c", "OpenAlert('恭喜!用户修改成功!');", true); } else { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c", "OpenAlert('抱歉!用户修改失败!');", true); } } else { RadScriptManager.RegisterStartupScript(this.Page, this.GetType(), "c", "OpenAlert('抱歉!用户修改失败,已不存在该用户!');", true); } } }