public void QueryHistoryByPage(int index, int page)
        {
            int iSizeSTCallHistroyData = Marshal.SizeOf(typeof(STCallHistroyData));
            int iSizeSTCallHistroyItem = Marshal.SizeOf(typeof(STCallHistroyItem));
            int uiBufSize = (iSizeSTCallHistroyData + iSizeSTCallHistroyItem * (count - 1));
            byte[] pCallHistory = new byte[uiBufSize];

            DataTable dt = new DataTable();
            dt.Columns.Add("Phone");
            dt.Columns.Add("Name");
            dt.Columns.Add("Time");
            dt.Columns.Add("Duration");
            dt.Columns.Add("TelType");

            List<CallItem> list = new List<CallItem>();
            UCServiceRetvCode iRet = (UCServiceRetvCode)query.QueryCallHistory((CallHistoryType)index, page * count, page * count + count - 1, pCallHistory, uiBufSize);
            if (UCServiceRetvCode.UC_SDK_Success == iRet)
            {
                IntPtr tempInfoIntPtr = Marshal.AllocHGlobal((int)iSizeSTCallHistroyData);
                byte[] tempInfoByte = new byte[iSizeSTCallHistroyData];

                Marshal.Copy(pCallHistory, 0, tempInfoIntPtr, (int)iSizeSTCallHistroyData);
                STCallHistroyData head = (STCallHistroyData)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STCallHistroyData));

                winHisitory.labTotal.Content = "/" + ((head.iTotal % count) == 0 ? (head.iTotal / count == 0 ? 1 : head.iTotal / count).ToString() : (head.iTotal / count + 1).ToString());
                winHisitory.txtPage.Text = (page + 1).ToString();
                int second = 0;
                for (int i = -1; i < head.iTotal - 1 && i < head.iTo-head.iFrom; i++)
                {
                    Marshal.Copy(pCallHistory, iSizeSTCallHistroyData + iSizeSTCallHistroyItem * i, tempInfoIntPtr, (int)iSizeSTCallHistroyItem);
                    STCallHistroyItem item = (STCallHistroyItem)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STCallHistroyItem));

                    CallItem callItem = new CallItem();
                    //2015/8/24    UTF8 转码UNICODE
                    //byte[] buffer1 = Encoding.Default.GetBytes(item.CallName);
                    //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
                    //string item1= Encoding.Default.GetString(buffer2, 0, buffer2.Length);
                    //callItem.Name = item1;
                    //byte[] buffer3 = Encoding.Default.GetBytes(item.CallNum);
                    //byte[] buffer4 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer3, 0, buffer3.Length);
                    //string item2 = Encoding.Default.GetString(buffer4, 0, buffer4.Length);
                    //callItem.Phone = item2;
                    //
                    callItem.Phone = item.CallNum;
                    callItem.Name = item.CallName;
                    DateTime dtTime = DateTime.Parse(item.startTime.year.ToString() + "-" + item.startTime.month + "-" + item.startTime.day
                                    + " " + item.startTime.hour + ":" + item.startTime.minute + ":" + item.startTime.second);
                    callItem.Time = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
                    second=Convert.ToInt32(item.duration);
                    callItem.Duration = (second == -1 ? "00:00:00" : DateTime.Today.AddSeconds(second).ToString("HH:mm:ss"));
                    callItem.TelType = (CallHistoryType)item.callType;

                    list.Add(callItem);
                }
                Marshal.Release(tempInfoIntPtr);
            }
            else
            {
                winHisitory.labTotal.Content = "/1";
                winHisitory.txtPage.Text = "1";
            }

            switch ((CallHistoryType)index)
            {
                case CallHistoryType.HISTORY_CALL_ALL:
                    winHisitory.listAll.DataContext = null;
                    winHisitory.listAll.DataContext = list;
                    break;
                case CallHistoryType.HISTORY_CALL_ANSWERED:
                    winHisitory.listAnswered.DataContext = null;
                    winHisitory.listAnswered.DataContext = list;
                    break;
                case CallHistoryType.HISTORY_CALL_DIALED:
                    winHisitory.listDialed.DataContext = null;
                    winHisitory.listDialed.DataContext = list;
                    break;
                case CallHistoryType.HISTORY_CALL_MISSED:
                    winHisitory.listMissed.DataContext = null;
                    winHisitory.listMissed.DataContext = list;
                    break;
            }
        }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (Lync.winCall != null)
            {
                DialogShow.Show(StringHelper.FindLanguageResource("Youareincallalready"), StringHelper.FindLanguageResource("error"), 2);  //不能同时发起两路通话
                return;
            }
            List <CallItem> list  = new List <CallItem>();
            int             index = -1;

            if (tabControlCall.SelectedIndex == 0)
            {
                list  = listMissed.DataContext as List <CallItem>;
                index = listMissed.SelectedIndex;
            }
            else if (tabControlCall.SelectedIndex == 1)
            {
                list  = listAnswered.DataContext as List <CallItem>;
                index = listAnswered.SelectedIndex;
            }
            else if (tabControlCall.SelectedIndex == 2)
            {
                list  = listDialed.DataContext as List <CallItem>;
                index = listDialed.SelectedIndex;
            }
            else if (tabControlCall.SelectedIndex == 3)
            {
                list  = listAll.DataContext as List <CallItem>;
                index = listAll.SelectedIndex;
            }

            if (index < 0)
            {
                return;
            }
            CallItem item = list[index];

            MakeCallBusiness call = new MakeCallBusiness();
            MemberType       type;

            if (item.Phone.IndexOf("@") < 0)
            {
                type = MemberType.UC_IPPHONE;
            }
            else
            {
                type = MemberType.UC_ACCOUNT;
            }
            string str = "";

            if (item.Phone.IndexOf(":") != -1)
            {
                str = item.Phone.Substring(item.Phone.IndexOf(":") + 1);
            }
            else
            {
                str = item.Phone;
            }
            //2015/8/24    UNICODE  转码   UTF8
            //byte[] buffer1 = Encoding.UTF8.GetBytes(str.Trim().Replace(" ",""));
            //byte[] buffer2 = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, buffer1, 0, buffer1.Length);
            //string item1 = Encoding.UTF8.GetString(buffer2,0, buffer2.Length);
            //call.insertMember((int)type, new StringBuilder(item1));
            call.insertMember((int)type, new StringBuilder(str));
            if (call.startContextCall() == 0)
            {
                str                   = SingletonObj.LoginInfo.LyncName + ";" + str;
                Lync.winCall          = new WinCall(Lync, str);
                Lync.winCall.callType = CallHistoryType.HISTORY_CALL_DIALED;
                Lync.winCall.Show();
            }
            else
            {
                Dialog.Show(StringHelper.FindLanguageResource("startContextCallFailed"), StringHelper.FindLanguageResource("error"));
                return;
            }
        }
        public void QueryHistoryByPage(int index, int page)
        {
            int iSizeSTCallHistroyData = Marshal.SizeOf(typeof(STCallHistroyData));
            int iSizeSTCallHistroyItem = Marshal.SizeOf(typeof(STCallHistroyItem));
            int uiBufSize = (iSizeSTCallHistroyData + iSizeSTCallHistroyItem * (count - 1));

            byte[] pCallHistory = new byte[uiBufSize];

            DataTable dt = new DataTable();

            dt.Columns.Add("Phone");
            dt.Columns.Add("Name");
            dt.Columns.Add("Time");
            dt.Columns.Add("Duration");
            dt.Columns.Add("TelType");


            List <CallItem>   list = new List <CallItem>();
            UCServiceRetvCode iRet = (UCServiceRetvCode)query.QueryCallHistory((CallHistoryType)index, page * count, page * count + count - 1, pCallHistory, uiBufSize);

            if (UCServiceRetvCode.UC_SDK_Success == iRet)
            {
                IntPtr tempInfoIntPtr = Marshal.AllocHGlobal((int)iSizeSTCallHistroyData);
                byte[] tempInfoByte   = new byte[iSizeSTCallHistroyData];

                Marshal.Copy(pCallHistory, 0, tempInfoIntPtr, (int)iSizeSTCallHistroyData);
                STCallHistroyData head = (STCallHistroyData)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STCallHistroyData));

                winHisitory.labTotal.Content = "/" + ((head.iTotal % count) == 0 ? (head.iTotal / count == 0 ? 1 : head.iTotal / count).ToString() : (head.iTotal / count + 1).ToString());
                winHisitory.txtPage.Text     = (page + 1).ToString();
                int second = 0;
                for (int i = -1; i < head.iTotal - 1 && i < head.iTo - head.iFrom; i++)
                {
                    Marshal.Copy(pCallHistory, iSizeSTCallHistroyData + iSizeSTCallHistroyItem * i, tempInfoIntPtr, (int)iSizeSTCallHistroyItem);
                    STCallHistroyItem item = (STCallHistroyItem)Marshal.PtrToStructure(tempInfoIntPtr, typeof(STCallHistroyItem));

                    CallItem callItem = new CallItem();
                    //2015/8/24    UTF8 转码UNICODE
                    //byte[] buffer1 = Encoding.Default.GetBytes(item.CallName);
                    //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
                    //string item1= Encoding.Default.GetString(buffer2, 0, buffer2.Length);
                    //callItem.Name = item1;
                    //byte[] buffer3 = Encoding.Default.GetBytes(item.CallNum);
                    //byte[] buffer4 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer3, 0, buffer3.Length);
                    //string item2 = Encoding.Default.GetString(buffer4, 0, buffer4.Length);
                    //callItem.Phone = item2;
                    //
                    callItem.Phone = item.CallNum;
                    callItem.Name  = item.CallName;
                    DateTime dtTime = DateTime.Parse(item.startTime.year.ToString() + "-" + item.startTime.month + "-" + item.startTime.day
                                                     + " " + item.startTime.hour + ":" + item.startTime.minute + ":" + item.startTime.second);
                    callItem.Time     = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
                    second            = Convert.ToInt32(item.duration);
                    callItem.Duration = (second == -1 ? "00:00:00" : DateTime.Today.AddSeconds(second).ToString("HH:mm:ss"));
                    callItem.TelType  = (CallHistoryType)item.callType;

                    list.Add(callItem);
                }
                Marshal.Release(tempInfoIntPtr);
            }
            else
            {
                winHisitory.labTotal.Content = "/1";
                winHisitory.txtPage.Text     = "1";
            }

            switch ((CallHistoryType)index)
            {
            case CallHistoryType.HISTORY_CALL_ALL:
                winHisitory.listAll.DataContext = null;
                winHisitory.listAll.DataContext = list;
                break;

            case CallHistoryType.HISTORY_CALL_ANSWERED:
                winHisitory.listAnswered.DataContext = null;
                winHisitory.listAnswered.DataContext = list;
                break;

            case CallHistoryType.HISTORY_CALL_DIALED:
                winHisitory.listDialed.DataContext = null;
                winHisitory.listDialed.DataContext = list;
                break;

            case CallHistoryType.HISTORY_CALL_MISSED:
                winHisitory.listMissed.DataContext = null;
                winHisitory.listMissed.DataContext = list;
                break;
            }
        }