Beispiel #1
0
        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);
         }
     }
 }