示例#1
0
 public void ShowReceiveWin(STCallParam _callParam)    //显示视频被叫方的画面
 {
     Dispatcher.Invoke(new Action(() =>
     {
         WinCallReceive receive = new WinCallReceive(lync, _callParam.ucAcc + StringHelper.GetLyncDomainString(SingletonObj.LoginInfo.LyncName), true);
         receive.Show();
     }));
 }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (txtNumber.Text.ToString().Trim() == "" || txtNumber.Text.ToString() == "")
            {
                return;
            }
            else
            {
                boolnum(txtNumber.Text.ToString());
            }
            if (boolnum(txtNumber.Text.ToString()) == true)
            {
                //modify by jinyeqing  00327190  2015/6/10  添加号码时先看是否是UC用户,如果是按照UC帐号添加,不是就按话机号码添加
                MakeCallBusiness call   = new MakeCallBusiness();
                StringBuilder    ucName = new StringBuilder(100);

                string strLyncURI = StringHelper.GetLyncDomainString(SingletonObj.LoginInfo.LyncName);
                if (call.GetUCAccountByPhoneNo(txtNumber.Text.ToString().Trim(), ucName) != "" && call.GetUCAccountByPhoneNo(txtNumber.Text.ToString().Trim(), ucName) != null)
                {
                    foreach (DataRow d in dtSelectedContact.Rows)
                    {
                        if (d["Phone"].ToString() == txtNumber.Text.ToString())
                        {
                            DialogShow.Show(StringHelper.FindLanguageResource("theNumisExist"), StringHelper.FindLanguageResource("error"), 2);
                            return;
                        }
                        if (d["Url"].ToString() == ucName + strLyncURI)   //2015/8/6  如果URL 一致,则不添加
                        {
                            DialogShow.Show(StringHelper.FindLanguageResource("theNameisExist"), StringHelper.FindLanguageResource("error"), 2);
                            return;
                        }
                    }
                    DataRow dr   = dtSelectedContact.NewRow();
                    string  str  = txtNumber.Text.ToString();
                    int     page = 0;
                    GetAllLyncContacts(str, page);
                    dtSource = dtContact.Copy();
                    string name = "";
                    //modify by 00327190 2015/8/6  如果号码是UC用户,则连用户名一起查出来,这样为了避免加人重复
                    UserConfigBusiness conf  = new UserConfigBusiness();
                    STContact          con   = new STContact();
                    string             name1 = StringHelper.GetSubString(ucName.ToString());
                    int iRet1 = conf.GetContactInfo(new StringBuilder(name1), ref con);
                    if (0 == iRet1)
                    {
                        name = con.name_;
                    }
                    //modify by 00327190 2015/8/6  如果号码是UC用户,则连用户名一起查出来,这样为了避免加人重复

                    for (int i = 0; i < dtSource.Rows.Count; i++)
                    {
                        if (dtSource.Rows[i]["URL"].ToString().Trim() == call.GetUCAccountByPhoneNo(txtNumber.Text.ToString(), ucName) + strLyncURI)
                        {
                            name = dtSource.Rows[i]["NAME"].ToString().Trim();
                        }
                    }
                    dr[0] = name;
                    //2015/8/24    UTF8 转码UNICODE
                    //byte[] buffer1 = Encoding.Default.GetBytes(call.GetUCAccountByPhoneNo(txtNumber.Text.ToString(), ucName));
                    //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
                    //string item1 = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
                    //dr[1] = item1 + strLyncURI;
                    dr[1] = call.GetUCAccountByPhoneNo(txtNumber.Text.ToString(), ucName) + strLyncURI;
                    dr[2] = txtNumber.Text.ToString();
                    dtSelectedContact.Rows.Add(dr);
                    listSelectedContact.DataContext = null;
                    listSelectedContact.DataContext = dtSelectedContact;
                    listSelectedContact.ScrollIntoView(listSelectedContact.Items[dtSelectedContact.Rows.Count - 1], listSelectedContact.Columns[0]);

                    txtName.Text   = "";
                    txtNumber.Text = "";
                }
                //之前没有if ,只有中间的循环体部分
                else
                {
                    foreach (DataRow d in dtSelectedContact.Rows)
                    {
                        if (d["Phone"].ToString() == txtNumber.Text.ToString())
                        {
                            return;
                        }
                    }
                    DataRow dr = dtSelectedContact.NewRow();
                    dr[0] = txtName.Text.ToString();
                    dr[2] = txtNumber.Text.ToString();
                    dtSelectedContact.Rows.Add(dr);
                    listSelectedContact.DataContext = null;
                    listSelectedContact.DataContext = dtSelectedContact;
                    listSelectedContact.ScrollIntoView(listSelectedContact.Items[dtSelectedContact.Rows.Count - 1], listSelectedContact.Columns[0]);

                    txtName.Text   = "";
                    txtNumber.Text = "";
                }

                //是否是盲转窗体
                if (isBlindTransCall)
                {
                    btnOK_Click(null, null);
                }
            }
            else
            {
                lync.winCall.OpenDialogTiming(StringHelper.FindLanguageResource("Invalidnum"), StringHelper.FindLanguageResource("error"), 2);
                return;
            }
        }
示例#3
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            Image img = ((sender as Button).Content as StackPanel).Children[0] as Image;

            if (img.Tag.ToString() == "call")
            {
                if (txtNumber.Text.ToString() == "")
                {
                    return;
                }
                if (Lync.winCall != null)
                {
                    this.Close();
                    Dialog.Show(StringHelper.FindLanguageResource("TwoCallsSameTime"), StringHelper.FindLanguageResource("error"));
                    return;
                }
                //拨号
                MakeCallBusiness call   = new MakeCallBusiness();
                StringBuilder    ucName = new StringBuilder(100);
                call.GetUCAccount(txtNumber.Text.ToString(), ucName);
                string str = null;

                if (ucName.ToString() == "")
                {
                    str = txtNumber.Text.ToString();
                    call.insertMember((int)MemberType.UC_IPPHONE, new StringBuilder(str));
                }
                else
                {
                    str = ucName + StringHelper.GetLyncDomainString(SingletonObj.LoginInfo.LyncName);
                    call.insertMember((int)MemberType.UC_ACCOUNT, ucName);
                }

                if (call.startContextCall() == 0)   //modify by 00327190  2015/6/18 只要返回值不为0,就不能执行以下操作
                {
                    this.Close();

                    WinCall winCall = new WinCall(Lync, SingletonObj.LoginInfo.LyncName + ";" + str.ToString());
                    winCall.callType = CallHistoryType.HISTORY_CALL_DIALED;
                    winCall.Show();
                    Lync.winCall = winCall;
                }
                else
                {
                    this.Close();
                    DialogShow.Show(StringHelper.FindLanguageResource("startContextCallFailed"), StringHelper.FindLanguageResource("error"), 2);
                    return;
                }
            }
            else if (img.Tag.ToString() == "back")
            {
                if (txtNumber.Text.Length > 0)
                {
                    txtNumber.Text = txtNumber.Text.Substring(0, txtNumber.Text.Length - 1);
                }
            }
            else
            {
                txtNumber.Text = txtNumber.Text + img.Tag.ToString();
                txtNumber.Focus();
                txtNumber.Select(txtNumber.Text.Length, 0);
            }
        }
        /// <summary>
        /// 获取前两百条数据
        /// </summary>
        /// <param name="strSearchKey">查询关键字</param>
        void GetAllLyncContacts(string strSearchKey = "", int page = 0)
        {
            dtContact = new DataTable();
            dtContact.Columns.Add("Name");
            dtContact.Columns.Add("Url");
            dtContact.Columns.Add("Phone");

            if (dtSelectedContact.Columns.Count == 0)
            {
                dtSelectedContact.Columns.Add("Name");
                dtSelectedContact.Columns.Add("Url");
                dtSelectedContact.Columns.Add("Phone");
            }

            MakeCallBusiness call = new MakeCallBusiness();

            int maxCount           = 200; //最多查询的数量
            int count              = 100; //每次查询的数量
            int iSizeSTContactList = Marshal.SizeOf(typeof(STContactList));
            int iSizeSTContact     = Marshal.SizeOf(typeof(STContact));
            int uiBufSize          = (iSizeSTContactList + iSizeSTContact * (count - 1));

            byte[] pSTContactList = new byte[uiBufSize];

            UCServiceRetvCode iRet = (UCServiceRetvCode)call.GetEntContactList(strSearchKey, page * count, page * count + count - 1, pSTContactList);

            if (UCServiceRetvCode.UC_SDK_Success == iRet)
            {
                string strLyncURI     = StringHelper.GetLyncDomainString(SingletonObj.LoginInfo.LyncName);
                IntPtr tempInfoIntPtr = Marshal.AllocHGlobal((int)iSizeSTContactList);
                byte[] tempInfoByte   = new byte[iSizeSTContactList];
                try
                {
                    Marshal.Copy(pSTContactList, 0, tempInfoIntPtr, (int)iSizeSTContactList);
                    STContactList head = (STContactList)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STContactList));
                    this.labTotal.Content = "/" + ((head.iTotal % count) == 0 ? (head.iTotal / count == 0 ? 1 : head.iTotal / count).ToString() : (head.iTotal / count + 1).ToString());
                    this.txtPage.Text     = (page + 1).ToString();

                    //for (int index = -1; index < head.iTotal - 1 && index < count - 1; index++)
                    //{
                    //    Marshal.Copy(pSTContactList, iSizeSTContactList + iSizeSTContact * index, tempInfoIntPtr, (int)iSizeSTContact);
                    //    STContact item = (STContact)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STContact));
                    //    dtContact.Rows.Add(item.name_, string.IsNullOrEmpty(item.uri_) ? "" : item.uri_ + strLyncURI, item.mobile_);
                    //}
                    //if (head.iTotal > count)//继续查询
                    //{
                    //最多查询maxCount条数据
                    if (head.iTotal < maxCount)
                    {
                        maxCount = head.iTotal;
                    }
                    int num = maxCount % count != 0 ? (maxCount / count + 1) : maxCount / count;//需要查询的次数
                    for (int iNum = 1; iNum < num; iNum++)
                    {
                        iRet = (UCServiceRetvCode)call.GetEntContactList(strSearchKey, iNum * count, iNum * count + count - 1, pSTContactList);
                        if (UCServiceRetvCode.UC_SDK_Success == iRet)
                        {
                            Marshal.Copy(pSTContactList, 0, tempInfoIntPtr, (int)iSizeSTContactList);
                            head = (STContactList)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STContactList));

                            for (int index = -1; index < (maxCount - iNum * count - 1) && index < count - 1; index++)
                            {
                                Marshal.Copy(pSTContactList, iSizeSTContactList + iSizeSTContact * index, tempInfoIntPtr, (int)iSizeSTContact);
                                STContact item = (STContact)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STContact));
                                if (item.name_ != null && item.name_ != "")
                                {
                                    dtContact.Rows.Add(item.name_, string.IsNullOrEmpty(item.uri_) ? "" : item.uri_ + strLyncURI, item.mobile_);
                                }
                            }
                        }
                        else
                        {
                            LogManager.SystemLog.Error("GetAllLyncContacts failed");
                            break;
                        }
                    }
                    //}
                }
                finally
                {
                    Marshal.Release(tempInfoIntPtr);
                }
            }
            else
            {
                LogManager.SystemLog.Error("GetAllLyncContacts failed");
            }

            #region 根据lync接口查询lync用户的联系人列表
            //foreach (Microsoft.Lync.Model.Group.Group group in WinLync.LyncContactGroups)
            //{
            //    foreach (Contact contact in (ContactCollection)(group))
            //    {
            //        int index = -1;
            //        foreach (DataRow dr in dtContact.Rows)
            //        {
            //            if (dr["Url"].ToString() == contact.Uri)
            //            {
            //                index = 0;
            //            }
            //        }
            //        if (index == -1)
            //        {
            //            string phone = "";
            //            List<object> list = contact.GetContactInformation(ContactInformationType.ContactEndpoints) as List<object>;
            //            foreach (object point in list)
            //            {
            //                if (((Microsoft.Lync.Model.ContactEndpoint)point).Type == ContactEndpointType.WorkPhone)
            //                {
            //                    phone = ((Microsoft.Lync.Model.ContactEndpoint)point).DisplayName;
            //                }
            //            }
            //           string name = contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
            //           dtContact.Rows.Add(name, contact.Uri, phone);

            //        }
            //    }
            //}
            #endregion
        }