预览
代码
手机端效果
frmConcent.cs
frmConcent.Designer.cs
模板类frmUserLayout1.cs
模板类frmUserLayout1.Designer.cs
模板类frmGroupLayout.cs
模板类frmGroupLayout.Designer.cs
frmAddConcentOrGroup.cs
frmAddConcentOrGroup.Designer.cs
模板类frmAddUser1Layout.cs
模板类frmAddUser1Layout.Designer.cs
模板类frmAddUserLayout.cs
模板类frmAddUserLayout.Designer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using Smobiler.Plugins.RongIM;
using SmoONE.DTOs;
using SmoONE.UI.Layout;
namespace SmoONE.UI.Im
{
partial class frmConcent : Smobiler.Core.Controls.MobileForm
{
#region "definition"
AutofacConfig AutofacConfig = new AutofacConfig();//调用配置类
/// <summary>
/// key和Secret请去融云注册应用:http://www.rongcloud.cn/
/// </summary>
string key = "";//融云应用KEY
string secret = "";//融云应用Secret
#endregion
/// <summary>
/// 初始化
/// </summary>
private void InitialIM()
{
im1.InitialInstance(key, secret);//初始化
if (System.String.IsNullOrEmpty(im1.Token) == true)
{
string tokenuser = Client.Session["U_ID"].ToString();
if (System.String.IsNullOrEmpty(tokenuser) == false)
{
//在融云用户初始化,如若报“toke失效”请去融云中查看token是否失效
UserDetails userDetails = new UserDetails();
UserDetailDto userDetailDto = userDetails.getUser(tokenuser);
string portraitUri = "";
if (userDetailDto != null)
{
portraitUri =System.IO.Path.Combine( MobileResourceManager.DefaultImagePath , userDetailDto.U_Portrait);
}
im1.InitialToken(tokenuser, tokenuser, portraitUri);
}
else
{
MessageBox.Show("TokenUser Not Be NullOrEmpty!");
}
}
else
{
im1.InitialToken();
}
}
private void segmentedControl1_SelectedIndexChanged(object sender, EventArgs e)
{
tabPageView1 .PageIndex =segmentedControl1.SelectedIndex;
Bind();
}
private void frmConcent_Load(object sender, EventArgs e)
{
InitialIM();
tabPageView1.Controls.Add(listContact);
tabPageView1.Controls.Add(listGroup);
Bind();
}
public void Bind()
{
try
{
switch (segmentedControl1.SelectedIndex)
{
case 0:
lblAdd.Text = "添加联系人";
//读取数据库,获取当前用户联系人
List<ContactDto> listContactDto = AutofacConfig.contactService .GetByCreateUsers(Client.Session["U_ID"].ToString());
listContact.Rows.Clear();
if (listContactDto.Count >0)
{
List<UserDetailDto> listuser = new List<UserDetailDto>();
foreach (ContactDto contact in listContactDto)
{
UserDetails userDetails = new UserDetails();
UserDetailDto user = userDetails.getUser(contact.C_USER);
if (user != null)
{
listuser.Add(user);
}
}
listContact.DataSource = listuser;
listContact.DataBind();
}
break;
case 1:
lblAdd.Text = "创建群组";
//读取数据库,获取当前用户群组
List<CGroupDto> listCGroupDto = AutofacConfig.cGroupService.GetByCreateUsers(Client.Session["U_ID"].ToString());
listGroup.Rows.Clear();
if (listCGroupDto.Count > 0)
{
listGroup.DataSource = listCGroupDto;
listGroup.DataBind();
}
break;
}
}
catch(Exception ex)
{
Toast(ex.Message, ToastLength.SHORT);
}
}
/// <summary>
/// 调用聊天列表
/// </summary>
public void getchatMsg()
{
im1.StartConversationList();
}
private void im1_LoadGroupInfo(object sender, IMLoadGroupInfoArgs e)
{
IMGroupEntry group = new IMGroupEntry();
CGroupDto CGroupDto = AutofacConfig.cGroupService.GetByID(e.GroupId);
group.GroupID = e.GroupId;
if (CGroupDto != null)
{
group.GroupName = CGroupDto.G_NAME;
}
group.PortraitUri = System.IO.Path.Combine(MobileResourceManager.DefaultImagePath, "group.PNG");
e.Result = group;
}
private void im1_LoadUserInfo(object sender, IMLoadUserInfoArgs e)
{
IMUserEntry user = new IMUserEntry();
UserDetails userDetails = new UserDetails();
UserDetailDto userDetailDto = userDetails.getUser(e.UserId);
user.UserID = e.UserId;
if (userDetailDto != null)
{
user.UserName = userDetailDto.U_Name;
// user.PortraitUri = ".\\Image\\" + userDetailDto.U_Portrait + ".PNG";
user.PortraitUri = System.IO.Path.Combine(MobileResourceManager.DefaultImagePath, userDetailDto.U_Portrait);
}
//返回IMUserEntry
e.Result = user;
}
private void im1_LoadGroupMembers(object sender, IMLoadGroupMembersArgs e)
{
CGroupDto CGroupDto = AutofacConfig.cGroupService.GetByID(e.GroupId );
string[] groupusers ;
if (CGroupDto!=null )
{
groupusers = CGroupDto.G_USER.Split(',');
}
else
{
groupusers = new String[1];
}
e.Result =groupusers;
}
private void im1_TokenExpired(object sender, IMTokenExpiredArgs e)
{
if (im1 != null && System.String.IsNullOrEmpty(e.UserId ) == false)
{
//重置当前的用户Token
// im1.Token = im1.GetUserToken(userid, userid, ".\\Image\\" + userid + ".PNG");
//返回Token
e.Result = im1.Token;
}
else
{
e.Result = "";
}
}
/// <summary>
/// 添加联系人或群组
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pAdd_Press(object sender, EventArgs e)
{
frmAddConcentOrGroup frm = new frmAddConcentOrGroup(im1);
switch (segmentedControl1.SelectedIndex)
{
case 0:
frm.ctype = ConcentState.Concent;
break;
case 1:
frm.ctype = ConcentState.Group;
break;
}
Show(frm, (MobileForm form, object args) =>
{
if (frm.ShowResult == ShowResult.Yes)
{
ShowResult = ShowResult.Yes;
Bind();
}
});
}
private void tabPageView1_PageIndexChanged(object sender, EventArgs e)
{
segmentedControl1.SelectedIndex = tabPageView1.PageIndex;
Bind();
}
private void toolBar1_ToolbarItemClick(object sender, ToolbarClickEventArgs e)
{
if (e.Name .Equals ("msg"))
{
getchatMsg();
}
}
/// <summary>
/// 提示未读消息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void im1_UnReadMessage(object sender, IMUnReadMessageArgs e)
{
Toast("当前有未读消息"+e.UnReadMsgCount.ToString()+"条");
}
}
}
using System;
using Smobiler.Core;
namespace SmoONE.UI.Im
{
partial class frmConcent : Smobiler.Core.Controls.MobileForm
{
#region "SmobilerForm generated code "
public frmConcent()
: base()
{
//This call is required by the SmobilerForm.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//SmobilerForm overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerForm
//It can be modified using the SmobilerForm.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
Smobiler.Core.Controls.ToolBarItem toolBarItem1 = new Smobiler.Core.Controls.ToolBarItem();
Smobiler.Core.Controls.ToolBarItem toolBarItem2 = new Smobiler.Core.Controls.ToolBarItem();
this.title1 = new SmoONE.UI.Layout.Title();
this.segmentedControl1 = new Smobiler.Core.Controls.SegmentedControl();
this.listContact = new Smobiler.Core.Controls.ListView();
this.listGroup = new Smobiler.Core.Controls.ListView();
this.pAdd = new Smobiler.Core.Controls.Panel();
this.label1 = new Smobiler.Core.Controls.Label();
this.lblAdd = new Smobiler.Core.Controls.Label();
this.toolBar1 = new Smobiler.Core.Controls.ToolBar();
this.tabPageView1 = new Smobiler.Core.Controls.TabPageView();
this.im1 = new Smobiler.Plugins.RongIM.IM();
//
// title1
//
this.title1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(242)))));
this.title1.Direction = Smobiler.Core.Controls.LayoutDirection.Row;
this.title1.Dock = System.Windows.Forms.DockStyle.Top;
this.title1.Name = "title1";
this.title1.Size = new System.Drawing.Size(100, 50);
this.title1.TitleText = "IM";
//
// segmentedControl1
//
this.segmentedControl1.Items = new string[] {
"联系人",
"群组"};
this.segmentedControl1.Location = new System.Drawing.Point(0, 50);
this.segmentedControl1.Name = "segmentedControl1";
this.segmentedControl1.SegmentedBorderRadius = 0;
this.segmentedControl1.SelectedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(146)))), ((int)(((byte)(223)))));
this.segmentedControl1.SelectedColor = System.Drawing.Color.White;
this.segmentedControl1.Size = new System.Drawing.Size(300, 35);
this.segmentedControl1.UnSelectedBackColor = System.Drawing.Color.White;
this.segmentedControl1.UnSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(146)))), ((int)(((byte)(223)))));
this.segmentedControl1.SelectedIndexChanged += new System.EventHandler(this.segmentedControl1_SelectedIndexChanged);
//
// listContact
//
this.listContact.BackColor = System.Drawing.Color.White;
this.listContact.Name = "listContact";
this.listContact.PageSize = 8;
this.listContact.PageSizeTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(145)))), ((int)(((byte)(145)))), ((int)(((byte)(145)))));
this.listContact.ShowSplitLine = true;
this.listContact.Size = new System.Drawing.Size(300, 355);
this.listContact.SplitLineColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.listContact.TemplateControlName = "frmUserLayout1";
//
// listGroup
//
this.listGroup.BackColor = System.Drawing.Color.White;
this.listGroup.Name = "listGroup";
this.listGroup.PageSize = 8;
this.listGroup.PageSizeTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(145)))), ((int)(((byte)(145)))), ((int)(((byte)(145)))));
this.listGroup.ShowSplitLine = true;
this.listGroup.Size = new System.Drawing.Size(300, 355);
this.listGroup.SplitLineColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.listGroup.TemplateControlName = "frmGroupLayout";
//
// pAdd
//
this.pAdd.BackColor = System.Drawing.Color.White;
this.pAdd.Border = new Smobiler.Core.Controls.Border(0F, 0F, 0F, 1F);
this.pAdd.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.pAdd.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.label1,
this.lblAdd});
this.pAdd.Direction = Smobiler.Core.Controls.LayoutDirection.Row;
this.pAdd.Layout = Smobiler.Core.Controls.LayoutPosition.Relative;
this.pAdd.Location = new System.Drawing.Point(0, 85);
this.pAdd.Name = "pAdd";
this.pAdd.Size = new System.Drawing.Size(300, 35);
this.pAdd.Touchable = true;
this.pAdd.Press += new System.EventHandler(this.pAdd_Press);
//
// label1
//
this.label1.Bold = true;
this.label1.FontSize = 30F;
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(44)))), ((int)(((byte)(44)))));
this.label1.Name = "label1";
this.label1.Padding = new Smobiler.Core.Controls.Padding(4F, 0F, 0F, 0F);
this.label1.Size = new System.Drawing.Size(30, 0);
this.label1.Text = "+";
//
// lblAdd
//
this.lblAdd.Flex = 1;
this.lblAdd.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(44)))), ((int)(((byte)(44)))));
this.lblAdd.Name = "lblAdd";
this.lblAdd.Size = new System.Drawing.Size(0, 0);
this.lblAdd.Text = "添加联系人";
//
// toolBar1
//
this.toolBar1.BackColor = System.Drawing.Color.White;
toolBarItem1.IconID = "lianxiren";
toolBarItem1.Name = "contact";
toolBarItem1.SelectIconID = "lianxiren";
toolBarItem2.IconID = "xiaoxi";
toolBarItem2.Name = "msg";
toolBarItem2.SelectIconID = "xiaoxi";
this.toolBar1.Items.AddRange(new Smobiler.Core.Controls.ToolBarItem[] {
toolBarItem1,
toolBarItem2});
this.toolBar1.Location = new System.Drawing.Point(0, 457);
this.toolBar1.Name = "toolBar1";
this.toolBar1.SelectBackColor = System.Drawing.Color.White;
this.toolBar1.SelectedIndex = 0;
this.toolBar1.SelectForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(146)))), ((int)(((byte)(223)))));
this.toolBar1.Size = new System.Drawing.Size(100, 50);
this.toolBar1.ToolbarItemClick += new Smobiler.Core.Controls.ToolbarItemClickEventHandler(this.toolBar1_ToolbarItemClick);
//
// tabPageView1
//
this.tabPageView1.BackColor = System.Drawing.Color.White;
this.tabPageView1.Location = new System.Drawing.Point(0, 120);
this.tabPageView1.Name = "tabPageView1";
this.tabPageView1.Size = new System.Drawing.Size(300, 330);
this.tabPageView1.PageIndexChanged += new System.EventHandler(this.tabPageView1_PageIndexChanged);
//
// im1
//
this.im1.Name = "im1";
this.im1.LoadUserInfo += new Smobiler.Plugins.RongIM.IMLoadUserInfoHandler(this.im1_LoadUserInfo);
this.im1.LoadGroupInfo += new Smobiler.Plugins.RongIM.IMLoadGroupInfoHandler(this.im1_LoadGroupInfo);
this.im1.LoadGroupMembers += new Smobiler.Plugins.RongIM.IMLoadGroupMembersHandler(this.im1_LoadGroupMembers);
this.im1.TokenExpired += new Smobiler.Plugins.RongIM.IMTokenExpiredHandler(this.im1_TokenExpired);
this.im1.UnReadMessage += new Smobiler.Plugins.RongIM.IMUnReadMessageHandler(this.im1_UnReadMessage);
//
// frmConcent
//
this.Components.AddRange(new Smobiler.Core.Controls.MobileComponent[] {
this.im1});
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.title1,
this.segmentedControl1,
this.pAdd,
this.toolBar1,
this.tabPageView1});
this.Orientation = Smobiler.Core.Controls.FormOrientation.Portrait;
this.Load += new System.EventHandler(this.frmConcent_Load);
this.Name = "frmConcent";
}
#endregion
private Layout.Title title1;
private Smobiler.Core.Controls.SegmentedControl segmentedControl1;
private Smobiler.Core.Controls.ListView listContact;
private Smobiler.Core.Controls.ListView listGroup;
private Smobiler.Core.Controls.Panel pAdd;
private Smobiler.Core.Controls.ToolBar toolBar1;
private Smobiler.Core.Controls.TabPageView tabPageView1;
private Smobiler.Core.Controls.Label label1;
private Smobiler.Core.Controls.Label lblAdd;
public Smobiler.Plugins.RongIM.IM im1;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using Smobiler.Plugins.RongIM;
namespace SmoONE.UI.Layout
{
//发起聊天模板
////ToolboxItem用于控制是否添加自定义控件到工具箱,true添加,false不添加
//[System.ComponentModel.ToolboxItem(true)]
partial class frmUserLayout1 : Smobiler.Core.Controls.MobileUserControl
{
/// <summary>
/// 用户聊天
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tpUser_Press(object sender, EventArgs e)
{
try
{
//在联系人模板中调用im用户聊天
if (((SmoONE.UI.Im .frmConcent)this.Form).im1 != null)
{
((SmoONE.UI.Im.frmConcent)this.Form).im1.StartPrivateChat(lblUser .BindDataValue .ToString (), lblUser.BindDisplayValue.ToString());
}
}
catch (Exception ex)
{
this.Form.Toast(ex.Message);
}
}
}
}
using System;
using Smobiler.Core;
namespace SmoONE.UI.Layout
{
partial class frmUserLayout1 : Smobiler.Core.Controls.MobileUserControl
{
#region "SmobilerUserControl generated code "
public frmUserLayout1()
: base()
{
//This call is required by the SmobilerUserControl.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//SmobilerUserControl overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerUserControl
//It can be modified using the SmobilerUserControl.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.tpUser = new Smobiler.Core.Controls.Panel();
this.imgPortrait = new Smobiler.Core.Controls.Image();
this.lblUser = new Smobiler.Core.Controls.Label();
//
// tpUser
//
this.tpUser.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.imgPortrait,
this.lblUser});
this.tpUser.Name = "tpUser";
this.tpUser.Size = new System.Drawing.Size(300, 50);
this.tpUser.Touchable = true;
this.tpUser.Press += new System.EventHandler(this.tpUser_Press);
//
// imgPortrait
//
this.imgPortrait.BorderRadius = 18;
this.imgPortrait.DataMember = "U_Portrait";
this.imgPortrait.DisplayMember = "U_Portrait";
this.imgPortrait.Location = new System.Drawing.Point(4, 7);
this.imgPortrait.Name = "imgPortrait";
this.imgPortrait.Size = new System.Drawing.Size(36, 36);
this.imgPortrait.SizeMode = Smobiler.Core.Controls.ImageSizeMode.Cover;
//
// lblUser
//
this.lblUser.DataMember = "U_ID";
this.lblUser.DisplayMember = "U_Name";
this.lblUser.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(45)))));
this.lblUser.Location = new System.Drawing.Point(47, 0);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(253, 50);
//
// frmUserLayout1
//
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.tpUser});
this.Size = new System.Drawing.Size(0, 50);
this.Name = "frmUserLayout1";
}
#endregion
private Smobiler.Core.Controls.Panel tpUser;
private Smobiler.Core.Controls.Image imgPortrait;
private Smobiler.Core.Controls.Label lblUser;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using Smobiler.Plugins.RongIM;
namespace SmoONE.UI.Layout
{
//发起群聊模板
////ToolboxItem用于控制是否添加自定义控件到工具箱,true添加,false不添加
//[System.ComponentModel.ToolboxItem(true)]
partial class frmGroupLayout : Smobiler.Core.Controls.MobileUserControl
{
#region "definition"
AutofacConfig AutofacConfig = new AutofacConfig();//调用配置类
#endregion
//public frmGroupLayout(IM im):this()
//{
// im1 = im;
//}
/// <summary>
/// 群组聊天
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tpUser_Press(object sender, EventArgs e)
{
try
{
if (((SmoONE.UI.Im.frmConcent)this.Form).im1 != null)
{
//在群组列表模板中调用群组聊天
((SmoONE.UI.Im.frmConcent)this.Form).im1.StartGroupChat(lblGroup.BindDataValue.ToString(), lblGroup.BindDisplayValue.ToString());
}
}
catch (Exception ex)
{
this.Form.Toast(ex.Message,ToastLength.SHORT );
}
}
}
}
using System;
using Smobiler.Core;
namespace SmoONE.UI.Layout
{
partial class frmGroupLayout : Smobiler.Core.Controls.MobileUserControl
{
#region "SmobilerUserControl generated code "
public frmGroupLayout()
: base()
{
//This call is required by the SmobilerUserControl.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//SmobilerUserControl overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerUserControl
//It can be modified using the SmobilerUserControl.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.tpUser = new Smobiler.Core.Controls.Panel();
this.imgPortrait = new Smobiler.Core.Controls.Image();
this.lblGroup = new Smobiler.Core.Controls.Label();
//
// tpUser
//
this.tpUser.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.imgPortrait,
this.lblGroup});
this.tpUser.Name = "tpUser";
this.tpUser.Size = new System.Drawing.Size(300, 50);
this.tpUser.Touchable = true;
this.tpUser.Press += new System.EventHandler(this.tpUser_Press);
//
// imgPortrait
//
this.imgPortrait.BorderRadius = 18;
this.imgPortrait.Location = new System.Drawing.Point(4, 7);
this.imgPortrait.Name = "imgPortrait";
this.imgPortrait.ResourceID = "group";
this.imgPortrait.Size = new System.Drawing.Size(36, 36);
this.imgPortrait.SizeMode = Smobiler.Core.Controls.ImageSizeMode.Cover;
//
// lblGroup
//
this.lblGroup.DataMember = "G_ID";
this.lblGroup.DisplayMember = "G_NAME";
this.lblGroup.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(45)))));
this.lblGroup.Location = new System.Drawing.Point(47, 0);
this.lblGroup.Name = "lblGroup";
this.lblGroup.Size = new System.Drawing.Size(253, 50);
//
// frmGroupLayout
//
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.tpUser});
this.Size = new System.Drawing.Size(0, 50);
this.Name = "frmGroupLayout";
}
#endregion
private Smobiler.Core.Controls.Panel tpUser;
private Smobiler.Core.Controls.Image imgPortrait;
private Smobiler.Core.Controls.Label lblGroup;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using Smobiler.Plugins.RongIM;
using SmoONE.DTOs;
using SmoONE.CommLib;
using SmoONE.UI.Layout;
namespace SmoONE.UI.Im
{
//创建群和添加联系人窗体
partial class frmAddConcentOrGroup : Smobiler.Core.Controls.MobileForm
{
#region "definition"
AutofacConfig AutofacConfig = new AutofacConfig();//调用配置类
public ConcentState ctype;
public IM im1;
#endregion
public frmAddConcentOrGroup(IM im):this()
{
im1 = im;
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
switch (ctype)
{
case ConcentState.Group:
if (txtName.Text.Trim().Length <= 0)
{
throw new Exception("请输入群组名称!");
}
CGroupInputDto cgroupInputDto = new CGroupInputDto();
cgroupInputDto.G_NAME = txtName.Text.Trim();
string guser = "";
foreach (ListViewRow rows in listView1.Rows)
{
if (Convert.ToBoolean(((Layout.frmAddUserLayout)(rows.Control)).Check.BindDisplayValue) == true)
{
if (guser.Length <= 0)
{
guser = ((Layout.frmAddUserLayout)(rows.Control)).lblUser.BindDataValue .ToString();
}
else
{
guser = guser + "," + ((Layout.frmAddUserLayout)(rows.Control)).lblUser.BindDataValue.ToString();
}
}
}
if (guser.Length <= 0)
{
throw new Exception("请选择群组成员!");
}
guser= guser+"," + Client.Session["U_ID"].ToString();
cgroupInputDto.G_USER = guser;
cgroupInputDto.G_CreateUser = Client.Session["U_ID"].ToString();
cgroupInputDto.G_UpdateUser = Client.Session["U_ID"].ToString();
ReturnInfo r = AutofacConfig.cGroupService .AddGroup(cgroupInputDto);
if (r.IsSuccess == true)
{
string[] guser1 = guser.Split(',');
string groupid = r.ErrorInfo;//当返回true时,返回群组编号
//创建群组
im1.CreateGroup(guser1, groupid, cgroupInputDto.G_NAME);
this.ShowResult = ShowResult.Yes;
this.Close();
Toast("群组创建成功!", ToastLength.SHORT);
}
else
{
throw new Exception(r.ErrorInfo);
}
break;
}
}
catch(Exception ex)
{
Toast(ex.Message, ToastLength.SHORT);
}
}
/// <summary>
/// 加载数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAddConcentOrGroup_Load(object sender, EventArgs e)
{
switch (ctype)
{
case ConcentState.Concent:
title1.TitleText = "添加联系人";
pGName.Visible = false;
pPost.Visible = false;
listView1.TemplateControl = new frmAddUser1Layout();
break;
case ConcentState.Group:
title1.TitleText = "创建群组";
pGName.Visible = true ;
pPost.Visible = true ;
listView1.TemplateControl= new frmAddUserLayout();
break;
}
Bind();
}
/// <summary>
/// 初始化方法
/// </summary>
private void Bind ()
{
try
{
List<UserDto> listUser = new List<UserDto>();
List<UserDto> listCUser = AutofacConfig.userService.GetAllUsers();//获取分配部门人员
List<string> listCUser1 = new List<string>();
listView1.Rows.Clear();
switch (ctype)
{
case ConcentState.Concent:
//获取当前用户联系人
List<ContactDto> listContactDto = AutofacConfig.contactService.GetByCreateUsers(Client.Session["U_ID"].ToString());
if (listContactDto.Count > 0)
{
foreach (ContactDto contact in listContactDto)
{
listCUser1.Add(contact.C_USER);
}
}
break;
}
if (listCUser.Count > 0)
{
listCUser1.Add(Client.Session["U_ID"].ToString());
foreach (UserDto user in listCUser)
{
if (listCUser1.Count <= 0 || (listCUser1.Count > 0 && !listCUser1.Contains(user.U_ID)))
{
if (string.IsNullOrEmpty(user.U_Portrait) == true)
{
switch (user.U_Sex)
{
case (int)Sex.男:
user.U_Portrait = "boy";
break;
case (int)Sex.女:
user.U_Portrait = "girl";
break;
}
}
listUser.Add(user);
}
}
}
listView1.Rows.Clear();
if (listUser.Count > 0)
{
listView1.DataSource = listUser;
listView1.DataBind();
}
}
catch (Exception ex)
{
Toast(ex.Message, ToastLength.SHORT);
}
}
}
}
using System;
using Smobiler.Core;
namespace SmoONE.UI.Im
{
partial class frmAddConcentOrGroup : Smobiler.Core.Controls.MobileForm
{
#region "SmobilerForm generated code "
public frmAddConcentOrGroup()
: base()
{
//This call is required by the SmobilerForm.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//SmobilerForm overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerForm
//It can be modified using the SmobilerForm.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.title1 = new SmoONE.UI.Layout.Title();
this.pGName = new Smobiler.Core.Controls.Panel();
this.Label4 = new Smobiler.Core.Controls.Label();
this.txtName = new Smobiler.Core.Controls.TextBox();
this.pPost = new Smobiler.Core.Controls.Panel();
this.btnSave = new Smobiler.Core.Controls.Button();
this.listView1 = new Smobiler.Core.Controls.ListView();
//
// title1
//
this.title1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(242)))));
this.title1.Direction = Smobiler.Core.Controls.LayoutDirection.Row;
this.title1.Dock = System.Windows.Forms.DockStyle.Top;
this.title1.Name = "title1";
this.title1.Size = new System.Drawing.Size(100, 50);
//
// pGName
//
this.pGName.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.Label4,
this.txtName});
this.pGName.Direction = Smobiler.Core.Controls.LayoutDirection.Row;
this.pGName.Dock = System.Windows.Forms.DockStyle.Top;
this.pGName.Layout = Smobiler.Core.Controls.LayoutPosition.Relative;
this.pGName.Location = new System.Drawing.Point(0, 60);
this.pGName.Margin = new Smobiler.Core.Controls.Margin(0F, 10F, 0F, 0F);
this.pGName.Name = "pGName";
this.pGName.Size = new System.Drawing.Size(300, 35);
//
// Label4
//
this.Label4.BackColor = System.Drawing.Color.White;
this.Label4.Border = new Smobiler.Core.Controls.Border(0F, 1F, 0F, 1F);
this.Label4.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.Label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(44)))), ((int)(((byte)(44)))));
this.Label4.Name = "Label4";
this.Label4.Padding = new Smobiler.Core.Controls.Padding(4F, 0F, 0F, 0F);
this.Label4.Size = new System.Drawing.Size(66, 0);
this.Label4.Text = "群组名称";
this.Label4.ZIndex = 1;
//
// txtName
//
this.txtName.Border = new Smobiler.Core.Controls.Border(0F, 1F, 0F, 1F);
this.txtName.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.txtName.Flex = 1;
this.txtName.FontSize = 12F;
this.txtName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(99)))), ((int)(((byte)(99)))));
this.txtName.HorizontalAlignment = Smobiler.Core.Controls.HorizontalAlignment.Right;
this.txtName.Name = "txtName";
this.txtName.Padding = new Smobiler.Core.Controls.Padding(0F, 0F, 4F, 0F);
this.txtName.ReturnKeyType = Smobiler.Core.Controls.ReturnKeyType.Done;
this.txtName.Size = new System.Drawing.Size(0, 0);
this.txtName.WaterMarkText = "(必填)";
this.txtName.ZIndex = 2;
//
// pPost
//
this.pPost.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.btnSave});
this.pPost.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pPost.Location = new System.Drawing.Point(0, 461);
this.pPost.Name = "pPost";
this.pPost.Size = new System.Drawing.Size(100, 50);
//
// btnSave
//
this.btnSave.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(146)))), ((int)(((byte)(223)))));
this.btnSave.BorderRadius = 4;
this.btnSave.FontSize = 17F;
this.btnSave.Location = new System.Drawing.Point(10, 10);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(280, 35);
this.btnSave.Text = "提交";
this.btnSave.Press += new System.EventHandler(this.btnSave_Click);
//
// listView1
//
this.listView1.BackColor = System.Drawing.Color.White;
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.Location = new System.Drawing.Point(0, 95);
this.listView1.Margin = new Smobiler.Core.Controls.Margin(0F, 10F, 0F, 0F);
this.listView1.Name = "listView1";
this.listView1.PageSize = 8;
this.listView1.PageSizeTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(145)))), ((int)(((byte)(145)))), ((int)(((byte)(145)))));
this.listView1.PageSizeTextSize = 11F;
this.listView1.Size = new System.Drawing.Size(300, 0);
//
// frmAddConcentOrGroup
//
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.title1,
this.pGName,
this.pPost,
this.listView1});
this.Orientation = Smobiler.Core.Controls.FormOrientation.Portrait;
this.Load += new System.EventHandler(this.frmAddConcentOrGroup_Load);
this.Name = "frmAddConcentOrGroup";
}
#endregion
private Layout.Title title1;
private Smobiler.Core.Controls.Panel pGName;
internal Smobiler.Core.Controls.Label Label4;
internal Smobiler.Core.Controls.TextBox txtName;
private Smobiler.Core.Controls.Panel pPost;
private Smobiler.Core.Controls.ListView listView1;
private Smobiler.Core.Controls.Button btnSave;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using Smobiler.Plugins.RongIM;
using SmoONE.DTOs;
using SmoONE.CommLib;
namespace SmoONE.UI.Layout
{
//添加群成员模板
////ToolboxItem用于控制是否添加自定义控件到工具箱,true添加,false不添加
//[System.ComponentModel.ToolboxItem(true)]
partial class frmAddUser1Layout : Smobiler.Core.Controls.MobileUserControl
{
#region "definition"
AutofacConfig AutofacConfig = new AutofacConfig();//调用配置类
#endregion
private void btnAdd_Press(object sender, EventArgs e)
{
try
{
ContactInputDto cInputDto = new ContactInputDto();
cInputDto.C_USER = lblUser.BindDataValue.ToString();
cInputDto.C_CreateUser = Client.Session["U_ID"].ToString();
cInputDto.C_UpdateUser = Client.Session["U_ID"].ToString();
ReturnInfo r = AutofacConfig.contactService.AddContact(cInputDto);
if (r.IsSuccess == true)
{
if (((SmoONE.UI.Im.frmAddConcentOrGroup)this.Form).im1 != null)
{
//添加联系人
((SmoONE.UI.Im.frmAddConcentOrGroup)this.Form).im1.CreateUser(cInputDto.C_USER, lblUser.BindDisplayValue.ToString(),System.IO.Path.Combine( MobileResourceManager.DefaultImagePath ,imgPortrait .BindDisplayValue .ToString ()));
}
this.Form .ShowResult = ShowResult.Yes;
this.Form .Close();
this.Form .Toast ("联系人添加成功!", ToastLength.SHORT);
}
else
{
throw new Exception(r.ErrorInfo);
}
}
catch (Exception ex)
{
this.Form.Toast(ex.Message , ToastLength.SHORT);
}
}
}
}
using System;
using Smobiler.Core;
namespace SmoONE.UI.Layout
{
partial class frmAddUser1Layout : Smobiler.Core.Controls.MobileUserControl
{
#region "SmobilerUserControl generated code "
public frmAddUser1Layout()
: base()
{
//This call is required by the SmobilerUserControl.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//SmobilerUserControl overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerUserControl
//It can be modified using the SmobilerUserControl.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.imgPortrait = new Smobiler.Core.Controls.Image();
this.lblUser = new Smobiler.Core.Controls.Label();
this.btnAdd = new Smobiler.Core.Controls.Button();
//
// imgPortrait
//
this.imgPortrait.BorderRadius = 10;
this.imgPortrait.DataMember = "U_Portrait";
this.imgPortrait.DisplayMember = "U_Portrait";
this.imgPortrait.Location = new System.Drawing.Point(4, 7);
this.imgPortrait.Name = "imgPortrait";
this.imgPortrait.Size = new System.Drawing.Size(35, 35);
this.imgPortrait.SizeMode = Smobiler.Core.Controls.ImageSizeMode.Cover;
//
// lblUser
//
this.lblUser.DataMember = "U_ID";
this.lblUser.DisplayMember = "U_Name";
this.lblUser.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(45)))));
this.lblUser.Location = new System.Drawing.Point(47, 0);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(203, 50);
//
// btnAdd
//
this.btnAdd.BackColor = System.Drawing.Color.White;
this.btnAdd.Border = new Smobiler.Core.Controls.Border(1F);
this.btnAdd.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(140)))), ((int)(((byte)(255)))));
this.btnAdd.BorderRadius = 4;
this.btnAdd.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(140)))), ((int)(((byte)(255)))));
this.btnAdd.Location = new System.Drawing.Point(256, 13);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(40, 24);
this.btnAdd.Text = "添加";
this.btnAdd.Press += new System.EventHandler(this.btnAdd_Press);
//
// frmAddUser1Layout
//
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.imgPortrait,
this.lblUser,
this.btnAdd});
this.Size = new System.Drawing.Size(300, 50);
this.Name = "frmAddUser1Layout";
}
#endregion
public Smobiler.Core.Controls.Image imgPortrait;
public Smobiler.Core.Controls.Label lblUser;
private Smobiler.Core.Controls.Button btnAdd;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
namespace SmoONE.UI.Layout
{
//添加联系人模板
////ToolboxItem用于控制是否添加自定义控件到工具箱,true添加,false不添加
//[System.ComponentModel.ToolboxItem(true)]
partial class frmAddUserLayout : Smobiler.Core.Controls.MobileUserControl
{
private void Check_CheckedChanged(object sender, EventArgs e)
{
}
}
}
using System;
using Smobiler.Core;
namespace SmoONE.UI.Layout
{
partial class frmAddUserLayout : Smobiler.Core.Controls.MobileUserControl
{
#region "SmobilerUserControl generated code "
public frmAddUserLayout()
: base()
{
//This call is required by the SmobilerUserControl.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//SmobilerUserControl overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerUserControl
//It can be modified using the SmobilerUserControl.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.imgPortrait = new Smobiler.Core.Controls.Image();
this.lblUser = new Smobiler.Core.Controls.Label();
this.Check = new Smobiler.Core.Controls.CheckBox();
//
// imgPortrait
//
this.imgPortrait.BorderRadius = 10;
this.imgPortrait.DataMember = "U_Portrait";
this.imgPortrait.DisplayMember = "U_Portrait";
this.imgPortrait.Location = new System.Drawing.Point(4, 7);
this.imgPortrait.Name = "imgPortrait";
this.imgPortrait.Size = new System.Drawing.Size(35, 35);
this.imgPortrait.SizeMode = Smobiler.Core.Controls.ImageSizeMode.Cover;
//
// lblUser
//
this.lblUser.DataMember = "U_ID";
this.lblUser.DisplayMember = "U_Name";
this.lblUser.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(45)))));
this.lblUser.Location = new System.Drawing.Point(47, 0);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(219, 50);
//
// Check
//
this.Check.Location = new System.Drawing.Point(274, 15);
this.Check.Name = "Check";
this.Check.Size = new System.Drawing.Size(20, 20);
this.Check.CheckedChanged += new System.EventHandler(this.Check_CheckedChanged);
//
// frmAddUserLayout
//
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.imgPortrait,
this.lblUser,
this.Check});
this.Size = new System.Drawing.Size(300, 50);
this.Name = "frmAddUserLayout";
}
#endregion
public Smobiler.Core.Controls.Label lblUser;
public Smobiler.Core.Controls.CheckBox Check;
public Smobiler.Core.Controls.Image imgPortrait;
}
}