using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections;
using DPSDK_RES = System.Int32;

namespace DPSDK_CSharpDemo
{
    public partial class CSharpDemo : Form
    {
        private string Utf8StringToWideString(string content)
        {
            //Character encoding conversion gb2312:936 utf-8:65001 big5:950 latin1:1252
            int len = MultiByteToWideChar(65001, 0, content, -1, null, 0);
            StringBuilder content1 = new StringBuilder(len);
            MultiByteToWideChar(65001, 0, content, -1, content1, content1.Capacity);
            return content1.ToString();
        }

        private string WideStringToUtf8String(string content)
        {
            int len = WideCharToMultiByte(65001, 0, content, -1, null, 0, IntPtr.Zero, IntPtr.Zero);
            StringBuilder content1 = new StringBuilder(len);
            WideCharToMultiByte(65001, 0, content, -1, content1, content1.Capacity, IntPtr.Zero, IntPtr.Zero);
            return content1.ToString();
        }

        private void ShowAttendanceInfo(string strInfo)
        {
            string strShow = textAttendanceResult.Text + "\r\n" + strInfo;
            textAttendanceResult.Text = strShow;
        }

        private void PraseDepIDList(ref AllDepartmentInfo struAllDepartmentInfo, ref List<ComboBoxItem> list)
        {
            list.Add(new ComboBoxItem(struAllDepartmentInfo.struDepartment.strId, struAllDepartmentInfo.struDepartment.strId));
            for (int i = 0; i < struAllDepartmentInfo.vecDepartment.Count; i++)
            {
                AllDepartmentInfo struSubAllDepartmentInfo = (AllDepartmentInfo)struAllDepartmentInfo.vecDepartment[i];
                PraseDepIDList(ref struSubAllDepartmentInfo, ref list);
            }
        }

        private void fAttendanceDataCallback(IntPtr iDataType, IntPtr pDataBuf, IntPtr uiBufSize, IntPtr pUserData)
        {
            switch (iDataType.ToInt32())
            {
                case DPSDK_DATA_GET_ATTENDANCE_TIMEINTERVALS_INFO:
                    {
                        listViewAttendanceTimeIntervalList.Items.Clear();
                        DPSDK_GET_TIMEINTERVAL_LIST pGetTimeIntervalList = (DPSDK_GET_TIMEINTERVAL_LIST)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_GET_TIMEINTERVAL_LIST));
                        for (int i = 0; i < pGetTimeIntervalList.iNum; i++)
                        {
                            IntPtr ptr = new IntPtr(pGetTimeIntervalList.pIntervalInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_INFO)) * i);
                            DPSDK_TIMEINTERVAL_INFO struTimeIntervalInfo = (DPSDK_TIMEINTERVAL_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_TIMEINTERVAL_INFO));
                            ListViewItem item = listViewAttendanceTimeIntervalList.Items.Add(struTimeIntervalInfo.iColor.ToString());
                            item.SubItems.Add(Utf8StringToWideString(struTimeIntervalInfo.szName));
                            item.SubItems.Add(struTimeIntervalInfo.szIntervalId);
                            item.SubItems.Add(struTimeIntervalInfo.iAttModel.ToString());
                        }
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_TIMEINTERVAL_INFO:
                    {
                        DPSDK_TIMEINTERVAL_DATA pTimeIntervalData = (DPSDK_TIMEINTERVAL_DATA)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_TIMEINTERVAL_DATA));
                        string strTimeIntervalInfo = AppData._CS("TimeIntervalID = %1, TimeIntervalName = %2, AttendanceMode = %3, Color = %4", pTimeIntervalData.szIntervalId, Utf8StringToWideString(pTimeIntervalData.szName), pTimeIntervalData.iAttendanceModel.ToString(), pTimeIntervalData.iColor.ToString());
                        strTimeIntervalInfo += "\r\n";
                        if (pTimeIntervalData.iAttendanceModel == 1)//Fixed attendance
                        {
                            if (pTimeIntervalData.iWorkAttNum > 0)
                            {
                                string strAttendanceInterval = AppData._CS("Attendance Interval");
                                strAttendanceInterval += "\r\n";
                                for (int i = 0; i < pTimeIntervalData.iWorkAttNum; i++)
                                {
                                    IntPtr ptr = new IntPtr(pTimeIntervalData.pWorkAttInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_WORKATT_INFO)) * i);
                                    DPSDK_WORKATT_INFO struWorkAttInfo = (DPSDK_WORKATT_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_WORKATT_INFO));
                                    strAttendanceInterval += AppData._CS("Work Time = %1 - %2", struWorkAttInfo.szStartTime, struWorkAttInfo.szEndTime);
                                    strAttendanceInterval += "\r\n";
                                    strAttendanceInterval += AppData._CS("Work Hours = %1", struWorkAttInfo.fWorkHours.ToString());
                                    strAttendanceInterval += "\r\n";
                                    strAttendanceInterval += AppData._CS("Valid Sign-in Time = %1 - %2", struWorkAttInfo.szSignInStartTime, struWorkAttInfo.szSignInEndTime);
                                    strAttendanceInterval += "\r\n";
                                    strAttendanceInterval += AppData._CS("Shall Sign in = %1", struWorkAttInfo.iMustSignIn.ToString());
                                    strAttendanceInterval += "\r\n";
                                    strAttendanceInterval += AppData._CS("Valid Sign-out Time = %1 - %2", struWorkAttInfo.szSignOutStartTime, struWorkAttInfo.szSignOutEndTime);
                                    strAttendanceInterval += "\r\n";
                                    strAttendanceInterval += AppData._CS("Shall Sign out = %1", struWorkAttInfo.iMustSignOut.ToString());
                                    strAttendanceInterval += "\r\n";
                                }
                                strTimeIntervalInfo += strAttendanceInterval;

                                string strAttendanceRule = AppData._CS("Attendance Rule");
                                strAttendanceRule += "\r\n";
                                strAttendanceRule += AppData._CS("Late sign in within %1 minutes is permitted.", pTimeIntervalData.iLater.ToString());
                                strAttendanceRule += "\r\n";
                                strAttendanceRule += AppData._CS("Late sign in over %1 minutes is recorded as absence.", pTimeIntervalData.iLaterAbsence.ToString());
                                strAttendanceRule += "\r\n";
                                strAttendanceRule += AppData._CS("Early leave within %1 minutes is permitted.", pTimeIntervalData.iEarly.ToString());
                                strAttendanceRule += "\r\n";
                                strAttendanceRule += AppData._CS("Early sign out over %1 minutes is recorded as absence.", pTimeIntervalData.iEarlyAbsence.ToString());
                                strAttendanceRule += "\r\n";
                                strAttendanceRule += AppData._CS("End of Off Duty %1 minutes late than off duty time is recorded as absence.", pTimeIntervalData.iWorkOvertime.ToString());
                                strAttendanceRule += "\r\n";
                                strTimeIntervalInfo += strAttendanceRule;
                            }
                        }
                        else if (pTimeIntervalData.iAttendanceModel == 2)//Free attendance
                        {
                            string strAttendanceRule = AppData._CS("Attendance Rule");
                            strAttendanceRule += "\r\n";
                            strAttendanceRule += AppData._CS("%1 Hour Syetem", pTimeIntervalData.fFreeWorkHours.ToString());
                            strAttendanceRule += "\r\n";
                            strAttendanceRule += AppData._CS("freeWorkLimit %1", pTimeIntervalData.iFreeWorkLimit.ToString());//0: no limit, 1: limit
                            strAttendanceRule += "\r\n";
                            if (pTimeIntervalData.iFreeWorkLimit == 1)
                            {
                                strAttendanceRule += AppData._CS("the final punch in time %1", pTimeIntervalData.szFreeLimitTime);
                                strAttendanceRule += "\r\n";
                            }
                            strAttendanceRule += AppData._CS("Marked as %1 Working Hours", pTimeIntervalData.fFreeWorkHours.ToString());
                            strAttendanceRule += "\r\n";
                            strAttendanceRule += AppData._CS("Final Punch out Time %1", pTimeIntervalData.szDayChangeTime);
                            strAttendanceRule += "\r\n";
                            strAttendanceRule += AppData._CS("EnableFreeWorkOver %1", pTimeIntervalData.iEnableFreeWorkOver.ToString());/** Whether to enable overtime configuration for free attendance 0=not enabled, 1=enabled */
                            strAttendanceRule += "\r\n";
                            if (pTimeIntervalData.iEnableFreeWorkOver == 1)
                            {
                                strAttendanceRule += AppData._CS("Workup to %1 hours as overtime.", pTimeIntervalData.fFreeWorkOvertime.ToString());
                                strAttendanceRule += "\r\n";
                            }
                            strAttendanceRule += AppData._CS("EnableOddInEvenOut %1", pTimeIntervalData.iEnableOddInEvenOut.ToString());/** Whether to enable odd in and even out：1=enabled, 0=Not enabled */
                            strAttendanceRule += "\r\n";
                            if (pTimeIntervalData.iEnableOddInEvenOut == 1)
                            {
                                strAttendanceRule += AppData._CS("Continuous Punch Interval more than %1 miniute", pTimeIntervalData.iSwingCardInterval.ToString());
                                strAttendanceRule += "\r\n";
                            }
                            strTimeIntervalInfo += strAttendanceRule;
                        }
                        ShowAttendanceInfo(strTimeIntervalInfo);
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_BATCH_TIMEINTERVAL_INFO:
                    {
                        DPSDK_BATCH_TIMEINTERVAL_LIST pBatchTimeIntervalList = (DPSDK_BATCH_TIMEINTERVAL_LIST)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_BATCH_TIMEINTERVAL_LIST));
                        if (pBatchTimeIntervalList.iTimeIntervalNum > 0)
                        {
                            string strTimeIntervalListInfo = AppData._CS("Attendance TimeInterval List");
                            strTimeIntervalListInfo += "\r\n";
                            for (int i = 0; i < pBatchTimeIntervalList.iTimeIntervalNum; i++)
                            {
                                IntPtr ptr = new IntPtr(pBatchTimeIntervalList.pTimeIntervalList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_DATA)) * i);
                                DPSDK_TIMEINTERVAL_DATA pTimeIntervalData = (DPSDK_TIMEINTERVAL_DATA)Marshal.PtrToStructure(ptr, typeof(DPSDK_TIMEINTERVAL_DATA));
                                string strTimeIntervalInfo = AppData._CS("TimeIntervalID = %1, TimeIntervalName = %2, AttendanceMode = %3, Color = %4", pTimeIntervalData.szIntervalId, Utf8StringToWideString(pTimeIntervalData.szName), pTimeIntervalData.iAttendanceModel.ToString(), pTimeIntervalData.iColor.ToString());
                                strTimeIntervalInfo += "\r\n";
                                if (pTimeIntervalData.iAttendanceModel == 1)//Fixed attendance
                                {
                                    if (pTimeIntervalData.iWorkAttNum > 0)
                                    {
                                        string strAttendanceInterval = AppData._CS("Attendance Interval");
                                        strAttendanceInterval += "\r\n";
                                        for (int j = 0; j < pTimeIntervalData.iWorkAttNum; j++)
                                        {
                                            IntPtr ptr2 = new IntPtr(pTimeIntervalData.pWorkAttInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_WORKATT_INFO)) * j);
                                            DPSDK_WORKATT_INFO struWorkAttInfo = (DPSDK_WORKATT_INFO)Marshal.PtrToStructure(ptr2, typeof(DPSDK_WORKATT_INFO));
                                            strAttendanceInterval += AppData._CS("Work Time = %1 - %2", struWorkAttInfo.szStartTime, struWorkAttInfo.szEndTime);
                                            strAttendanceInterval += "\r\n";
                                            strAttendanceInterval += AppData._CS("Work Hours = %1", struWorkAttInfo.fWorkHours.ToString());
                                            strAttendanceInterval += "\r\n";
                                            strAttendanceInterval += AppData._CS("Valid Sign-in Time = %1 - %2", struWorkAttInfo.szSignInStartTime, struWorkAttInfo.szSignInEndTime);
                                            strAttendanceInterval += "\r\n";
                                            strAttendanceInterval += AppData._CS("Shall Sign in = %1", struWorkAttInfo.iMustSignIn.ToString());
                                            strAttendanceInterval += "\r\n";
                                            strAttendanceInterval += AppData._CS("Valid Sign-out Time = %1 - %2", struWorkAttInfo.szSignOutStartTime, struWorkAttInfo.szSignOutEndTime);
                                            strAttendanceInterval += "\r\n";
                                            strAttendanceInterval += AppData._CS("Shall Sign out = %1", struWorkAttInfo.iMustSignOut.ToString());
                                            strAttendanceInterval += "\r\n";
                                        }
                                        strTimeIntervalInfo += strAttendanceInterval;

                                        string strAttendanceRule = AppData._CS("Attendance Rule");
                                        strAttendanceRule += "\r\n";
                                        strAttendanceRule += AppData._CS("Late sign in within %1 minutes is permitted.", pTimeIntervalData.iLater.ToString());
                                        strAttendanceRule += "\r\n";
                                        strAttendanceRule += AppData._CS("Late sign in over %1 minutes is recorded as absence.", pTimeIntervalData.iLaterAbsence.ToString());
                                        strAttendanceRule += "\r\n";
                                        strAttendanceRule += AppData._CS("Early leave within %1 minutes is permitted.", pTimeIntervalData.iEarly.ToString());
                                        strAttendanceRule += "\r\n";
                                        strAttendanceRule += AppData._CS("Early sign out over %1 minutes is recorded as absence.", pTimeIntervalData.iEarlyAbsence.ToString());
                                        strAttendanceRule += "\r\n";
                                        strAttendanceRule += AppData._CS("End of Off Duty %1 minutes late than off duty time is recorded as absence.", pTimeIntervalData.iWorkOvertime.ToString());
                                        strAttendanceRule += "\r\n";
                                        strTimeIntervalInfo += strAttendanceRule;
                                    }
                                }
                                else if (pTimeIntervalData.iAttendanceModel == 2)//Free attendance
                                {
                                    string strAttendanceRule = AppData._CS("Attendance Rule");
                                    strAttendanceRule += "\r\n";
                                    strAttendanceRule += AppData._CS("%1 Hour Syetem", pTimeIntervalData.fFreeWorkHours.ToString());
                                    strAttendanceRule += "\r\n";
                                    strAttendanceRule += AppData._CS("freeWorkLimit %1", pTimeIntervalData.iFreeWorkLimit.ToString());//0: no limit, 1: limit
                                    strAttendanceRule += "\r\n";
                                    if (pTimeIntervalData.iFreeWorkLimit == 1)
                                    {
                                        strAttendanceRule += AppData._CS("the final punch in time %1", pTimeIntervalData.szFreeLimitTime);
                                        strAttendanceRule += "\r\n";
                                    }
                                    strAttendanceRule += AppData._CS("Marked as %1 Working Hours", pTimeIntervalData.fFreeWorkHours.ToString());
                                    strAttendanceRule += "\r\n";
                                    strAttendanceRule += AppData._CS("Final Punch out Time %1", pTimeIntervalData.szDayChangeTime);
                                    strAttendanceRule += "\r\n";
                                    strAttendanceRule += AppData._CS("EnableFreeWorkOver %1", pTimeIntervalData.iEnableFreeWorkOver.ToString());/** Whether to enable overtime configuration for free attendance 0=not enabled, 1=enabled */
                                    strAttendanceRule += "\r\n";
                                    if (pTimeIntervalData.iEnableFreeWorkOver == 1)
                                    {
                                        strAttendanceRule += AppData._CS("Workup to %1 hours as overtime.", pTimeIntervalData.fFreeWorkOvertime.ToString());
                                        strAttendanceRule += "\r\n";
                                    }
                                    strAttendanceRule += AppData._CS("EnableOddInEvenOut %1", pTimeIntervalData.iEnableOddInEvenOut.ToString());/** Whether to enable odd in and even out：1=enabled, 0=Not enabled */
                                    strAttendanceRule += "\r\n";
                                    if (pTimeIntervalData.iEnableOddInEvenOut == 1)
                                    {
                                        strAttendanceRule += AppData._CS("Continuous Punch Interval more than %1 miniute", pTimeIntervalData.iSwingCardInterval.ToString());
                                        strAttendanceRule += "\r\n";
                                    }
                                    strTimeIntervalInfo += strAttendanceRule;
                                }

                                strTimeIntervalListInfo += strTimeIntervalInfo;
                            }
                            ShowAttendanceInfo(strTimeIntervalListInfo);
                        }
                    }
                    break;
                case DPSDK_DATA_DEL_ATTENDANCE_TIMEINTERVAL_INFO:
                    {
                        DPSDK_ATTENDANCE_TIMEINTERVAL_NAME_LIST pTimeIntervalNameList = (DPSDK_ATTENDANCE_TIMEINTERVAL_NAME_LIST)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_ATTENDANCE_TIMEINTERVAL_NAME_LIST));
                        string strDelTimeIntervalInfo = AppData._CS("------------------Del Failed Interval Name List Start-----------------");
                        strDelTimeIntervalInfo += "\r\n";
                        for (int i = 0; i < pTimeIntervalNameList.iNum; i++)
                        {
                            IntPtr ptr = new IntPtr(pTimeIntervalNameList.pFailedIntervalList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_NAME)) * i);
                            DPSDK_TIMEINTERVAL_NAME struTimeIntervalName = (DPSDK_TIMEINTERVAL_NAME)Marshal.PtrToStructure(ptr, typeof(DPSDK_TIMEINTERVAL_NAME));
                            if (i == 0)
                            {
                                strDelTimeIntervalInfo += Utf8StringToWideString(struTimeIntervalName.szName);
                            }
                            else
                            {
                                strDelTimeIntervalInfo = strDelTimeIntervalInfo + " | " + Utf8StringToWideString(struTimeIntervalName.szName);
                            }
                        }
                        strDelTimeIntervalInfo += "\r\n";
                        strDelTimeIntervalInfo += AppData._CS("------------------Del Failed Interval Name List End-----------------");
                        strDelTimeIntervalInfo += "\r\n";
                        ShowAttendanceInfo(strDelTimeIntervalInfo);
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_HOLIDAYS_INFO:
                    {
                        DPSDK_GET_HOLIDAY_RESULT pGetHolidayResult = (DPSDK_GET_HOLIDAY_RESULT)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_GET_HOLIDAY_RESULT));
                        listViewAttendanceHolidayManageHolidayList.Items.Clear();
                        for (int i = 0; i < pGetHolidayResult.iHolidayListNum; i++)
                        {
                            IntPtr ptr = new IntPtr(pGetHolidayResult.pHolidayList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ATTENDANCE_HOLIDAY_INFO)) * i);
                            DPSDK_ATTENDANCE_HOLIDAY_INFO struAttendanceHolidayInfo = (DPSDK_ATTENDANCE_HOLIDAY_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_ATTENDANCE_HOLIDAY_INFO));
                            ListViewItem item = listViewAttendanceHolidayManageHolidayList.Items.Add(Utf8StringToWideString(struAttendanceHolidayInfo.szName));
                            item.SubItems.Add(struAttendanceHolidayInfo.szHolidayId);
                            item.SubItems.Add(struAttendanceHolidayInfo.iHolidayNum.ToString());
                            item.SubItems.Add(struAttendanceHolidayInfo.szStartDate);
                            item.SubItems.Add(struAttendanceHolidayInfo.szEndDate);
                        }
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_ORDERS_INFO:
                    {
                        DPSDK_ATTENDANCEORDER_LIST struAttendanceOrderList = (DPSDK_ATTENDANCEORDER_LIST)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_ATTENDANCEORDER_LIST));
                        listViewAttendanceShiftOrderList.Items.Clear();
                        for (int i = 0; i < struAttendanceOrderList.iNum; i++)
                        {
                            IntPtr ptr = new IntPtr(struAttendanceOrderList.pOrderInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ATTENDANCEORDER_DATA)) * i);
                            DPSDK_ATTENDANCEORDER_DATA struAttendanceOrderData = (DPSDK_ATTENDANCEORDER_DATA)Marshal.PtrToStructure(ptr, typeof(DPSDK_ATTENDANCEORDER_DATA));
                            ListViewItem item = listViewAttendanceShiftOrderList.Items.Add(Utf8StringToWideString(struAttendanceOrderData.szName));
                            item.SubItems.Add(struAttendanceOrderData.szId);
                            item.SubItems.Add(struAttendanceOrderData.iLoopType.ToString());
                        }
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_BATCH_ORDER_INFO:
                    {
                        DPSDK_BATCH_ATTENDANCEORDER_LIST struBatchAttendanceOrderList = (DPSDK_BATCH_ATTENDANCEORDER_LIST)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_BATCH_ATTENDANCEORDER_LIST));
                        string strBatchOrderInfo = "";
                        for (int i = 0; i < struBatchAttendanceOrderList.iOrderNum; i++)
                        {
                            IntPtr ptr = new IntPtr(struBatchAttendanceOrderList.pOrderList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ATTENDANCEORDER_INFO)) * i);
                            DPSDK_ATTENDANCEORDER_INFO struAttendanceOrderInfo = (DPSDK_ATTENDANCEORDER_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_ATTENDANCEORDER_INFO));
                            strBatchOrderInfo += AppData._CS("OrderName = %1, OrderID = %2, LoopType = %3, LoopValue = %4, IntervalNum = %5", Utf8StringToWideString(struAttendanceOrderInfo.szName), struAttendanceOrderInfo.szId,
                                struAttendanceOrderInfo.iLoopType.ToString(), struAttendanceOrderInfo.iLoopValue.ToString(), struAttendanceOrderInfo.iIntervalNum.ToString());
                            strBatchOrderInfo += "\r\n";
                            strBatchOrderInfo += AppData._CS("IntervalList = ");
                            strBatchOrderInfo += "\r\n";
                            for (int j = 0; j < struAttendanceOrderInfo.iIntervalNum; j++)
                            {
                                IntPtr ptr2 = new IntPtr(struAttendanceOrderInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * j);
                                DPSDK_TIMEINTERVAL_ID struTimeIntervalId = (DPSDK_TIMEINTERVAL_ID)Marshal.PtrToStructure(ptr2, typeof(DPSDK_TIMEINTERVAL_ID));
                                if (j == 0)
                                {
                                    strBatchOrderInfo += struTimeIntervalId.szId;
                                }
                                else
                                {
                                    strBatchOrderInfo = strBatchOrderInfo + " ; " + struTimeIntervalId.szId;
                                }
                            }
                            strBatchOrderInfo += "\r\n";
                        }
                        ShowAttendanceInfo(strBatchOrderInfo);
                    }
                    break;
                case DPSDK_DATA_DEL_ATTENDANCE_ORDERS_INFO:
                    {
                        DPSDK_ATTENDANCE_ORDER_NAME_LIST struAttendanceOrderNameList = (DPSDK_ATTENDANCE_ORDER_NAME_LIST)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_ATTENDANCE_ORDER_NAME_LIST));
                        if (struAttendanceOrderNameList.iNum > 0)
                        {
                            string strDelAttendanceOrdersInfo = AppData._CS("Delete Failed Order Name:");
                            for (int i = 0; i < struAttendanceOrderNameList.iNum; i++)
                            {
                                IntPtr ptr = new IntPtr(struAttendanceOrderNameList.pFailedOrderList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ORDER_NAME)) * i);
                                DPSDK_ORDER_NAME struOrderName = (DPSDK_ORDER_NAME)Marshal.PtrToStructure(ptr, typeof(DPSDK_ORDER_NAME));
                                if (i == 0)
                                {
                                    strDelAttendanceOrdersInfo += Utf8StringToWideString(struOrderName.szName);
                                }
                                else
                                {
                                    strDelAttendanceOrdersInfo = strDelAttendanceOrdersInfo + " ; " + Utf8StringToWideString(struOrderName.szName);
                                }
                            }
                            ShowAttendanceInfo(strDelAttendanceOrdersInfo);
                        }
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_DEPTSCHEDULE_INFO:
                    {
                        DPSDK_DEPT_SCHEDULE_INFO pDeptScheduleInfo = (DPSDK_DEPT_SCHEDULE_INFO)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_DEPT_SCHEDULE_INFO));
                        for (int i = 0; i < pDeptScheduleInfo.iOrderNum; i++)
                        {
                            IntPtr ptr = new IntPtr(pDeptScheduleInfo.pOrderList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO)) * i);
                            DPSDK_STANDARD_SCHEDULE_ORDER_INFO struScheduleOrderInfo = (DPSDK_STANDARD_SCHEDULE_ORDER_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO));
                            ListViewItem item = listViewDepartmentShiftDeptSchedule.Items.Add(struScheduleOrderInfo.szStartDate);
                            item.SubItems.Add(struScheduleOrderInfo.szEndDate);
                            item.SubItems.Add(struScheduleOrderInfo.szOrderId);
                        }
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_SCHEDULE_INFO:
                    {
                        DPSDK_PERSON_SCHEDULE_INFO struPersonScheduleInfo = (DPSDK_PERSON_SCHEDULE_INFO)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_PERSON_SCHEDULE_INFO));
                        for (int i = 0; i < struPersonScheduleInfo.iStandardOrderNum; i++)
                        {
                            IntPtr ptr = new IntPtr(struPersonScheduleInfo.pStandardOrderList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO)) * i);
                            DPSDK_STANDARD_SCHEDULE_ORDER_INFO struScheduleOrderInfo = (DPSDK_STANDARD_SCHEDULE_ORDER_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO));
                            ListViewItem item = listViewPersonnelPersonSchedule.Items.Add(struScheduleOrderInfo.szStartDate);
                            item.SubItems.Add(struScheduleOrderInfo.szEndDate);
                            item.SubItems.Add(struScheduleOrderInfo.szOrderId);
                        }

                        if (struPersonScheduleInfo.iTempOrderNum > 0)
                        {
                            string strTempOrderList = "";
                            for (int i = 0; i < struPersonScheduleInfo.iTempOrderNum; i++)
                            {
                                IntPtr ptr = new IntPtr(struPersonScheduleInfo.pTempOrderList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_SCHEDULE_TEMP_ORDER_INFO)) * i);
                                DPSDK_SCHEDULE_TEMP_ORDER_INFO struTempOrderInfo = (DPSDK_SCHEDULE_TEMP_ORDER_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_SCHEDULE_TEMP_ORDER_INFO));
                                strTempOrderList += AppData._CS("TempDate = %1", struTempOrderInfo.szTempDate);
                                strTempOrderList += "\r\n";

                                string strIntervalIdList = "";
                                for (int j = 0; j < struTempOrderInfo.iIdNum; j++)
                                {
                                    IntPtr ptr2 = new IntPtr(struTempOrderInfo.pIntervalId.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                                    DPSDK_TIMEINTERVAL_ID struTimeIntervalID = (DPSDK_TIMEINTERVAL_ID)Marshal.PtrToStructure(ptr2, typeof(DPSDK_TIMEINTERVAL_ID));
                                    if (j == 0)
                                    {
                                        strIntervalIdList += AppData._CS("IntervalID :");
                                    }
                                    else
                                    {
                                        strIntervalIdList += " ; ";
                                        
                                    }
                                    strIntervalIdList += struTimeIntervalID.szId;
                                }
                                strIntervalIdList += "\r\n";
                                strTempOrderList += strIntervalIdList;
                            }
                            textPersonnelTempOrders.Text = strTempOrderList;
                        }
                    }
                    break;
                case DPSDK_DATA_GET_ATTENDANCE_CHANNELS_LIST:
                    {
                        DPSDK_GET_CHANNEL_RESULT struGetChannelResult = (DPSDK_GET_CHANNEL_RESULT)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_GET_CHANNEL_RESULT));
                        for (int i = 0; i < struGetChannelResult.iChannelInfoNum; i++)
                        {
                            IntPtr ptr = new IntPtr(struGetChannelResult.pRelChannelInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ATT_CHANNEL_INFO)) * i);
                            DPSDK_ATT_CHANNEL_INFO struAttChannelInfo = (DPSDK_ATT_CHANNEL_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_ATT_CHANNEL_INFO));
                            ListViewItem item = listViewAttendanceConfigChannels.Items.Add(Utf8StringToWideString(struAttChannelInfo.szChannelName));
                            item.SubItems.Add(struAttChannelInfo.szChannelId);
                        }
                    }
                    break;
                default:
                    break;
            }
        }

        private void fGetTimeIntervalsCallback(IntPtr iDataType, IntPtr pDataBuf, IntPtr uiBufSize, IntPtr pUserData)
        {
            listViewAttendanceShiftIntervalList.Items.Clear();
            DPSDK_GET_TIMEINTERVAL_LIST pGetTimeIntervalList = (DPSDK_GET_TIMEINTERVAL_LIST)Marshal.PtrToStructure(pDataBuf, typeof(DPSDK_GET_TIMEINTERVAL_LIST));
            for (int i = 0; i < pGetTimeIntervalList.iNum; i++)
            {
                IntPtr ptr = new IntPtr(pGetTimeIntervalList.pIntervalInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_INFO)) * i);
                DPSDK_TIMEINTERVAL_INFO struTimeIntervalInfo = (DPSDK_TIMEINTERVAL_INFO)Marshal.PtrToStructure(ptr, typeof(DPSDK_TIMEINTERVAL_INFO));
                ListViewItem item = listViewAttendanceShiftIntervalList.Items.Add(Utf8StringToWideString(struTimeIntervalInfo.szName));
                item.SubItems.Add(struTimeIntervalInfo.szIntervalId);
            }
        }

        private void btnAttendanceClear_Click(object sender, EventArgs e)
        {
            textAttendanceResult.Text = "";
        }

        private void btnAttendanceTimeGetIntervalList_Click(object sender, EventArgs e)
        {
            DPSDK_PAGE_INFO pPageInfo = new DPSDK_PAGE_INFO();
            pPageInfo.uiPage = Convert.ToUInt32(textAttendanceTimePageNum.Text);
            pPageInfo.uiPageSize = Convert.ToUInt32(textAttendanceTimePageSize.Text);
            DPSDK_RES iRet = DPSDK_AttendanceGetTimeIntervals(m_iSessionID, ref pPageInfo, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetTimeIntervals") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetTimeIntervals") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceTimeGetTimeIntervalInfo_Click(object sender, EventArgs e)
        {
            string pIntervalId = textAttendanceTimeIntervalID2.Text;
            DPSDK_RES iRet = DPSDK_AttendanceGetTimeInterval(m_iSessionID, pIntervalId, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetTimeInterval") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetTimeInterval") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceTimeBatchGetTimeIntervals_Click(object sender, EventArgs e)
        {
            DPSDK_TIMEINTERVAL_ID_LIST struTimeIntervalIDList = new DPSDK_TIMEINTERVAL_ID_LIST();
            string strIntervalIDList = textAttendanceTimeIntervalID2.Text;
            ArrayList arrIntervalID = new ArrayList();
            StringSplit(strIntervalIDList, ";", ref arrIntervalID);
            struTimeIntervalIDList.iIdNum = arrIntervalID.Count;
            if (struTimeIntervalIDList.iIdNum > 0)
            {
                struTimeIntervalIDList.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struTimeIntervalIDList.iIdNum);
                for (int i = 0; i < struTimeIntervalIDList.iIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(struTimeIntervalIDList.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                    DPSDK_TIMEINTERVAL_ID struTimeIntervalId= new DPSDK_TIMEINTERVAL_ID();
                    struTimeIntervalId.szId = (string)arrIntervalID[i];
                    Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceBatchGetTimeIntervals(m_iSessionID, ref struTimeIntervalIDList, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceBatchGetTimeIntervals") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceBatchGetTimeIntervals") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struTimeIntervalIDList.pIntervalIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struTimeIntervalIDList.pIntervalIdList);
            }
        }

        private void btnAttendanceTimeAddTimeInterval_Click(object sender, EventArgs e)
        {
            DPSDK_TIMEINTERVAL_DATA struTimeIntervalData = new DPSDK_TIMEINTERVAL_DATA();
            struTimeIntervalData.szName = WideStringToUtf8String(textAttendanceTimeTimeIntervalName.Text);
            struTimeIntervalData.iColor = Convert.ToInt32(textAttendanceTimeColorCode.Text);
            if (comboBoxAttendanceTimeAttendanceMode.SelectedIndex != -1)
            {
                struTimeIntervalData.iAttendanceModel = comboBoxAttendanceTimeAttendanceMode.SelectedIndex + 1;
            }

            if (struTimeIntervalData.iAttendanceModel == 1)
            {
                struTimeIntervalData.iWorkAttNum = 1;//Demo only sets one attendance period, the interface supports multiple
                if (struTimeIntervalData.iWorkAttNum > 0)
                {
                    struTimeIntervalData.pWorkAttInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_WORKATT_INFO)) * struTimeIntervalData.iWorkAttNum);
                    for (int i = 0; i < struTimeIntervalData.iWorkAttNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struTimeIntervalData.pWorkAttInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_WORKATT_INFO)) * i);
                        DPSDK_WORKATT_INFO struWorkAttInfo = new DPSDK_WORKATT_INFO();
                        struWorkAttInfo.szStartTime = dateAttendanceTimeWorkTimeBegin.Text;
                        struWorkAttInfo.szEndTime = dateAttendanceTimeWorkTimeEnd.Text;
                        struWorkAttInfo.szSignInStartTime = dateAttendanceTimeValidSigninTimeBegin.Text;
                        struWorkAttInfo.szSignInEndTime = dateAttendanceTimeValidSigninTimeEnd.Text;
                        struWorkAttInfo.szSignOutStartTime = dateAttendanceTimeValidSignoutTimeBegin.Text;
                        struWorkAttInfo.szSignOutEndTime = dateAttendanceTimeValidSignoutTimeEnd.Text;
                        struWorkAttInfo.fWorkHours = Convert.ToSingle(numericUpDownAttendanceTimeWorkHours.Value);
                        struWorkAttInfo.iMustSignIn = checkBoxAttendanceTimeShallSignin.CheckState == CheckState.Checked ? 1 : 0;
                        struWorkAttInfo.iMustSignOut = checkBoxAttendanceTimeShallSignout.CheckState == CheckState.Checked ? 1 : 0;
                        Marshal.StructureToPtr(struWorkAttInfo, ptr, true);
                    }
                }

                struTimeIntervalData.iLater = Convert.ToInt32(textAttendanceTimeAttendanceRule1.Text);
                struTimeIntervalData.iLaterAbsence = Convert.ToInt32(textAttendanceTimeAttendanceRule2.Text);
                struTimeIntervalData.iEarly = Convert.ToInt32(textAttendanceTimeAttendanceRule3.Text);
                struTimeIntervalData.iEarlyAbsence = Convert.ToInt32(textAttendanceTimeAttendanceRule4.Text);
                struTimeIntervalData.iWorkOvertime = Convert.ToInt32(textAttendanceTimeAttendanceRule5.Text);
            }
            else if (struTimeIntervalData.iAttendanceModel == 2)//Free mode
            {
                struTimeIntervalData.fFreeWorkHours = Convert.ToSingle(numericUpDownAttendanceTimeHourSystem.Value);
                if (comboBoxAttendanceTimeFinalPunch.SelectedIndex != -1)
                {
                    struTimeIntervalData.iFreeWorkLimit = comboBoxAttendanceTimeFinalPunch.SelectedIndex;//Whether free time attendance is limited time: 0=unlimited, 1=restricted
                }
                struTimeIntervalData.szFreeLimitTime = dateAttendanceTimeFinalPunchInTime.Text;
                struTimeIntervalData.fRecordWorkHours = Convert.ToSingle(numericUpDownAttendancTimeWorkingHours.Value);
                struTimeIntervalData.szDayChangeTime = dateAttendanceTimeFinalPunchOutTime.Text;
                struTimeIntervalData.iEnableFreeWorkOver = checkBoxAttendancTimeOverTime.CheckState == CheckState.Checked ? 1 : 0;
                if (struTimeIntervalData.iEnableFreeWorkOver == 1)//Whether to enable overtime configuration for free attendance 0=Not enabled, 1=enabled
                {
                    struTimeIntervalData.fFreeWorkOvertime = Convert.ToSingle(numericUpDownAttendanceTimeOverTime.Value);
                }
                struTimeIntervalData.iEnableOddInEvenOut = checkBoxAttendanceTimeOddIn.CheckState == CheckState.Checked ? 1 : 0;
                if (struTimeIntervalData.iEnableOddInEvenOut == 1)//Whether to enable odd in and even out: 1=enabled, 0=Not enabled
                {
                    struTimeIntervalData.iSwingCardInterval = textAttendanceTimeMiniute.Text != "" ? Convert.ToInt32(textAttendanceTimeMiniute.Text) : 0;
                }
            }
            else
            {
                return;
            }

            DPSDK_RES iRet = DPSDK_AttendanceAddTimeInterval(m_iSessionID, ref struTimeIntervalData);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddTimeInterval") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddTimeInterval") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struTimeIntervalData.pWorkAttInfo != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struTimeIntervalData.pWorkAttInfo);
            }
        }

        private void btnAttendanceTimeUpdateTimeInterval_Click(object sender, EventArgs e)
        {
            DPSDK_TIMEINTERVAL_DATA struTimeIntervalData = new DPSDK_TIMEINTERVAL_DATA();
            struTimeIntervalData.szName = WideStringToUtf8String(textAttendanceTimeTimeIntervalName.Text);
            struTimeIntervalData.iColor = Convert.ToInt32(textAttendanceTimeColorCode.Text);
            if (comboBoxAttendanceTimeAttendanceMode.SelectedIndex != -1)
            {
                struTimeIntervalData.iAttendanceModel = comboBoxAttendanceTimeAttendanceMode.SelectedIndex + 1;
            }

            if (struTimeIntervalData.iAttendanceModel == 1)
            {
                struTimeIntervalData.iWorkAttNum = 1;//Demo only sets one attendance period, the interface supports multiple
                if (struTimeIntervalData.iWorkAttNum > 0)
                {
                    struTimeIntervalData.pWorkAttInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_WORKATT_INFO)) * struTimeIntervalData.iWorkAttNum);
                    for (int i = 0; i < struTimeIntervalData.iWorkAttNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struTimeIntervalData.pWorkAttInfo.ToInt32() + Marshal.SizeOf(typeof(DPSDK_WORKATT_INFO)) * i);
                        DPSDK_WORKATT_INFO struWorkAttInfo = new DPSDK_WORKATT_INFO();
                        struWorkAttInfo.szStartTime = dateAttendanceTimeWorkTimeBegin.Text;
                        struWorkAttInfo.szEndTime = dateAttendanceTimeWorkTimeEnd.Text;
                        struWorkAttInfo.szSignInStartTime = dateAttendanceTimeValidSigninTimeBegin.Text;
                        struWorkAttInfo.szSignInEndTime = dateAttendanceTimeValidSigninTimeEnd.Text;
                        struWorkAttInfo.szSignOutStartTime = dateAttendanceTimeValidSignoutTimeBegin.Text;
                        struWorkAttInfo.szSignOutEndTime = dateAttendanceTimeValidSignoutTimeEnd.Text;
                        struWorkAttInfo.fWorkHours = Convert.ToSingle(numericUpDownAttendanceTimeWorkHours.Value);
                        struWorkAttInfo.iMustSignIn = checkBoxAttendanceTimeShallSignin.CheckState == CheckState.Checked ? 1 : 0;
                        struWorkAttInfo.iMustSignOut = checkBoxAttendanceTimeShallSignout.CheckState == CheckState.Checked ? 1 : 0;
                        Marshal.StructureToPtr(struWorkAttInfo, ptr, true);
                    }
                }

                struTimeIntervalData.iLater = Convert.ToInt32(textAttendanceTimeAttendanceRule1.Text);
                struTimeIntervalData.iLaterAbsence = Convert.ToInt32(textAttendanceTimeAttendanceRule2.Text);
                struTimeIntervalData.iEarly = Convert.ToInt32(textAttendanceTimeAttendanceRule3.Text);
                struTimeIntervalData.iEarlyAbsence = Convert.ToInt32(textAttendanceTimeAttendanceRule4.Text);
                struTimeIntervalData.iWorkOvertime = Convert.ToInt32(textAttendanceTimeAttendanceRule5.Text);
            }
            else if (struTimeIntervalData.iAttendanceModel == 2)//Free mode
            {
                struTimeIntervalData.fFreeWorkHours = Convert.ToSingle(numericUpDownAttendanceTimeHourSystem.Value);
                if (comboBoxAttendanceTimeFinalPunch.SelectedIndex != -1)
                {
                    struTimeIntervalData.iFreeWorkLimit = comboBoxAttendanceTimeFinalPunch.SelectedIndex;//Whether free time attendance is limited time: 0=unlimited, 1=restricted
                }
                struTimeIntervalData.szFreeLimitTime = dateAttendanceTimeFinalPunchInTime.Text;
                struTimeIntervalData.fRecordWorkHours = Convert.ToSingle(numericUpDownAttendancTimeWorkingHours.Value);
                struTimeIntervalData.szDayChangeTime = dateAttendanceTimeFinalPunchOutTime.Text;
                struTimeIntervalData.iEnableFreeWorkOver = checkBoxAttendancTimeOverTime.CheckState == CheckState.Checked ? 1 : 0;
                if (struTimeIntervalData.iEnableFreeWorkOver == 1)//Whether to enable overtime configuration for free attendance 0=Not enabled, 1=enabled
                {
                    struTimeIntervalData.fFreeWorkOvertime = Convert.ToSingle(numericUpDownAttendanceTimeOverTime.Value);
                }
                struTimeIntervalData.iEnableOddInEvenOut = checkBoxAttendanceTimeOddIn.CheckState == CheckState.Checked ? 1 : 0;
                if (struTimeIntervalData.iEnableOddInEvenOut == 1)//Whether to enable odd in and even out: 1=enabled, 0=Not enabled
                {
                    struTimeIntervalData.iSwingCardInterval = textAttendanceTimeMiniute.Text != "" ? Convert.ToInt32(textAttendanceTimeMiniute.Text) : 0;
                }
            }
            else
            {
                return;
            }

            DPSDK_RES iRet = DPSDK_AttendanceUpdateTimeInterval(m_iSessionID, ref struTimeIntervalData);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateTimeInterval") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateTimeInterval") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struTimeIntervalData.pWorkAttInfo != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struTimeIntervalData.pWorkAttInfo);
            }
        }

        private void btnAttendanceTimeDelTimeInterval_Click(object sender, EventArgs e)
        {
            DPSDK_DEL_TIMEINTERVAL_PARAM struDelTimeIntervalParam = new DPSDK_DEL_TIMEINTERVAL_PARAM();
            string strIntervalIDList = textAttendanceTimeIntervalID.Text;
            ArrayList arrIntervalID = new ArrayList();
            StringSplit(strIntervalIDList, ";", ref arrIntervalID);
            struDelTimeIntervalParam.iIdNum = arrIntervalID.Count;
            if (struDelTimeIntervalParam.iIdNum > 0)
            {
                struDelTimeIntervalParam.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struDelTimeIntervalParam.iIdNum);
                for (int i = 0; i < struDelTimeIntervalParam.iIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(struDelTimeIntervalParam.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                    DPSDK_TIMEINTERVAL_ID struTimeIntervalId = new DPSDK_TIMEINTERVAL_ID();
                    struTimeIntervalId.szId = (string)arrIntervalID[i];
                    Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceDelTimeInterval(m_iSessionID, ref struDelTimeIntervalParam, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelTimeInterval") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelTimeInterval") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struDelTimeIntervalParam.pIntervalIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struDelTimeIntervalParam.pIntervalIdList);
            }
        }

        private void btnAttendanceHolidayManageGetHolidayList_Click(object sender, EventArgs e)
        {
            DPSDK_GET_HOLIDAY_PARAM pGetHolidayParam = new DPSDK_GET_HOLIDAY_PARAM();
            pGetHolidayParam.iPageNo = Convert.ToInt32(textAttendanceHolidayManagePageNum.Text);
            pGetHolidayParam.iPageSize = Convert.ToInt32(textAttendanceHolidayManagePageSize.Text);
            pGetHolidayParam.szStartDate = dateAttendanceHolidayManageStartDate.Text;
            pGetHolidayParam.szEndDate = dateAttendanceHolidayManageEndDate.Text;
            DPSDK_RES iRet = DPSDK_AttendanceGetHolidayList(m_iSessionID, ref pGetHolidayParam, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetHolidayList") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetHolidayList") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceHolidayManageGetHolidayInfo_Click(object sender, EventArgs e)
        {
            string pHolidayId = textAttendanceHolidayManageHolidayID2.Text;
            IntPtr pGetResult = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_HOLIDAY_DATA)));
            DPSDK_RES iRet = DPSDK_AttendanceGetHolidayById(m_iSessionID, pHolidayId, pGetResult);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetHolidayById") + AppData._CS(" success."));

                DPSDK_HOLIDAY_DATA struHolidayData = (DPSDK_HOLIDAY_DATA)Marshal.PtrToStructure(pGetResult, typeof(DPSDK_HOLIDAY_DATA));
                ShowAttendanceInfo(AppData._CS("HolidayName = %1, HolidayID = %2, HolidayType = %3, HolidayValue = %4, HolidayDays = %5", Utf8StringToWideString(struHolidayData.szName), struHolidayData.szHolidayId, struHolidayData.iHolidayType.ToString(), struHolidayData.szHolidayValueStr, struHolidayData.iHolidayNum.ToString()));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetHolidayById") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            Marshal.FreeHGlobal(pGetResult);
        }

        private void btnAttendanceHolidayManageAddHoliday_Click(object sender, EventArgs e)
        {
            DPSDK_HOLIDAY_DATA struHolidayData = new DPSDK_HOLIDAY_DATA();
            struHolidayData.szName = WideStringToUtf8String(textAttendanceHolidayManageHolidayName.Text);
            if(comboBoxAttendanceHolidayManageHolidayMode.SelectedIndex != -1)
            {
                struHolidayData.iHolidayType = comboBoxAttendanceHolidayManageHolidayMode.SelectedIndex + 1;//Holiday type, 1 fixed date 2 recurring by date 3 recurring by year
            }
            struHolidayData.iHolidayNum = textAttendanceHolidayManageHolidayDay.Text != "" ? Convert.ToInt32(textAttendanceHolidayManageHolidayDay.Text) : 0;

            if (struHolidayData.iHolidayType == 1)
            {
                struHolidayData.szHolidayValueStr = dateAttendanceHolidayManageFixedDate.Value.ToString("yyyy-MM-dd");
            }
            else if (struHolidayData.iHolidayType == 2)
            {
                int iMonth = 0;
                int iOrder = 0;
                int iWeek = 0;
                if (comboBoxAttendanceHolidayManageDateCycleMonth.SelectedIndex != -1)
                {
                    iMonth = comboBoxAttendanceHolidayManageDateCycleMonth.SelectedIndex + 1;
                }
                if (comboBoxAttendanceHolidayManageDateCycleOrder.SelectedIndex != -1)
                {
                    iOrder = comboBoxAttendanceHolidayManageDateCycleOrder.SelectedIndex + 1;
                }
                if (comboBoxAttendanceHolidayManageDateCycleWeekday.SelectedIndex != -1)
                {
                    iWeek = comboBoxAttendanceHolidayManageDateCycleWeekday.SelectedIndex + 1;
                }
                struHolidayData.szHolidayValueStr = iMonth.ToString() + "," + iOrder.ToString() + "," + iWeek.ToString();
            }
            else if (struHolidayData.iHolidayType == 3)
            {
                string szMonth = textAttendanceHolidayManageYearCycleMonth.Text;
                string szDay = textAttendanceHolidayManageYearCycleDay.Text;
                struHolidayData.szHolidayValueStr = szMonth + "," + szDay;
            }

            DPSDK_RES iRet = DPSDK_AttendanceAddHoliday(m_iSessionID, ref struHolidayData);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddHoliday") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddHoliday") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceHolidayManageUpdateHoliday_Click(object sender, EventArgs e)
        {
            DPSDK_HOLIDAY_DATA struHolidayData = new DPSDK_HOLIDAY_DATA();
            struHolidayData.szHolidayId = textAttendanceHolidayManageHolidayID.Text;
            struHolidayData.szName = WideStringToUtf8String(textAttendanceHolidayManageHolidayName.Text);
            if (comboBoxAttendanceHolidayManageHolidayMode.SelectedIndex != -1)
            {
                struHolidayData.iHolidayType = comboBoxAttendanceHolidayManageHolidayMode.SelectedIndex + 1;//Holiday type, 1 fixed date 2 recurring by date 3 recurring by year
            }
            struHolidayData.iHolidayNum = textAttendanceHolidayManageHolidayDay.Text != "" ? Convert.ToInt32(textAttendanceHolidayManageHolidayDay.Text) : 0;

            if (struHolidayData.iHolidayType == 1)
            {
                struHolidayData.szHolidayValueStr = dateAttendanceHolidayManageFixedDate.Value.ToString("yyyy-MM-dd");
            }
            else if (struHolidayData.iHolidayType == 2)
            {
                int iMonth = 0;
                int iOrder = 0;
                int iWeek = 0;
                if (comboBoxAttendanceHolidayManageDateCycleMonth.SelectedIndex != -1)
                {
                    iMonth = comboBoxAttendanceHolidayManageDateCycleMonth.SelectedIndex + 1;
                }
                if (comboBoxAttendanceHolidayManageDateCycleOrder.SelectedIndex != -1)
                {
                    iOrder = comboBoxAttendanceHolidayManageDateCycleOrder.SelectedIndex + 1;
                }
                if (comboBoxAttendanceHolidayManageDateCycleWeekday.SelectedIndex != -1)
                {
                    iWeek = comboBoxAttendanceHolidayManageDateCycleWeekday.SelectedIndex + 1;
                }
                struHolidayData.szHolidayValueStr = iMonth.ToString() + "," + iOrder.ToString() + "," + iWeek.ToString();
            }
            else if (struHolidayData.iHolidayType == 3)
            {
                string szMonth = textAttendanceHolidayManageYearCycleMonth.Text;
                string szDay = textAttendanceHolidayManageYearCycleDay.Text;
                struHolidayData.szHolidayValueStr = szMonth + "," + szDay;
            }

            DPSDK_RES iRet = DPSDK_AttendanceUpdateHoliday(m_iSessionID, ref struHolidayData);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateHoliday") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateHoliday") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceHolidayManageDelHoliday_Click(object sender, EventArgs e)
        {
            DPSDK_DEL_HOLIDAY_INFO struDelHolidayInfo = new DPSDK_DEL_HOLIDAY_INFO();
            string strHolidayIDList = textAttendanceHolidayManageHolidayIDList.Text;
            ArrayList arrHolidayID = new ArrayList();
            StringSplit(strHolidayIDList, ";", ref arrHolidayID);
            struDelHolidayInfo.iHolidayNum = arrHolidayID.Count;
            if (struDelHolidayInfo.iHolidayNum > 0)
            {
                struDelHolidayInfo.pHolidayId = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ID)) * struDelHolidayInfo.iHolidayNum);
                for (int i = 0; i < struDelHolidayInfo.iHolidayNum; i++)
                {
                    IntPtr ptr = new IntPtr(struDelHolidayInfo.pHolidayId.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ID)) * i);
                    DPSDK_ID struHolidayId = new DPSDK_ID();
                    struHolidayId.szId = (string)arrHolidayID[i];
                    Marshal.StructureToPtr(struHolidayId, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceDelHoliday(m_iSessionID, ref struDelHolidayInfo);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelHoliday") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelHoliday") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struDelHolidayInfo.pHolidayId != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struDelHolidayInfo.pHolidayId);
            }
        }

        private void btnAttendanceShiftDailyApply_Click(object sender, EventArgs e)
        {
            int i = 0;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay1.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay2.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay3.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay4.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay5.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay6.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay7.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay8.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay9.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay10.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay11.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay12.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay13.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay14.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay15.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay16.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay17.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay18.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay19.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay20.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay21.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay22.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay23.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay24.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay25.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay26.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay27.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay28.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay29.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay30.Text;
            m_pDayInfo[i++].szId = textAttendanceShiftMonthDateDay31.Text;
        }

        private void btnAttendanceShiftWeeklyApply_Click(object sender, EventArgs e)
        {
            int i = 0;
            if (comboBoxAttendanceShiftMonthly.SelectedIndex != -1)
            {
                i = comboBoxAttendanceShiftMonthly.SelectedIndex * 7;
            }
            else
            {
                i = 0;
            }

            m_pWeekInfo[i++].szId = textAttendanceShiftWeeklySun.Text;
            m_pWeekInfo[i++].szId = textAttendanceShiftWeeklyMon.Text;
            m_pWeekInfo[i++].szId = textAttendanceShiftWeeklyTues.Text;
            m_pWeekInfo[i++].szId = textAttendanceShiftWeeklyWed.Text;
            m_pWeekInfo[i++].szId = textAttendanceShiftWeeklyThur.Text;
            m_pWeekInfo[i++].szId = textAttendanceShiftWeeklyFri.Text;
            m_pWeekInfo[i++].szId = textAttendanceShiftWeeklySat.Text;
        }

        private void btnAttendanceShiftMonthlyApply_Click(object sender, EventArgs e)
        {
            int i = 0;
            if (comboBoxAttendanceShiftMonthly.SelectedIndex != -1)
            {
                i = comboBoxAttendanceShiftMonthly.SelectedIndex * 31;
            }
            else
            {
                i = 0;
            }

            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay1.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay2.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay3.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay4.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay5.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay6.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay7.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay8.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay9.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay10.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay11.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay12.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay13.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay14.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay15.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay16.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay17.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay18.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay19.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay20.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay21.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay22.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay23.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay24.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay25.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay26.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay27.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay28.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay29.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay30.Text;
            m_pMonthInfo[i++].szId = textAttendanceShiftMonthDateDay31.Text;
        }

        private void btnAttendanceShiftClearCycleDate_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 31; i++)
            {
                m_pDayInfo[i].szId = "";
            }

            for (int i = 0; i < 4 * 7; i++)
            {
                m_pWeekInfo[i].szId = "";
            }

            for (int i = 0; i < 3 * 31; i++)
            {
                m_pMonthInfo[i].szId = "";
            }
        }

        private void btnAttendanceShiftGetIntervalList_Click(object sender, EventArgs e)
        {
            DPSDK_PAGE_INFO pPageInfo = new DPSDK_PAGE_INFO();
            pPageInfo.uiPage = 1;
            pPageInfo.uiPageSize = 256;
            DPSDK_RES iRet = DPSDK_AttendanceGetTimeIntervals(m_iSessionID, ref pPageInfo, fGetTimeIntervalsCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetTimeIntervals") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetTimeIntervals") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceShiftGetOrderList_Click(object sender, EventArgs e)
        {
            DPSDK_PAGE_INFO pPageInfo = new DPSDK_PAGE_INFO();
            pPageInfo.uiPage = 1;
            pPageInfo.uiPageSize = 256;
            DPSDK_RES iRet = DPSDK_AttendanceGetOrders(m_iSessionID, ref pPageInfo, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetOrders") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetOrders") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceShiftGetOrderInfoList_Click(object sender, EventArgs e)
        {
            DPSDK_ORDER_ID_LIST pOrderIdList = new DPSDK_ORDER_ID_LIST();
            string strIDList = textAttendanceShiftID.Text;
            ArrayList arrID = new ArrayList();
            StringSplit(strIDList, ";", ref arrID);
            pOrderIdList.iIdNum = arrID.Count;
            if (pOrderIdList.iIdNum > 0)
            {
                pOrderIdList.pOrgIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ORDER_ID)) * pOrderIdList.iIdNum);
                for (int i = 0; i < pOrderIdList.iIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(pOrderIdList.pOrgIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ORDER_ID)) * i);
                    DPSDK_ORDER_ID struOrderId = new DPSDK_ORDER_ID();
                    struOrderId.szId = (string)arrID[i];
                    Marshal.StructureToPtr(struOrderId, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceBatchGetOrders(m_iSessionID, ref pOrderIdList, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceBatchGetOrders") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceBatchGetOrders") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (pOrderIdList.pOrgIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(pOrderIdList.pOrgIdList);
            }
        }

        private void btnAttendanceShiftAddOrder_Click(object sender, EventArgs e)
        {
            DPSDK_ATTENDANCEORDER_INFO struAttendanceOrderInfo = new DPSDK_ATTENDANCEORDER_INFO();
            struAttendanceOrderInfo.szName = WideStringToUtf8String(textAttendanceShiftName.Text);
            if (comboBoxAttendanceShiftCyclicMode.SelectedIndex != -1)
            {
                struAttendanceOrderInfo.iLoopType = comboBoxAttendanceShiftCyclicMode.SelectedIndex + 1;
            }
            else
            {
                struAttendanceOrderInfo.iLoopType = 1;
            }
            struAttendanceOrderInfo.iLoopValue = textAttendanceShiftCyclicPeriod.Text != "" ? Convert.ToInt32(textAttendanceShiftCyclicPeriod.Text) : 0;

            //循环模式：1=日，2=周，3=月
            if (struAttendanceOrderInfo.iLoopType == 1)
            {
                struAttendanceOrderInfo.iIntervalNum = struAttendanceOrderInfo.iLoopValue;
                if (struAttendanceOrderInfo.iIntervalNum > 0 && struAttendanceOrderInfo.iIntervalNum <= 31)
                {
                    struAttendanceOrderInfo.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struAttendanceOrderInfo.iIntervalNum);
                    for (int i = 0; i < struAttendanceOrderInfo.iIntervalNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struAttendanceOrderInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                        DPSDK_TIMEINTERVAL_ID struTimeIntervalId = new DPSDK_TIMEINTERVAL_ID();
                        struTimeIntervalId.szId = m_pDayInfo[i].szId;
                        Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                    }
                }
                else
                {
                    return;
                }
            }
            else if (struAttendanceOrderInfo.iLoopType == 2)
            {
                if (struAttendanceOrderInfo.iLoopValue > 0 && struAttendanceOrderInfo.iLoopValue <= 4)
                {
                    struAttendanceOrderInfo.iIntervalNum = struAttendanceOrderInfo.iLoopValue * 7;
                    struAttendanceOrderInfo.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struAttendanceOrderInfo.iIntervalNum);
                    for (int i = 0; i < struAttendanceOrderInfo.iIntervalNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struAttendanceOrderInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                        DPSDK_TIMEINTERVAL_ID struTimeIntervalId = new DPSDK_TIMEINTERVAL_ID();
                        struTimeIntervalId.szId = m_pWeekInfo[i].szId;
                        Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                    }
                }
                else
                {
                    return;
                }
            }
            else if (struAttendanceOrderInfo.iLoopType == 3)
            {
                if (struAttendanceOrderInfo.iLoopValue > 0 && struAttendanceOrderInfo.iLoopValue <= 3)
                {
                    struAttendanceOrderInfo.iIntervalNum = struAttendanceOrderInfo.iLoopValue * 31;
                    struAttendanceOrderInfo.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struAttendanceOrderInfo.iIntervalNum);
                    for (int i = 0; i < struAttendanceOrderInfo.iIntervalNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struAttendanceOrderInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                        DPSDK_TIMEINTERVAL_ID struTimeIntervalId = new DPSDK_TIMEINTERVAL_ID();
                        struTimeIntervalId.szId = m_pMonthInfo[i].szId;
                        Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                    }
                }
                else
                {
                    return;
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceAddOrder(m_iSessionID, ref struAttendanceOrderInfo);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddOrder") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddOrder") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struAttendanceOrderInfo.pIntervalIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struAttendanceOrderInfo.pIntervalIdList);
            }
        }

        private void btnAttendanceShiftUpdateOrder_Click(object sender, EventArgs e)
        {
            DPSDK_ATTENDANCEORDER_INFO struAttendanceOrderInfo = new DPSDK_ATTENDANCEORDER_INFO();
            struAttendanceOrderInfo.szId = textAttendanceShiftID.Text;
            struAttendanceOrderInfo.szName = WideStringToUtf8String(textAttendanceShiftName.Text);
            if (comboBoxAttendanceShiftCyclicMode.SelectedIndex != -1)
            {
                struAttendanceOrderInfo.iLoopType = comboBoxAttendanceShiftCyclicMode.SelectedIndex + 1;
            }
            else
            {
                struAttendanceOrderInfo.iLoopType = 1;
            }
            struAttendanceOrderInfo.iLoopValue = textAttendanceShiftCyclicPeriod.Text != "" ? Convert.ToInt32(textAttendanceShiftCyclicPeriod.Text) : 0;

            //循环模式：1=日，2=周，3=月
            if (struAttendanceOrderInfo.iLoopType == 1)
            {
                struAttendanceOrderInfo.iIntervalNum = struAttendanceOrderInfo.iLoopValue;
                if (struAttendanceOrderInfo.iIntervalNum > 0 && struAttendanceOrderInfo.iIntervalNum <= 31)
                {
                    struAttendanceOrderInfo.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struAttendanceOrderInfo.iIntervalNum);
                    for (int i = 0; i < struAttendanceOrderInfo.iIntervalNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struAttendanceOrderInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                        DPSDK_TIMEINTERVAL_ID struTimeIntervalId = new DPSDK_TIMEINTERVAL_ID();
                        struTimeIntervalId.szId = m_pDayInfo[i].szId;
                        Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                    }
                }
                else
                {
                    return;
                }
            }
            else if (struAttendanceOrderInfo.iLoopType == 2)
            {
                if (struAttendanceOrderInfo.iLoopValue > 0 && struAttendanceOrderInfo.iLoopValue <= 4)
                {
                    struAttendanceOrderInfo.iIntervalNum = struAttendanceOrderInfo.iLoopValue * 7;
                    struAttendanceOrderInfo.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struAttendanceOrderInfo.iIntervalNum);
                    for (int i = 0; i < struAttendanceOrderInfo.iIntervalNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struAttendanceOrderInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                        DPSDK_TIMEINTERVAL_ID struTimeIntervalId = new DPSDK_TIMEINTERVAL_ID();
                        struTimeIntervalId.szId = m_pWeekInfo[i].szId;
                        Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                    }
                }
                else
                {
                    return;
                }
            }
            else if (struAttendanceOrderInfo.iLoopType == 3)
            {
                if (struAttendanceOrderInfo.iLoopValue > 0 && struAttendanceOrderInfo.iLoopValue <= 3)
                {
                    struAttendanceOrderInfo.iIntervalNum = struAttendanceOrderInfo.iLoopValue * 31;
                    struAttendanceOrderInfo.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struAttendanceOrderInfo.iIntervalNum);
                    for (int i = 0; i < struAttendanceOrderInfo.iIntervalNum; i++)
                    {
                        IntPtr ptr = new IntPtr(struAttendanceOrderInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                        DPSDK_TIMEINTERVAL_ID struTimeIntervalId = new DPSDK_TIMEINTERVAL_ID();
                        struTimeIntervalId.szId = m_pMonthInfo[i].szId;
                        Marshal.StructureToPtr(struTimeIntervalId, ptr, true);
                    }
                }
                else
                {
                    return;
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceUpdateOrder(m_iSessionID, ref struAttendanceOrderInfo);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateOrder") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateOrder") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struAttendanceOrderInfo.pIntervalIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struAttendanceOrderInfo.pIntervalIdList);
            }
        }

        private void btnAttendanceShiftDelOrder_Click(object sender, EventArgs e)
        {
            DPSDK_ORDER_ID_LIST pOrderIdList = new DPSDK_ORDER_ID_LIST();
            string strIDList = textAttendanceShiftID.Text;
            ArrayList arrID = new ArrayList();
            StringSplit(strIDList, ";", ref arrID);
            pOrderIdList.iIdNum = arrID.Count;
            if (pOrderIdList.iIdNum > 0)
            {
                pOrderIdList.pOrgIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ORDER_ID)) * pOrderIdList.iIdNum);
                for (int i = 0; i < pOrderIdList.iIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(pOrderIdList.pOrgIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ORDER_ID)) * i);
                    DPSDK_ORDER_ID struOrderId = new DPSDK_ORDER_ID();
                    struOrderId.szId = (string)arrID[i];
                    Marshal.StructureToPtr(struOrderId, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceDelOrder(m_iSessionID, ref pOrderIdList, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelOrder") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelOrder") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (pOrderIdList.pOrgIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(pOrderIdList.pOrgIdList);
            }
        }

        private void btnDepartmentShiftGetDepartmentList_Click(object sender, EventArgs e)
        {
            DPSDK_RES iRet = DPSDK_GetDepartmentTree(m_iSessionID, "", fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_GetDepartmentTree") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_GetDepartmentTree") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnDepartmentShiftGetDeptSchedule_Click(object sender, EventArgs e)
        {
            if (comboBoxDepartmentShiftDepartmentList.SelectedIndex == -1)
                return;

            string pDeptId = ((ComboBoxItem)comboBoxDepartmentShiftDepartmentList.SelectedItem).Value;
            DPSDK_RES iRet = DPSDK_AttendanceGetDeptSchedule(m_iSessionID, pDeptId, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetDeptSchedule") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetDeptSchedule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnDepartmentShiftUpdateDeptSchedule_Click(object sender, EventArgs e)
        {
            if (comboBoxDepartmentShiftDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_UPDATE_DEPT_SCHEDULE struUpdateDeptSchedule = new DPSDK_UPDATE_DEPT_SCHEDULE();
            struUpdateDeptSchedule.iDeptIdNum = 1;
            if (struUpdateDeptSchedule.iDeptIdNum > 0)
            {
                struUpdateDeptSchedule.pDeptIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ID)) * struUpdateDeptSchedule.iDeptIdNum);
                for (int i = 0; i < struUpdateDeptSchedule.iDeptIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(struUpdateDeptSchedule.pDeptIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ID)) * i);
                    DPSDK_ID struDpsdkID = new DPSDK_ID();
                    struDpsdkID.szId = ((ComboBoxItem)comboBoxDepartmentShiftDepartmentList.SelectedItem).Value;
                    Marshal.StructureToPtr(struDpsdkID, ptr, true);
                }
            }

            struUpdateDeptSchedule.iStandardOrderNum = 1;
            if (struUpdateDeptSchedule.iStandardOrderNum > 0)
            {
                struUpdateDeptSchedule.pStandardOrderList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO)) * struUpdateDeptSchedule.iStandardOrderNum);
                for (int i = 0; i < struUpdateDeptSchedule.iStandardOrderNum; i++)
                {
                    IntPtr ptr = new IntPtr(struUpdateDeptSchedule.pStandardOrderList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO)) * i);
                    DPSDK_STANDARD_SCHEDULE_ORDER_INFO struScheduleOrderInfo = new DPSDK_STANDARD_SCHEDULE_ORDER_INFO();
                    struScheduleOrderInfo.szStartDate = dateDepartmentShiftStartDate.Value.ToString("yyyy-MM-dd");
                    struScheduleOrderInfo.szEndDate = dateDepartmentShiftEndDate.Value.ToString("yyyy-MM-dd");
                    struScheduleOrderInfo.szOrderId = textDepartmentShiftShiftID.Text;
                    Marshal.StructureToPtr(struScheduleOrderInfo, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceUpdateDeptSchedule(m_iSessionID, ref struUpdateDeptSchedule);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateDeptSchedule") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateDeptSchedule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struUpdateDeptSchedule.pDeptIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struUpdateDeptSchedule.pDeptIdList);
            }
            if (struUpdateDeptSchedule.pStandardOrderList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struUpdateDeptSchedule.pStandardOrderList);
            }
        }

        private void btnPersonnelGetPersonSchedule_Click(object sender, EventArgs e)
        {
            if (comboBoxPersonnelDepartmentList.SelectedIndex == -1)
                return;

            string pPersonId = ((ComboBoxItem)comboBoxPersonnelDepartmentList.SelectedItem).Value;
            DPSDK_RES iRet = DPSDK_AttendanceGetSchedule(m_iSessionID, pPersonId, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetSchedule") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetSchedule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnPersonnelUpdatePersonSchedule_Click(object sender, EventArgs e)
        {
            if (comboBoxPersonnelDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_UPDATE_PERSON_SCHEDULE struUpdatePersonSchedule = new DPSDK_UPDATE_PERSON_SCHEDULE();
            struUpdatePersonSchedule.iPersonIdNum = 1;
            if (struUpdatePersonSchedule.iPersonIdNum > 0)
            {
                struUpdatePersonSchedule.pPersonIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ID)) * struUpdatePersonSchedule.iPersonIdNum);
                for (int i = 0; i < struUpdatePersonSchedule.iPersonIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(struUpdatePersonSchedule.pPersonIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_ID)) * i);
                    DPSDK_ID struDpsdkID = new DPSDK_ID();
                    struDpsdkID.szId = ((ComboBoxItem)comboBoxPersonnelDepartmentList.SelectedItem).Value;
                    Marshal.StructureToPtr(struDpsdkID, ptr, true);
                }
            }

            struUpdatePersonSchedule.iStandardOrderNum = 1;
            if (struUpdatePersonSchedule.iStandardOrderNum > 0)
            {
                struUpdatePersonSchedule.pStandardOrderList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO)) * struUpdatePersonSchedule.iStandardOrderNum);
                for (int i = 0; i < struUpdatePersonSchedule.iStandardOrderNum; i++)
                {
                    IntPtr ptr = new IntPtr(struUpdatePersonSchedule.pStandardOrderList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_STANDARD_SCHEDULE_ORDER_INFO)) * i);
                    DPSDK_STANDARD_SCHEDULE_ORDER_INFO struScheduleOrderInfo = new DPSDK_STANDARD_SCHEDULE_ORDER_INFO();
                    struScheduleOrderInfo.szStartDate = datePersonnelStartDate.Value.ToString("yyyy-MM-dd");
                    struScheduleOrderInfo.szEndDate = datePersonnelEndDate.Value.ToString("yyyy-MM-dd");
                    struScheduleOrderInfo.szOrderId = textPersonnelShiftID.Text;
                    Marshal.StructureToPtr(struScheduleOrderInfo, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceUpdateSchedule(m_iSessionID, ref struUpdatePersonSchedule);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateSchedule") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceUpdateSchedule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struUpdatePersonSchedule.pPersonIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struUpdatePersonSchedule.pPersonIdList);
            }
            if (struUpdatePersonSchedule.pStandardOrderList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struUpdatePersonSchedule.pStandardOrderList);
            }
        }

        private void btnPersonnelAddTempSchedule_Click(object sender, EventArgs e)
        {
            if (comboBoxPersonnelDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_SCHEDULE_TEMP_INFO struScheduleTempInfo = new DPSDK_SCHEDULE_TEMP_INFO();
            struScheduleTempInfo.szTempDate = datePersonnelTempDate.Value.ToString("yyyy-MM-dd");
            struScheduleTempInfo.iPersonIdNum = 1;
            if (struScheduleTempInfo.iPersonIdNum > 0)
            {
                struScheduleTempInfo.pPersonIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_PERSON_ID)) * struScheduleTempInfo.iPersonIdNum);
                for (int i = 0; i < struScheduleTempInfo.iPersonIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(struScheduleTempInfo.pPersonIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_PERSON_ID)) * i);
                    DPSDK_PERSON_ID struPersonID = new DPSDK_PERSON_ID();
                    struPersonID.szPersonId = ((ComboBoxItem)comboBoxPersonnelDepartmentList.SelectedItem).Value;
                    Marshal.StructureToPtr(struPersonID, ptr, true);
                }
            }

            struScheduleTempInfo.iIntervalIdNum = 1;
            if (struScheduleTempInfo.iIntervalIdNum > 0)
            {
                struScheduleTempInfo.pIntervalIdList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * struScheduleTempInfo.iIntervalIdNum);
                for (int i = 0; i < struScheduleTempInfo.iIntervalIdNum; i++)
                {
                    IntPtr ptr = new IntPtr(struScheduleTempInfo.pIntervalIdList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_TIMEINTERVAL_ID)) * i);
                    DPSDK_TIMEINTERVAL_ID struTimeIntervalID = new DPSDK_TIMEINTERVAL_ID();
                    struTimeIntervalID.szId = textPersonnelIntervalID.Text;
                    Marshal.StructureToPtr(struTimeIntervalID, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceAddTempSchedule(m_iSessionID, ref struScheduleTempInfo);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddTempSchedule") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAddTempSchedule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struScheduleTempInfo.pPersonIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struScheduleTempInfo.pPersonIdList);
            }
            if (struScheduleTempInfo.pIntervalIdList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struScheduleTempInfo.pIntervalIdList);
            }
        }

        private void btnPersonnelDelTempSchedule_Click(object sender, EventArgs e)
        {
            if (comboBoxPersonnelDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_DEL_SCHEDULE_TEMP_INFO struDelScheduleTempInfo = new DPSDK_DEL_SCHEDULE_TEMP_INFO();
            struDelScheduleTempInfo.szPersonId = ((ComboBoxItem)comboBoxPersonnelDepartmentList.SelectedItem).Value;
            struDelScheduleTempInfo.szTempDate = datePersonnelTempDate.Value.ToString("yyyy-MM-dd");

            DPSDK_RES iRet = DPSDK_AttendanceDelTempSchedule(m_iSessionID, ref struDelScheduleTempInfo);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelTempSchedule") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceDelTempSchedule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceReportGetDepartmentList_Click(object sender, EventArgs e)
        {
            DPSDK_RES iRet = DPSDK_GetDepartmentTree(m_iSessionID, "", fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_GetDepartmentTree") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_GetDepartmentTree") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceReportCardRecordExport_Click(object sender, EventArgs e)
        {
            if (comboBoxAttendanceReportDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_ATTENDANCE_RECORD struAttendanceRecord = new DPSDK_ATTENDANCE_RECORD();
            struAttendanceRecord.szStartTime = dateAttendanceReportStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szEndTime = dateAttendanceReportEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szKeyWord = textAttendanceReportID.Text;
            struAttendanceRecord.szDeptId = ((ComboBoxItem)comboBoxAttendanceReportDepartmentList.SelectedItem).Value;
            struAttendanceRecord.szLocale = "en";
            struAttendanceRecord.iExportType = 5;
            if (comboBoxAttendanceReportAttendanceEvent.SelectedIndex != -1)/** Attendance events, 0: all 1: check in 2: check out 3: go out 4: go back */
            {
                struAttendanceRecord.szEventType = comboBoxAttendanceReportAttendanceEvent.SelectedIndex.ToString();
            }
            else
            {
                struAttendanceRecord.szEventType = "0";
            }

            IntPtr pFileUrl = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ATTENDANCE_FILE_URL)));
            DPSDK_RES iRet = DPSDK_AttendanceCardRecord(m_iSessionID, ref struAttendanceRecord, pFileUrl);
            if (iRet == DPSDK_SUCCESS)
            {
                string strResult = AppData._CS("DPSDK_AttendanceCardRecord") + AppData._CS(" success.");
                strResult += "\r\n";
                DPSDK_ATTENDANCE_FILE_URL struAttendanceFileUrl = (DPSDK_ATTENDANCE_FILE_URL)Marshal.PtrToStructure(pFileUrl, typeof(DPSDK_ATTENDANCE_FILE_URL));
                strResult += AppData._CS("File Url = %1", struAttendanceFileUrl.szFileUrl);
                ShowAttendanceInfo(strResult);
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceCardRecord") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            Marshal.FreeHGlobal(pFileUrl);
        }

        private void btnAttendanceReportAttendanceReportExport_Click(object sender, EventArgs e)
        {
            if (comboBoxAttendanceReportDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_ATTENDANCE_RECORD struAttendanceRecord = new DPSDK_ATTENDANCE_RECORD();
            struAttendanceRecord.szStartTime = dateAttendanceReportStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szEndTime = dateAttendanceReportEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szKeyWord = textAttendanceReportID.Text;
            struAttendanceRecord.szDeptId = ((ComboBoxItem)comboBoxAttendanceReportDepartmentList.SelectedItem).Value;
            struAttendanceRecord.szLocale = "en";
            struAttendanceRecord.iExportType = 5;

            IntPtr pFileUrl = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ATTENDANCE_FILE_URL)));
            DPSDK_RES iRet = DPSDK_AttendanceInfoRecord(m_iSessionID, ref struAttendanceRecord, pFileUrl);
            if (iRet == DPSDK_SUCCESS)
            {
                string strResult = AppData._CS("DPSDK_AttendanceInfoRecord") + AppData._CS(" success.");
                strResult += "\r\n";
                DPSDK_ATTENDANCE_FILE_URL struAttendanceFileUrl = (DPSDK_ATTENDANCE_FILE_URL)Marshal.PtrToStructure(pFileUrl, typeof(DPSDK_ATTENDANCE_FILE_URL));
                strResult += AppData._CS("File Url = %1", struAttendanceFileUrl.szFileUrl);
                ShowAttendanceInfo(strResult);
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceInfoRecord") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            Marshal.FreeHGlobal(pFileUrl);
        }

        private void btnAttendanceReportAwayExport_Click(object sender, EventArgs e)
        {
            if (comboBoxAttendanceReportDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_ATTENDANCE_RECORD struAttendanceRecord = new DPSDK_ATTENDANCE_RECORD();
            struAttendanceRecord.szStartTime = dateAttendanceReportStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szEndTime = dateAttendanceReportEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szKeyWord = textAttendanceReportID.Text;
            struAttendanceRecord.szDeptId = ((ComboBoxItem)comboBoxAttendanceReportDepartmentList.SelectedItem).Value;
            struAttendanceRecord.szLocale = "en";
            struAttendanceRecord.iExportType = 5;

            IntPtr pFileUrl = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ATTENDANCE_FILE_URL)));
            DPSDK_RES iRet = DPSDK_AttendanceOuting(m_iSessionID, ref struAttendanceRecord, pFileUrl);
            if (iRet == DPSDK_SUCCESS)
            {
                string strResult = AppData._CS("DPSDK_AttendanceOuting") + AppData._CS(" success.");
                strResult += "\r\n";
                DPSDK_ATTENDANCE_FILE_URL struAttendanceFileUrl = (DPSDK_ATTENDANCE_FILE_URL)Marshal.PtrToStructure(pFileUrl, typeof(DPSDK_ATTENDANCE_FILE_URL));
                strResult += AppData._CS("File Url = %1", struAttendanceFileUrl.szFileUrl);
                ShowAttendanceInfo(strResult);
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceOuting") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            Marshal.FreeHGlobal(pFileUrl);
        }

        private void btnAttendanceReportAbnormalityExport_Click(object sender, EventArgs e)
        {
            if (comboBoxAttendanceReportDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_ATTENDANCE_RECORD struAttendanceRecord = new DPSDK_ATTENDANCE_RECORD();
            struAttendanceRecord.szStartTime = dateAttendanceReportStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szEndTime = dateAttendanceReportEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szKeyWord = textAttendanceReportID.Text;
            struAttendanceRecord.szDeptId = ((ComboBoxItem)comboBoxAttendanceReportDepartmentList.SelectedItem).Value;
            struAttendanceRecord.szLocale = "en";
            struAttendanceRecord.iExportType = 5;
            if (comboBoxAttendanceReportAbnormalType.SelectedIndex != -1)/** Attendance events, 0 all 1: late 2: leave early 3: absenteeism 4: late and leave early 5: forget to check in 6: late and forget to check in 7: forget to check in and leave early */
            {
                struAttendanceRecord.szEventType = comboBoxAttendanceReportAbnormalType.SelectedIndex.ToString();
            }
            else
            {
                struAttendanceRecord.szEventType = "0";
            }

            IntPtr pFileUrl = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ATTENDANCE_FILE_URL)));
            DPSDK_RES iRet = DPSDK_AttendanceAbnormalRecord(m_iSessionID, ref struAttendanceRecord, pFileUrl);
            if (iRet == DPSDK_SUCCESS)
            {
                string strResult = AppData._CS("DPSDK_AttendanceAbnormalRecord") + AppData._CS(" success.");
                strResult += "\r\n";
                DPSDK_ATTENDANCE_FILE_URL struAttendanceFileUrl = (DPSDK_ATTENDANCE_FILE_URL)Marshal.PtrToStructure(pFileUrl, typeof(DPSDK_ATTENDANCE_FILE_URL));
                strResult += AppData._CS("File Url = %1", struAttendanceFileUrl.szFileUrl);
                ShowAttendanceInfo(strResult);
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceAbnormalRecord") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            Marshal.FreeHGlobal(pFileUrl);
        }

        private void btnAttendanceReportOverTimeExport_Click(object sender, EventArgs e)
        {
            if (comboBoxAttendanceReportDepartmentList.SelectedIndex == -1)
                return;

            DPSDK_ATTENDANCE_RECORD struAttendanceRecord = new DPSDK_ATTENDANCE_RECORD();
            struAttendanceRecord.szStartTime = dateAttendanceReportStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szEndTime = dateAttendanceReportEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            struAttendanceRecord.szKeyWord = textAttendanceReportID.Text;
            struAttendanceRecord.szDeptId = ((ComboBoxItem)comboBoxAttendanceReportDepartmentList.SelectedItem).Value;
            struAttendanceRecord.szLocale = "en";
            struAttendanceRecord.iExportType = 5;
            if (comboBoxAttendanceReportOverTimeType.SelectedIndex != -1)/** Overtime type 1 Normal 2 Rest 3 Holiday */
            {
                struAttendanceRecord.szEventType = comboBoxAttendanceReportOverTimeType.SelectedIndex.ToString();
            }
            else
            {
                struAttendanceRecord.szEventType = "1";
            }

            IntPtr pFileUrl = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_ATTENDANCE_FILE_URL)));
            DPSDK_RES iRet = DPSDK_AttendanceWorkOverTime(m_iSessionID, ref struAttendanceRecord, pFileUrl);
            if (iRet == DPSDK_SUCCESS)
            {
                string strResult = AppData._CS("DPSDK_AttendanceWorkOverTime") + AppData._CS(" success.");
                strResult += "\r\n";
                DPSDK_ATTENDANCE_FILE_URL struAttendanceFileUrl = (DPSDK_ATTENDANCE_FILE_URL)Marshal.PtrToStructure(pFileUrl, typeof(DPSDK_ATTENDANCE_FILE_URL));
                strResult += AppData._CS("File Url = %1", struAttendanceFileUrl.szFileUrl);
                ShowAttendanceInfo(strResult);
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceWorkOverTime") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            Marshal.FreeHGlobal(pFileUrl);
        }

        private void btnAttendanceConfigAttendanceGetChannels_Click(object sender, EventArgs e)
        {
            DPSDK_PAGE_INFO pPageInfo = new DPSDK_PAGE_INFO();
            pPageInfo.uiPage = 1;
            pPageInfo.uiPageSize = 256;
            DPSDK_RES iRet = DPSDK_AttendanceGetChannels(m_iSessionID, ref pPageInfo, fAttendanceDataCallback, IntPtr.Zero);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetChannels") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetChannels") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceConfigAttendanceSaveChannels_Click(object sender, EventArgs e)
        {
            DPSDK_ATTENDANCE_CHANNEL_PARAM struAttendanceChannelParam = new DPSDK_ATTENDANCE_CHANNEL_PARAM();
            string strChannelIDList = textAttendanceConfigChannelIDList.Text;
            ArrayList arrChannelID = new ArrayList();
            StringSplit(strChannelIDList, ";", ref arrChannelID);
            struAttendanceChannelParam.iChannelNum = arrChannelID.Count;
            if (struAttendanceChannelParam.iChannelNum > 0)
            {
                struAttendanceChannelParam.pChannelList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DPSDK_CHANNEL_ID)) * struAttendanceChannelParam.iChannelNum);
                for (int i = 0; i < struAttendanceChannelParam.iChannelNum; i++)
                {
                    IntPtr ptr = new IntPtr(struAttendanceChannelParam.pChannelList.ToInt32() + Marshal.SizeOf(typeof(DPSDK_CHANNEL_ID)) * i);
                    DPSDK_CHANNEL_ID struChannelId = new DPSDK_CHANNEL_ID();
                    struChannelId.szId = (string)arrChannelID[i];
                    Marshal.StructureToPtr(struChannelId, ptr, true);
                }
            }

            DPSDK_RES iRet = DPSDK_AttendanceSaveChannels(m_iSessionID, ref struAttendanceChannelParam);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceSaveChannels") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceSaveChannels") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }

            if (struAttendanceChannelParam.pChannelList != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(struAttendanceChannelParam.pChannelList);
            }
        }

        private void btnAttendanceConfigAttendanceSaveStatisRule_Click(object sender, EventArgs e)
        {
            IntPtr iStatisRule = new IntPtr(checkBoxAttendanceConfigRoundDown.CheckState == CheckState.Checked ? 1 : 0);
            DPSDK_RES iRet = DPSDK_AttendanceSaveStatisRule(m_iSessionID, iStatisRule);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceSaveStatisRule") + AppData._CS(" success."));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceSaveStatisRule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }

        private void btnAttendanceConfigAttendanceGetStatisRule_Click(object sender, EventArgs e)
        {
            IntPtr pStatisRule = IntPtr.Zero;
            DPSDK_RES iRet = DPSDK_AttendanceGetStatisRule(m_iSessionID, ref pStatisRule);
            if (iRet == DPSDK_SUCCESS)
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetStatisRule") + AppData._CS(" success."));
                ShowAttendanceInfo(AppData._CS("StatisticsRule = %1", pStatisRule.ToString()));
            }
            else
            {
                ShowAttendanceInfo(AppData._CS("DPSDK_AttendanceGetStatisRule") + AppData._CS(" failed. error code = %1.", iRet.ToString()));
            }
        }
    }
}