Example #1
0
void CNewTstatSchedulesDlg::OnBnClickedButtonInsert()
{

 


 
		CSetTimeDlg dlg;
		if (dlg.DoModal() == IDOK)
		{
			CString temp = dlg.m_strTime;
			Schedule_Node sr;
			CStringArray aaa;
			SplitCStringA(aaa, temp, L":");
			if (aaa.GetSize() >= 2)
			{
				sr.Hour = _wtoi(aaa[0]);
				sr.Minite = _wtoi(aaa[1]);
				InsertAndUpdate_Schdule(sr);

				WeeeklyList.InsertItem(WeeeklyList.GetRowCount(), L"");
			}

			Fresh_List();

		}

 



}
Example #2
0
LRESULT CNewTstatSchedulesDlg::Fresh_Input_Item(WPARAM wParam,LPARAM lParam)
{ 
	int Changed_Item = (int)wParam;
	int Changed_SubItem = (int)lParam;
	CString New_CString =  WeeeklyList.GetItemText(Changed_Item,Changed_SubItem);
	BOOL is_change = FALSE;
	if (Changed_SubItem>1)
	{
		int tempvalue = getvalue(New_CString); 
		if (tempvalue==0||(GetDayScheduleCount(Changed_SubItem)<=6))
		{
			if (GetValueItem(Changed_Item,Changed_SubItem)!=tempvalue)
			{
				SetValueItem(Changed_Item,Changed_SubItem,tempvalue);
				is_change = TRUE;
			}
		}
		else
		{
			AfxMessageBox(L"Can't be more than 6 !");
			is_change = TRUE;
		}

		
	}
	if (Changed_SubItem == 1)
	{
		CStringArray temparray;
		SplitCStringA(temparray,New_CString,_T(":"));
		if (temparray.GetSize()<=1)
		{
			AfxMessageBox(_T("The time that you input is not correct!"));
		   is_change = TRUE;
		}
		int Hour = _wtoi(temparray[0]);
		int minute = _wtoi(temparray[1]);
		int tempvalue = Hour*60+minute;
		
		if (GetValueItem(Changed_Item,Changed_SubItem)!=tempvalue)
		{
			SetValueItem(Changed_Item,Changed_SubItem,tempvalue);
			is_change = TRUE;
		}
		 
	}
	 
	Fresh_List();
	 

	return 0;
}
Example #3
0
void CNewTstatSchedulesDlg::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)
{
	 
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	CString temp_cstring;
	long lRow, lCol;

	DWORD dwPos = GetMessagePos();//Get which line is click by user.Set the check box, when user enter Insert it will jump to program dialog
	CPoint point(LOWORD(dwPos), HIWORD(dwPos));
	WeeeklyList.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt = point;
	lvinfo.flags = LVHT_ABOVE;
	int nItem = WeeeklyList.SubItemHitTest(&lvinfo);

	lRow = lvinfo.iItem;
	lCol = lvinfo.iSubItem;


 
		 CSetTimeDlg dlg;
		 if (dlg.DoModal() == IDOK)
		 {
			 CString temp = dlg.m_strTime;
			 Schedule_Node sr;
			 CStringArray aaa;
			 SplitCStringA(aaa, temp, L":");
			 if (aaa.GetSize() >= 2)
			 {
				 sr.Hour = _wtoi(aaa[0]);
				 sr.Minite = _wtoi(aaa[1]);
				 InsertAndUpdate_Schdule(sr);
				 
				 WeeeklyList.InsertItem(WeeeklyList.GetRowCount(), L"");
			 }
			 
			 Fresh_List();

		 }
		 
	 
	
	
	if (lRow < 0)
		return;
	*pResult = 0;
}
Example #4
0
int GetVariableValue(int index ,CString &ret_cstring,CString &ret_unit,CString &Auto_M,int &digital_value)
{
	CStringArray temparray;
	CString temp1;
	if(index >= BAC_VARIABLE_ITEM_COUNT)
	{
		ret_cstring.Empty();
		ret_unit.Empty();
		Auto_M.Empty();
		return -1;
	}
	int i = index;

	if(m_Variable_data.at(i).auto_manual == 1)
	{
		Auto_M = _T("M");
	}
	else
	{
		Auto_M.Empty();
	}

	if(m_Variable_data.at(i).digital_analog == BAC_UNITS_DIGITAL)
	{
		if(m_Variable_data.at(i).range>30)
		{
			ret_cstring = _T("Range Error");
			return RANGE_ERROR;
		}
		else
		{
			if((m_Variable_data.at(i).range < 23) &&(m_Variable_data.at(i).range !=0))
				temp1 = Digital_Units_Array[m_Variable_data.at(i).range];
			else if((m_Variable_data.at(i).range >=23) && (m_Variable_data.at(i).range <= 30))
			{
				if(receive_customer_unit)
					temp1 = temp_unit_no_index[m_Variable_data.at(i).range - 23];
			}
			else
			{
				ret_cstring = _T("Range Error");
				return RANGE_ERROR;
			}


			SplitCStringA(temparray,temp1,_T("/"));
			if((temparray.GetSize()==2))
			{
				if(m_Variable_data.at(i).control == 0)
				{
					digital_value = 0;
					ret_cstring = temparray.GetAt(0);
					return 1;
				}
				else
				{
					digital_value = 1;
					ret_cstring = temparray.GetAt(1);
				}
			}

		}
	}
	else
	{
		if(m_Variable_data.at(i).range == 20)	//如果是时间;
		{
			ret_unit = Variable_Analog_Units_Array[m_Variable_data.at(i).range];
			char temp_char[50];
			int time_seconds = m_Variable_data.at(i).value / 1000;
			intervaltotextfull(temp_char,time_seconds,0,0);

			MultiByteToWideChar( CP_ACP, 0, temp_char, strlen(temp_char) + 1, 
				ret_cstring.GetBuffer(MAX_PATH), MAX_PATH );
			ret_cstring.ReleaseBuffer();	
			digital_value = 2;

		}
		else if((m_Variable_data.at(i).range<=sizeof(Variable_Analog_Units_Array)/sizeof(Variable_Analog_Units_Array[0])) && (m_Variable_data.at(i).range != 0))
		{
			ret_unit = Variable_Analog_Units_Array[m_Variable_data.at(i).range];
			CString cstemp_value;
			float temp_float_value;
			temp_float_value = ((float)m_Variable_data.at(i).value) / 1000;
			ret_cstring.Format(_T("%.3f"),temp_float_value);
			digital_value = 2;
		}
		else
		{
			ret_cstring = _T("Range Error");
			ret_cstring.Empty();
			return RANGE_ERROR;
		}
	}

	return 1;
}
void CBacnetInput::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
    // TODO: Add your control notification handler code here

    long lRow,lCol;
    m_input_list.Set_Edit(true);
    DWORD dwPos=GetMessagePos();//Get which line is click by user.Set the check box, when user enter Insert it will jump to program dialog
    CPoint point( LOWORD(dwPos), HIWORD(dwPos));
    m_input_list.ScreenToClient(&point);
    LVHITTESTINFO lvinfo;
    lvinfo.pt=point;
    lvinfo.flags=LVHT_ABOVE;
    int nItem=m_input_list.SubItemHitTest(&lvinfo);

    lRow = lvinfo.iItem;
    lCol = lvinfo.iSubItem;


    if(lRow>m_input_list.GetItemCount()) //如果点击区超过最大行号,则点击是无效的
        return;
    if(lRow<0)
        return;

    if(lCol != INPUT_VALUE)
        return;

    if(m_Input_data.at(lRow).digital_analog != BAC_UNITS_DIGITAL)
        return;

    if(m_Input_data.at(lRow).auto_manual == BAC_AUTO)	//If it is auto mode, disable to change the value.
        return;

    memcpy_s(&m_temp_Input_data[lRow],sizeof(Str_in_point),&m_Input_data.at(lRow),sizeof(Str_in_point));

    CString New_CString;
    CString temp_task_info;

    CString temp1;
    CStringArray temparray;
    if((m_Input_data.at(lRow).range < 23) &&(m_Input_data.at(lRow).range !=0))
        temp1 = Digital_Units_Array[m_Input_data.at(lRow).range];
    else
        return;
    SplitCStringA(temparray,temp1,_T("/"));

    if(m_Input_data.at(lRow).control == 0)
    {
        m_Input_data.at(lRow).control = 1;
        m_input_list.SetItemText(lRow,INPUT_VALUE,temparray.GetAt(1));
        New_CString = temparray.GetAt(1);
    }
    else
    {
        m_Input_data.at(lRow).control = 0;
        m_input_list.SetItemText(lRow,INPUT_VALUE,temparray.GetAt(0));
        New_CString = temparray.GetAt(0);
    }
#if 0
    if(m_Input_data.at(lRow).range > 11)
        temp1 = Digital_Units_Array[m_Input_data.at(lRow).range - 11];//11 is the sizeof the array
    else
        temp1 = Digital_Units_Array[m_Input_data.at(lRow).range];
    SplitCStringA(temparray,temp1,_T("/"));

    if(m_Input_data.at(lRow).range>=12)
    {

        if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
        {
            m_input_list.SetItemText(lRow,INPUT_VALUE,temparray.GetAt(0));
            m_Input_data.at(lRow).range = m_Input_data.at(lRow).range - 11;
            New_CString = temparray.GetAt(0);
            m_Input_data.at(lRow).control = 0;
        }

    }
    else if(m_Input_data.at(lRow).range>=1)
    {

        if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
        {
            m_input_list.SetItemText(lRow,INPUT_VALUE,temparray.GetAt(1));
            m_Input_data.at(lRow).range = m_Input_data.at(lRow).range + 11;
            New_CString = temparray.GetAt(1);
            m_Input_data.at(lRow).control = 1;
        }

    }
#endif
    m_input_list.Set_Edit(false);

    int cmp_ret = memcmp(&m_temp_Input_data[lRow],&m_Input_data.at(lRow),sizeof(Str_in_point));
    if(cmp_ret!=0)
    {
        m_input_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
        temp_task_info.Format(_T("Write Input List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
        Post_Write_Message(g_bac_instance,WRITEINPUT_T3000,(int8_t)lRow,(int8_t)lRow,sizeof(Str_in_point),m_input_dlg_hwnd,temp_task_info,lRow,lCol);
    }



    *pResult = 0;
}
LRESULT CBacnetInput::Fresh_Input_List(WPARAM wParam,LPARAM lParam)
{
    // Str_in_point Get_Str_in_Point(int index);
    int Fresh_Item;
    int isFreshOne = (int)lParam;
    if(isFreshOne == REFRESH_ON_ITEM)
    {
        Fresh_Item = (int)wParam;
    }
    else
    {
        if(m_input_list.IsDataNewer((char *)&m_Input_data.at(0),sizeof(Str_in_point) * BAC_INPUT_ITEM_COUNT))
        {
            //避免list 刷新时闪烁;在没有数据变动的情况下不刷新List;
            m_input_list.SetListData((char *)&m_Input_data.at(0),sizeof(Str_in_point) * BAC_INPUT_ITEM_COUNT);
        }
        else
        {
            return 0;
        }
    }
    if(0)
    {
        int temp_select_raw = 0;
        int temp_select_col = 0;
        m_input_list.Get_Selected_Item(temp_select_raw,temp_select_col);
        m_input_list.SetItemBkColor(temp_select_raw,temp_select_col,LIST_ITEM_SELECTED,0);
    }

    //m_input_list.DeleteAllItems();
    for (int i=0; i<(int)m_Input_data.size(); i++)
    {
        CString temp_item,temp_value,temp_cal,temp_filter,temp_status,temp_lable;
        CString temp_des;
        CString temp_units;

        if(isFreshOne)
        {
            i = Fresh_Item;
        }

        MultiByteToWideChar( CP_ACP, 0, (char *)m_Input_data.at(i).description, (int)strlen((char *)m_Input_data.at(i).description)+1,
                             temp_des.GetBuffer(MAX_PATH), MAX_PATH );
        temp_des.ReleaseBuffer();

        m_input_list.SetItemText(i,INPUT_FULL_LABLE,temp_des);
        if(m_Input_data.at(i).auto_manual==0)
        {
            m_input_list.SetItemText(i,INPUT_AUTO_MANUAL,_T("Auto"));
            m_input_list.SetCellEnabled(i,INPUT_VALUE,0);
        }
        else
        {
            m_input_list.SetItemText(i,INPUT_AUTO_MANUAL,_T("Manual"));
            m_input_list.SetCellEnabled(i,INPUT_VALUE,1);
        }

        if(m_Input_data.at(i).digital_analog == BAC_UNITS_ANALOG)
        {

            m_input_list.SetCellEnabled(i,INPUT_CAL,1);


            m_input_list.SetItemText(i,INPUT_RANGE,Input_Analog_Units_Array[m_Input_data.at(i).range]);
            m_input_list.SetItemText(i,INPUT_UNITE,Input_List_Analog_Units[m_Input_data.at(i).range]);


            CString cstemp_value;
            float temp_float_value;
            temp_float_value = ((float)m_Input_data.at(i).value) / 1000;
            cstemp_value.Format(_T("%.2f"),temp_float_value);
            m_input_list.SetItemText(i,INPUT_VALUE,cstemp_value);

            //CString temp_value;
            //temp_value.Format(_T("%d"),m_Input_data.at(i).value);
            //m_input_list.SetItemText(i,INPUT_VALUE,temp_value);

            temp_cal.Format(_T("%d"),(m_Input_data.at(i).calibration));
            m_input_list.SetItemText(i,INPUT_CAL,temp_cal);
        }
        else if(m_Input_data.at(i).digital_analog == BAC_UNITS_DIGITAL)
        {

            m_input_list.SetItemText(i,INPUT_CAL,_T(""));
#if 0
            if(m_Input_data.at(i).range>=12)
                m_input_list.SetItemText(i,INPUT_RANGE,Digital_Units_Array[m_Input_data.at(i).range -11]);
            else
                m_input_list.SetItemText(i,INPUT_RANGE,Digital_Units_Array[m_Input_data.at(i).range]);
#endif
            if(m_Input_data.at(i).range<=22)
                m_input_list.SetItemText(i,INPUT_RANGE,Digital_Units_Array[m_Input_data.at(i).range]);
            else
                m_input_list.SetItemText(i,INPUT_RANGE,Digital_Units_Array[0]);
            m_input_list.SetItemText(i,INPUT_UNITE,_T(""));

            if((m_Input_data.at(i).range>22) || (m_Input_data.at(i).range == 0))
            {
                m_input_list.SetItemText(i,INPUT_UNITE,Digital_Units_Array[0]);
            }
            else
            {
                CString temp1;
                CStringArray temparray;
#if 0
                if(m_Input_data.at(i).range>=12)
                    temp1 = Digital_Units_Array[m_Input_data.at(i).range - 11];//11 is the sizeof the array
                else
#endif
                    temp1 = Digital_Units_Array[m_Input_data.at(i).range];
                SplitCStringA(temparray,temp1,_T("/"));
                if((temparray.GetSize()==2))
                {
                    if(m_Input_data.at(i).control == 0)
                        m_input_list.SetItemText(i,INPUT_VALUE,temparray.GetAt(0));
                    else
                        m_input_list.SetItemText(i,INPUT_VALUE,temparray.GetAt(1));
                }
            }

        }


        temp_filter.Format(_T("%d"),(int)pow((double)2,(int)m_Input_data.at(i).filter));
        m_input_list.SetItemText(i,INPUT_FITLER,temp_filter);

        if(m_Input_data.at(i).decom==0)
            temp_status.Format(Decom_Array[0]);
        else if(m_Input_data.at(i).decom==1)
            temp_status.Format(Decom_Array[1]);
        else
            temp_status.Empty();
        m_input_list.SetItemText(i,INPUT_DECOM,temp_status);


        CString temp_des2;
        MultiByteToWideChar( CP_ACP, 0, (char *)m_Input_data.at(i).label, (int)strlen((char *)m_Input_data.at(i).label)+1,
                             temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
        temp_des2.ReleaseBuffer();

        m_input_list.SetItemText(i,INPUT_LABLE,temp_des2);
        if(isFreshOne)
        {
            break;
        }
        //ptr_panel
    }
    copy_data_to_ptrpanel(TYPE_INPUT);
    return 0;
}
LRESULT CBacnetOutput::Fresh_Output_List(WPARAM wParam,LPARAM lParam)
{
     
	int Fresh_Item;
	int isFreshOne = (int)lParam;

	int digital_special_output_count = 0;
	int analog_special_output_count = 0;
	if(bacnet_device_type == BIG_MINIPANEL)
	{
		digital_special_output_count = BIG_MINIPANEL_OUT_D;
		analog_special_output_count = BIG_MINIPANEL_OUT_A;
	}
	else if(bacnet_device_type == SMALL_MINIPANEL)
	{
		digital_special_output_count = SMALL_MINIPANEL_OUT_D;
		analog_special_output_count = SMALL_MINIPANEL_OUT_A;
	}
	else if(bacnet_device_type == TINY_MINIPANEL)
	{
		digital_special_output_count = TINY_MINIPANEL_OUT_D;
		analog_special_output_count = TINY_MINIPANEL_OUT_A;
	}
	else if(bacnet_device_type == T38AI8AO6DO)
	{
		digital_special_output_count = T38AI8AO6DO_OUT_D;
		analog_special_output_count = T38AI8AO6DO_OUT_A;
	}
	else if(bacnet_device_type == PID_T322AI)
	{
		digital_special_output_count = T322AI_OUT_D;
		analog_special_output_count = T322AI_OUT_A;
	}
	//if(pFrame->m_product.at(selected_product_index).product_class_id == T38AI8AO6DO)
	if((bacnet_device_type == T38AI8AO6DO) ||
		(bacnet_device_type == PID_T322AI))
	{
		OUTPUT_LIMITE_ITEM_COUNT = digital_special_output_count + analog_special_output_count;
	}
	else
	{
		OUTPUT_LIMITE_ITEM_COUNT = BAC_OUTPUT_ITEM_COUNT;
	}

	bool temp_need_show_external = false;
	for (int z= 0 ;z < (int)m_Output_data.size();z++)
	{
		if(z>= OUTPUT_LIMITE_ITEM_COUNT)
			break;
		if((m_Output_data.at(z).sub_id !=0) &&
			(m_Output_data.at(z).sub_product !=0))
		{
			temp_need_show_external = true;
			break;
		}

	}
	if(show_output_external != temp_need_show_external)
	{
		show_output_external = temp_need_show_external;
		if(temp_need_show_external)
		{
			CRect temp_rect;
			temp_rect = Output_rect;
			temp_rect.right = 1150;
			temp_rect.top = temp_rect.top + 24;
			m_output_list.MoveWindow(temp_rect);
			m_output_list.SetColumnWidth(OUTPUT_EXTERNAL,60);
			m_output_list.SetColumnWidth(OUTPUT_PRODUCT,80);
			m_output_list.SetColumnWidth(OUTPUT_EXT_NUMBER,80);
		}
		else
		{
			CRect temp_rect;
			temp_rect = Output_rect;
			temp_rect.right = 950;
			temp_rect.top = temp_rect.top + 24;
			m_output_list.MoveWindow(temp_rect);

			m_output_list.SetColumnWidth(OUTPUT_EXTERNAL,0);
			m_output_list.SetColumnWidth(OUTPUT_PRODUCT,0);
			m_output_list.SetColumnWidth(OUTPUT_EXT_NUMBER,0);
		}
	}


	if(isFreshOne == REFRESH_ON_ITEM)
	{
		Fresh_Item = (int)wParam;
	}
	else
	{
		if(m_output_list.IsDataNewer((char *)&m_Output_data.at(0),sizeof(Str_out_point) * BAC_OUTPUT_ITEM_COUNT))
		{
			//避免list 刷新时闪烁;在没有数据变动的情况下不刷新List;
			m_output_list.SetListData((char *)&m_Output_data.at(0),sizeof(Str_out_point) * BAC_OUTPUT_ITEM_COUNT);
		}
		else
		{
			return 0;
		}
	}


	CString temp1;
	//int Fresh_Item;
	//int isFreshOne = (int)lParam;
	//if(isFreshOne == REFRESH_ON_ITEM)
	//{
	//	Fresh_Item = (int)wParam;
	//}
	for (int i=0;i<(int)m_Output_data.size();i++)
	{
		if(isFreshOne)
		{
			i = Fresh_Item;
		}

		if(i>=output_item_limit_count)
			break;

		if(i>= OUTPUT_LIMITE_ITEM_COUNT)
		{
			for (int a=0;a<OUTPUT_COL_NUMBER; a++)
			{
				m_output_list.SetItemText(i,a,_T(""));
			}
			continue;
		}
		CString temp_item,temp_value,temp_cal,temp_filter,temp_status,temp_lable;
		CString temp_des;
		CString temp_units;

		MultiByteToWideChar( CP_ACP, 0, (char *)m_Output_data.at(i).description, (int)strlen((char *)m_Output_data.at(i).description)+1, 
			temp_des.GetBuffer(MAX_PATH), MAX_PATH );
		temp_des.ReleaseBuffer();
		temp_item.Format(_T("OUT%d"),i+1);
		m_output_list.SetItemText(i,OUTPUT_NUM,temp_item);
		m_output_list.SetItemText(i,OUTPUT_FULL_LABLE,temp_des);

		m_output_list.SetCellEnabled(i,OUTPUT_HW_SWITCH,0);


		//int digital_special_output_count = 0;
		//int analog_special_output_count = 0;

		m_output_list.SetItemText(i,OUTPUT_HW_SWITCH,_T(""));
		//这样加实在是情非得已,老毛非得加一堆条件,还要smart;
		if((bacnet_device_type == BIG_MINIPANEL) || ((bacnet_device_type == SMALL_MINIPANEL)) || (bacnet_device_type == TINY_MINIPANEL) || 
			(bacnet_device_type == T38AI8AO6DO) || (bacnet_device_type == PID_T322AI) )
		{
			//if(bacnet_device_type == BIG_MINIPANEL)
			//{
			//	digital_special_output_count = BIG_MINIPANEL_OUT_D;
			//	analog_special_output_count = BIG_MINIPANEL_OUT_A;
			//}
			//else if(bacnet_device_type == SMALL_MINIPANEL)
			//{
			//	digital_special_output_count = SMALL_MINIPANEL_OUT_D;
			//	analog_special_output_count = SMALL_MINIPANEL_OUT_A;
			//}
			//else if(bacnet_device_type == TINY_MINIPANEL)
			//{
			//	digital_special_output_count = TINY_MINIPANEL_OUT_D;
			//	analog_special_output_count = TINY_MINIPANEL_OUT_A;
			//}
			//else if(bacnet_device_type == T38AI8AO6DO)
			//{
			//	digital_special_output_count = T38AI8AO6DO_OUT_D;
			//	analog_special_output_count = T38AI8AO6DO_OUT_A;
			//}

			if(i < (digital_special_output_count +analog_special_output_count) )
			{
				if(m_Output_data.at(i).hw_switch_status == HW_SW_OFF)
				{
					m_output_list.SetItemText(i,OUTPUT_HW_SWITCH,_T("MAN-OFF"));		
					m_output_list.SetCellEnabled(i,OUTPUT_AUTO_MANUAL,0);

					m_output_list.SetItemTextColor(i,-1,RGB(255,0,0),0);
				}
				else if(m_Output_data.at(i).hw_switch_status == HW_SW_HAND)
				{
					m_output_list.SetItemText(i,OUTPUT_HW_SWITCH,_T("MAN-ON"));
					m_output_list.SetCellEnabled(i,OUTPUT_AUTO_MANUAL,0);

					m_output_list.SetItemTextColor(i,-1,RGB(255,0,0),0);
				}
				else
				{
					m_output_list.SetItemTextColor(i,-1,RGB(0,0,0),0);

					//if((i%2)==0)	//恢复前景和 背景 颜色;
					//	m_output_list.SetItemBkColor(i,-1,LIST_ITEM_DEFAULT_BKCOLOR,0);
					//else
					//	m_output_list.SetItemBkColor(i,-1,LIST_ITEM_DEFAULT_BKCOLOR_GRAY,0);

					m_output_list.SetItemText(i,OUTPUT_HW_SWITCH,_T("AUTO"));
					m_output_list.SetCellEnabled(i,OUTPUT_AUTO_MANUAL,1);
					if(m_Output_data.at(i).auto_manual==0)	//In output table if it is auto ,the value can't be edit by user
					{
						m_output_list.SetItemText(i,OUTPUT_AUTO_MANUAL,_T("Auto"));
						//m_output_list.SetCellEnabled(i,OUTPUT_VALUE,0);
					}
					else
					{
						m_output_list.SetItemText(i,OUTPUT_AUTO_MANUAL,_T("Manual"));
						//m_output_list.SetCellEnabled(i,OUTPUT_VALUE,1);
					}
				}
			}
			else
			{
				m_output_list.SetItemTextColor(i,-1,RGB(0,0,0),0);
				m_output_list.SetItemText(i,OUTPUT_HW_SWITCH,_T("AUTO"));
				m_output_list.SetCellEnabled(i,OUTPUT_AUTO_MANUAL,1);
				if(m_Output_data.at(i).auto_manual==0)	//In output table if it is auto ,the value can't be edit by user
				{
					m_output_list.SetItemText(i,OUTPUT_AUTO_MANUAL,_T("Auto"));
					//m_output_list.SetCellEnabled(i,OUTPUT_VALUE,0);
				}
				else
				{
					m_Output_data.at(i).auto_manual = 1;
					m_output_list.SetItemText(i,OUTPUT_AUTO_MANUAL,_T("Manual"));
					//m_output_list.SetCellEnabled(i,OUTPUT_VALUE,1);
				}
			}
		}
		else
		{
			m_output_list.SetCellEnabled(i,OUTPUT_AUTO_MANUAL,1);
			if(m_Output_data.at(i).auto_manual==0)	//In output table if it is auto ,the value can't be edit by user
			{
				m_output_list.SetItemText(i,OUTPUT_AUTO_MANUAL,_T("Auto"));
				//m_output_list.SetCellEnabled(i,OUTPUT_VALUE,0);
			}
			else
			{
				m_Output_data.at(i).auto_manual = 1;
				m_output_list.SetItemText(i,OUTPUT_AUTO_MANUAL,_T("Manual"));
				//m_output_list.SetCellEnabled(i,OUTPUT_VALUE,1);
			}
		}




			m_output_list.SetCellEnabled(i,OUTPUT_UNITE,0);
		if(m_Output_data.at(i).digital_analog == BAC_UNITS_ANALOG)
		{
			//m_output_list.SetCellEnabled(i,OUTPUT_0_PERSENT,1);
			//m_output_list.SetCellEnabled(i,OUTPUT_100_PERSENT,1);

			if(m_Output_data.at(i).range == 0)
				m_output_list.SetItemText(i,OUTPUT_RANGE,_T("Unused"));
			else if(m_Output_data.at(i).range < (sizeof(OutPut_List_Analog_Range)/sizeof(OutPut_List_Analog_Range[0])))
				m_output_list.SetItemText(i,OUTPUT_RANGE,OutPut_List_Analog_Range[m_Output_data.at(i).range]);
			else
				m_output_list.SetItemText(i,OUTPUT_RANGE,_T("Out of range"));

			if(m_Output_data.at(i).range < (sizeof(OutPut_List_Analog_Units)/sizeof(OutPut_List_Analog_Units[0])))
				m_output_list.SetItemText(i,OUTPUT_UNITE,OutPut_List_Analog_Units[m_Output_data.at(i).range]);
			else
				m_output_list.SetItemText(i,OUTPUT_UNITE,_T("Unused"));

			CString temp_low,temp_high;
			temp_low.Format(_T("%d"),0);
			temp_high.Format(_T("%d"),0);


			CString temp_value;
			temp_value.Format(_T("%.2f"),((float)m_Output_data.at(i).value) / 1000);
			m_output_list.SetItemText(i,OUTPUT_VALUE,temp_value);
#if 0
			CString cstemp_value;
			float temp_float_value;
			temp_float_value = ((float)m_Output_data.at(i).value) / 1000;
			cstemp_value.Format(_T("%.2f"),temp_float_value);
			m_output_list.SetItemText(i,OUTPUT_VALUE,cstemp_value);
#endif
			//m_output_list.SetItemText(i,OUTPUT_0_PERSENT,temp_low);
			//m_output_list.SetItemText(i,OUTPUT_100_PERSENT,temp_high);
		}
		else if(m_Output_data.at(i).digital_analog == BAC_UNITS_DIGITAL)
		{
			//m_output_list.SetCellEnabled(i,OUTPUT_0_PERSENT,0);
			//m_output_list.SetCellEnabled(i,OUTPUT_100_PERSENT,0);
			//m_output_list.SetItemText(i,OUTPUT_0_PERSENT,_T(""));
			//m_output_list.SetItemText(i,OUTPUT_100_PERSENT,_T(""));
			/*m_output_list.SetItemText(i,OUTPUT_RANGE,Digital_Units_Array[m_Output_data.at(i).range]);*/
			m_output_list.SetItemText(i,OUTPUT_UNITE,_T(""));

			if(m_Output_data.at(i).range == 0)
			{
				CString temp_value2;
				temp_value2.Format(_T("%.2f"),((float)m_Output_data.at(i).value) / 1000);
				m_output_list.SetItemText(i,OUTPUT_VALUE,temp_value2);

				m_output_list.SetItemText(i,OUTPUT_RANGE,Digital_Units_Array[0]);
			}
			else if(m_Output_data.at(i).range<=22)
				m_output_list.SetItemText(i,OUTPUT_RANGE,Digital_Units_Array[m_Output_data.at(i).range]);
			else if((m_Output_data.at(i).range >= 23) && (m_Output_data.at(i).range <= 30))
			{
				if(receive_customer_unit)
					m_output_list.SetItemText(i,OUTPUT_RANGE,temp_unit_no_index[m_Output_data.at(i).range - 23]);
				else
					m_output_list.SetItemText(i,OUTPUT_RANGE,Digital_Units_Array[0]);
			}
			else
				m_output_list.SetItemText(i,OUTPUT_RANGE,Digital_Units_Array[0]);
#if 0
			if(m_Output_data.at(i).range>=12)
				m_output_list.SetItemText(i,OUTPUT_RANGE,Digital_Units_Array[m_Output_data.at(i).range -11]);
			else
				m_output_list.SetItemText(i,OUTPUT_RANGE,Digital_Units_Array[m_Output_data.at(i).range]);
#endif
			if((m_Output_data.at(i).range>30) || (m_Output_data.at(i).range == 0))
			{
				//m_output_list.SetItemText(i,OUTPUT_UNITE,Digital_Units_Array[0]);
			}
			else
			{
				
				CStringArray temparray;

				if((m_Output_data.at(i).range < 23) &&(m_Output_data.at(i).range !=0))
					temp1 = Digital_Units_Array[m_Output_data.at(i).range];
				else if((m_Output_data.at(i).range >=23) && (m_Output_data.at(i).range <= 30))
				{
					if(receive_customer_unit)
						temp1 = temp_unit_no_index[m_Output_data.at(i).range - 23];
				}
				else
				{
					temp1.Empty();
					m_output_list.SetItemText(i,OUTPUT_VALUE,_T(""));
				}

				SplitCStringA(temparray,temp1,_T("/"));
				if((temparray.GetSize()==2))
				{
					if(m_Output_data.at(i).control == 0)
						m_output_list.SetItemText(i,OUTPUT_VALUE,temparray.GetAt(0));
					else
						m_output_list.SetItemText(i,OUTPUT_VALUE,temparray.GetAt(1));
				}
			}
		}


			CString main_sub_panel;

#pragma region External info
		if((m_Output_data.at(i).sub_id !=0) &&
			//(m_Input_data.at(input_list_line).sub_number !=0) &&
			(m_Output_data.at(i).sub_product !=0))
		{
			unsigned char temp_pid = m_Output_data.at(i).sub_product;
			if((temp_pid == PM_T3PT10) ||
				(temp_pid == PM_T3IOA) ||
				(temp_pid == PM_T332AI) ||
				(temp_pid == PM_T38AI16O) ||
				(temp_pid == PM_T38I13O) ||
				(temp_pid == PM_T34AO) ||
				(temp_pid == PM_T322AI) ||
				(temp_pid == PM_T38AI8AO6DO) ||
				(temp_pid == PM_T36CT))
			{
				CString temp_name;
				temp_name = GetProductName(m_Output_data.at(i).sub_product);
				CString show_info;
				CString temp_id;
				CString temp_number;

				bitset<8> mytest((unsigned char)m_Output_data.at(i).sub_number);
				bool highest_bit;
				highest_bit = mytest.test(7);

				unsigned char temp_sub_number = 0;
				mytest = mytest.set(7,0);
				temp_sub_number = (unsigned char)mytest.to_ulong();


				if(highest_bit)
					temp_number.Format(_T("AO%d"),temp_sub_number + 1);
				else
					temp_number.Format(_T("DO%d"),temp_sub_number + 1);




				
				m_output_list.SetItemText(i,OUTPUT_EXTERNAL,_T("External"));
				m_output_list.SetItemTextColor(i,OUTPUT_EXTERNAL,RGB(0,0,255),FALSE);
				m_output_list.SetItemText(i,OUTPUT_PRODUCT,temp_name);
				m_output_list.SetItemText(i,OUTPUT_EXT_NUMBER,temp_number);

				main_sub_panel.Format(_T("%d-%d"),(unsigned char)Station_NUM,(unsigned char)m_Output_data.at(i).sub_id);
				m_output_list.SetItemText(i,OUTPUT_PANEL,main_sub_panel);
				//temp_id.Format(_T(" Sub ID: %u        "),(unsigned char)m_Input_data.at(input_list_line).sub_id);
				//temp_number.Format(_T("Input%d"),(unsigned char)m_Input_data.at(input_list_line).sub_number + 1);
				//show_info = _T("Module:") + temp_name +_T("        ") + temp_id + temp_number;
				//m_input_item_info.SetWindowTextW(show_info);

			}	
			else
			{
				main_sub_panel.Format(_T("%d"),(unsigned char)Station_NUM);
				m_output_list.SetItemText(i,OUTPUT_PANEL,main_sub_panel);
			}

		}
		else
		{
			main_sub_panel.Format(_T("%d"),(unsigned char)Station_NUM);
			m_output_list.SetItemText(i,OUTPUT_PANEL,main_sub_panel);
		}

#pragma endregion External info




		if(m_Output_data.at(i).decom==0)
			temp_status.Format(Output_Decom_Array[0]);
		else if(m_Output_data.at(i).decom==1)
			temp_status.Format(Output_Decom_Array[1]);
		else
			temp_status.Empty();
		m_output_list.SetItemText(i,OUTPUT_DECOM,temp_status);

		CString temp_pwm_period;
		temp_pwm_period.Format(_T("%u"),(unsigned char)m_Output_data.at(i).pwm_period);
		m_output_list.SetItemText(i,OUTPUT_PWM_PERIOD,temp_pwm_period);

		CString temp_des2;
		MultiByteToWideChar( CP_ACP, 0, (char *)m_Output_data.at(i).label, (int)strlen((char *)m_Output_data.at(i).label)+1, 
			temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
		temp_des2.ReleaseBuffer();
		m_output_list.SetItemText(i,OUTPUT_LABLE,temp_des2);
		if(isFreshOne)
		{
			break;
		}
	}
	copy_data_to_ptrpanel(TYPE_OUTPUT);
	Invalidate();
	return 0;
}
void CBacnetVariable::OnNMClickListVariable(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	long lRow,lCol;
	m_variable_list.Set_Edit(true);
	DWORD dwPos=GetMessagePos();//Get which line is click by user.Set the check box, when user enter Insert it will jump to program dialog
	CPoint point( LOWORD(dwPos), HIWORD(dwPos));
	m_variable_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_variable_list.SubItemHitTest(&lvinfo);

	lRow = lvinfo.iItem;
	lCol = lvinfo.iSubItem;


	if(lRow>m_variable_list.GetItemCount()) //如果点击区超过最大行号,则点击是无效的
		return;
	if(lRow<0)
		return;




	m_row = lRow;
	m_col = lCol;

	memcpy_s(&m_temp_variable_data[lRow],sizeof(Str_variable_point),&m_Variable_data.at(lRow),sizeof(Str_variable_point));

	CString temp_task_info;
	if((lCol == VARIABLE_VALUE) &&(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_DIGITAL ) && (m_Variable_data.at(lRow).auto_manual != BAC_AUTO))
	{
		CString New_CString;
		
		CString temp1;
		CStringArray temparray;

		if((m_Variable_data.at(lRow).range < 23) &&(m_Variable_data.at(lRow).range !=0))
			temp1 = Digital_Units_Array[m_Variable_data.at(lRow).range];
		else
			return;
		SplitCStringA(temparray,temp1,_T("/"));
		if(m_Variable_data.at(lRow).control == 0)
		{
			m_Variable_data.at(lRow).control = 1;
			m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(1));
			New_CString = temparray.GetAt(1);
		}
		else
		{
			m_Variable_data.at(lRow).control = 0;
			m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(0));
			New_CString = temparray.GetAt(0);
		}
#if 0
		if(m_Variable_data.at(lRow).range > 11)
			temp1 = Digital_Units_Array[m_Variable_data.at(lRow).range - 11];//11 is the sizeof the array
		else
			temp1 = Digital_Units_Array[m_Variable_data.at(lRow).range];
		SplitCStringA(temparray,temp1,_T("/"));
		if(m_Variable_data.at(lRow).range>=12)
		{

			if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
			{
				m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(0));
				m_Variable_data.at(lRow).range = m_Variable_data.at(lRow).range - 11;
				m_Variable_data.at(lRow).control = 0;	
				New_CString = temparray.GetAt(0);
			}

		}
		else if(m_Variable_data.at(lRow).range>=1)
		{

			if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
			{
				m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(1));
				m_Variable_data.at(lRow).range = m_Variable_data.at(lRow).range + 11;
				New_CString = temparray.GetAt(1);
				m_Variable_data.at(lRow).control = 1;
			}

		}
#endif
		m_variable_list.Set_Edit(false);

		temp_task_info.Format(_T("Write Variable List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
	}
	else if((lCol == VARIABLE_VALUE) &&(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_ANALOG ) && (m_Variable_data.at(lRow).auto_manual == BAC_MANUAL) && (m_Variable_data.at(lRow).range == 20))
	{
		m_variable_list.Set_Edit(false);
		m_variable_time_picker.ShowWindow(SW_SHOW);
		CRect list_rect,win_rect;
		m_variable_list.GetWindowRect(list_rect);
		GetWindowRect(win_rect);
		CRect myrect;
		m_variable_list.GetSubItemRect(lRow,lCol,LVIR_BOUNDS,myrect);


		myrect.left = myrect.left + list_rect.left - win_rect.left;
		myrect.right = myrect.right + list_rect.left - win_rect.left;
		myrect.top = myrect.top + 11;
		myrect.bottom = myrect.bottom + 13;

		m_variable_time_picker.BringWindowToTop();
		m_variable_time_picker.MoveWindow(myrect);

		
		CString Temp_CString =  m_variable_list.GetItemText(lRow,lCol);

		CStringArray TEMPCS;
		int temp_hour,temp_minute;
		SplitCStringA(TEMPCS, Temp_CString, _T(":"));
		if((int)TEMPCS.GetSize() <2)
		{
			temp_hour = 0;
			temp_minute = 0;
			CTime TimeTemp(2013,1,1,temp_hour,temp_minute,0);
			m_variable_time_picker.SetFormat(_T("HH:mm"));
			m_variable_time_picker.SetTime(&TimeTemp);
			m_variable_time_picker.SetFocus();
		}
		else
		{
			temp_hour = _wtoi(TEMPCS.GetAt(0));
			temp_minute = _wtoi(TEMPCS.GetAt(1));
			CTime TimeTemp(2013,1,1,temp_hour,temp_minute,0);
			m_variable_time_picker.SetFormat(_T("HH:mm"));
			m_variable_time_picker.SetTime(&TimeTemp);
			m_variable_time_picker.SetFocus();
		}
		m_variable_list.SetItemText(lRow,lCol,_T(""));
		m_variable_time_picker.Invalidate();
		SetTimer(2,100,NULL);



	}
	else
		return;

	int cmp_ret = memcmp(&m_temp_variable_data[lRow],&m_Variable_data.at(lRow),sizeof(Str_variable_point));
	if(cmp_ret!=0)
	{
		m_variable_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,lRow,lRow,sizeof(Str_variable_point),m_variable_dlg_hwnd,temp_task_info,lRow,lCol);
	}
//	GetDlgItem(IDC_BUTTON_VARIABLE_APPLY)->SetFocus();
	*pResult = 0;
}
LRESULT CBacnetVariable::Fresh_Variable_Item(WPARAM wParam,LPARAM lParam)
{
	int cmp_ret ;//compare if match it will 0;

	int Changed_Item = (int)wParam;
	int Changed_SubItem = (int)lParam;
	CString temp_task_info;
	CString New_CString =  m_variable_list.GetItemText(Changed_Item,Changed_SubItem);
	CString cstemp_value;
	memcpy_s(&m_temp_variable_data[Changed_Item],sizeof(Str_variable_point),&m_Variable_data.at(Changed_Item),sizeof(Str_variable_point));


	if(Changed_SubItem == VARIABLE_LABLE)
	{
		CString cs_temp = m_variable_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_VARIABLE_LABEL)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Length can not higher than 9"),_T("Warning"));
			PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,NULL,NULL);
			return 0;
		}

		char cTemp1[255];
		memset(cTemp1,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
		memcpy_s(m_Variable_data.at(Changed_Item).label,STR_VARIABLE_LABEL,cTemp1,STR_VARIABLE_LABEL);
	}

	if(Changed_SubItem == VARIABLE_FULL_LABLE)
	{
		CString cs_temp = m_variable_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_VARIABLE_DESCRIPTION_LENGTH)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Length can not higher than 20"),_T("Warning"));
			PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,NULL,NULL);
			return 0;
		}

		char cTemp1[255];
		memset(cTemp1,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
		memcpy_s(m_Variable_data.at(Changed_Item).description,STR_VARIABLE_DESCRIPTION_LENGTH,cTemp1,STR_VARIABLE_DESCRIPTION_LENGTH);
	}


	if(Changed_SubItem == VARIABLE_AUTO_MANUAL)
	{
		CString temp_cs = m_variable_list.GetItemText(Changed_Item,Changed_SubItem);
		if(temp_cs.CompareNoCase(_T("Auto"))==0)
		{
			m_variable_list.SetCellEnabled(Changed_Item,VARIABLE_VALUE,0);
			m_Variable_data.at(Changed_Item).auto_manual = BAC_AUTO;
		}
		else
		{
			m_variable_list.SetCellEnabled(Changed_Item,VARIABLE_VALUE,1);
			m_Variable_data.at(Changed_Item).auto_manual = BAC_MANUAL;
		}
	}
	if(Changed_SubItem == VARIABLE_VALUE)//这里只用处理 ANALOG 的值就看要了, DIGITAL 的值在Click 事件中处理过了;
	{
		CString temp_cs = m_variable_list.GetItemText(Changed_Item,Changed_SubItem);

		int temp_int = (int)(_wtof(temp_cs) * 1000);
		m_Variable_data.at(Changed_Item).value = temp_int;
		//int temp_int = _wtoi(temp_cs);
		//m_Variable_data.at(Changed_Item).value = temp_int;
	}
	if(Changed_SubItem == VARIABLE_UNITE)
	{
		BacnetRange dlg;
		CString temp_cs = m_variable_list.GetItemText(Changed_Item,Changed_SubItem);
		if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_ANALOG])==0)
		{



			bac_ranges_type = VARIABLE_RANGE_ANALOG_TYPE;
			dlg.DoModal();
			if(range_cancel)
			{
				PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,Changed_Item,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
				return 0;
			}
			m_Variable_data.at(Changed_Item).digital_analog = BAC_UNITS_ANALOG;
			m_Variable_data.at(Changed_Item).range = bac_range_number_choose;
			m_variable_list.SetItemText(Changed_Item,Changed_SubItem,Variable_Analog_Units_Array[bac_range_number_choose]);


			
			if(m_Variable_data.at(Changed_Item).range == 20)	//如果是时间;
			{
				char temp_char[50];
				int time_seconds = m_Variable_data.at(Changed_Item).value / 1000;
				intervaltotext(temp_char,time_seconds,0,0);
				
				CString temp_11;
				MultiByteToWideChar( CP_ACP, 0, temp_char, strlen(temp_char) + 1, 
					temp_11.GetBuffer(MAX_PATH), MAX_PATH );
				temp_11.ReleaseBuffer();		
				m_variable_list.SetItemText(Changed_Item,VARIABLE_VALUE,temp_11);

			}
			else
			{
				CString cstemp_value;
				float temp_float_value;
				temp_float_value = ((float)m_Variable_data.at(Changed_Item).value) / 1000;
				cstemp_value.Format(_T("%.3f"),temp_float_value);
				m_variable_list.SetItemText(Changed_Item,VARIABLE_VALUE,cstemp_value);

/*				cstemp_value.Format(_T("%d"),m_Variable_data.at(Changed_Item).value);
				m_variable_list.SetItemText(Changed_Item,VARIABLE_VALUE,cstemp_value);*/	
			}

		}
		else if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_DIGITAL])==0)
		{
			bac_ranges_type = VARIABLE_RANGE_DIGITAL_TYPE;
			dlg.DoModal();
			if(range_cancel)
			{
				PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,Changed_Item,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
				return 0;
			}
			m_Variable_data.at(Changed_Item).digital_analog = BAC_UNITS_DIGITAL;
			m_Variable_data.at(Changed_Item).range = bac_range_number_choose;

			CString temp1;
			CStringArray temparray;

			temp1 = Digital_Units_Array[bac_range_number_choose];//22 is the sizeof the array
			SplitCStringA(temparray,temp1,_T("/"));

			

			if(m_Variable_data.at(Changed_Item).control == 1)
			{
				if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
				{
					m_variable_list.SetItemText(Changed_Item,VARIABLE_VALUE,temparray.GetAt(1));
				}
			}
			else
			{
				if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
				{
					m_variable_list.SetItemText(Changed_Item,VARIABLE_VALUE,temparray.GetAt(0));
				}			
			}
			m_variable_list.SetItemText(Changed_Item,VARIABLE_UNITE,temp1);

		}
		else if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_CUSTOM])==0)
		{
			bac_ranges_type = VARIABLE_RANGE_CUSTOM_DIG_TYPE;
		}
	}
	cmp_ret = memcmp(&m_temp_variable_data[Changed_Item],&m_Variable_data.at(Changed_Item),sizeof(Str_variable_point));
	if(cmp_ret!=0)
	{
		m_variable_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR);
	temp_task_info.Format(_T("Write Variable List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString);
	Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,Changed_Item,Changed_Item,sizeof(Str_variable_point),m_variable_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem);
	}
	return 0;
}
BOOL CBADO::OnInitADOConn()
{
	CString StrTips;
	HANDLE hFind;//
	WIN32_FIND_DATA wfd;//
	hFind = FindFirstFile(m_dbfilepath, &wfd);//
	if (hFind == INVALID_HANDLE_VALUE)//说明当前目录下无t3000.mdb
	{
		// 	StrTips.Format(_T("%s\n The datebase file disappeared.T3000 help you create a default datebase of your current building."),m_dbfilepath);
		// 	AfxMessageBox(StrTips);
		CStringArray ArrayFileName;
		SplitCStringA(ArrayFileName, m_dbfilepath, L"\\");
		CString filename = L"";
		for (int i = 0; i < ArrayFileName.GetSize() - 1; i++)
		{
			filename += ArrayFileName[i];
			filename += L"\\";
		}
		CreateDirectory(filename,NULL);
		m_dbImgeFolder = filename + _T("image");
		CreateDirectory(m_dbImgeFolder,NULL);

		hFind = FindFirstFile(m_dbfilepath, &wfd);//
		if (hFind == INVALID_HANDLE_VALUE)//说明当前目录下没有building数据库的话,就创建一个
		{
#if 0
		HRSRC hrSrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_BUILDING_DB2), _T("BUILDING_DB"));   
		HGLOBAL hGlobal = LoadResource(AfxGetResourceHandle(), hrSrc);   


		LPVOID lpExe = LockResource(hGlobal);   
		CFile file;
		if(file.Open(m_dbfilepath, CFile::modeCreate | CFile::modeWrite))    
			file.Write(lpExe, (UINT)SizeofResource(AfxGetResourceHandle(), hrSrc));    
		file.Close();    
		::UnlockResource(hGlobal);   
		::FreeResource(hGlobal);
#endif
		}//
		FindClose(hFind);

		//return FALSE;
	}
	::CoInitialize(NULL);
	try
	{
		////////////////////////////////////////////////////////////////////////////////////////////


		m_ConnectString = (CString)FOR_DATABASE_CONNECT + m_dbfilepath;

		// 		CStringArray  ArrayFileName;
		// 		SplitCStringA(ArrayFileName,m_dbfilepath,L"\\");
		// 		CString filename=L"";
		// 		for (int i=0;i<ArrayFileName.GetSize()-1;i++)
		// 		{
		// 			filename+=ArrayFileName[i];
		// 			filename+=L"\\";
		// 		}
		// 		m_dbImgeFolder=filename+_T("image");
		// 		CreateDirectory(m_dbImgeFolder,NULL);

		/////////////////////////////////////////////////////////////////////////////////////////////////
		//连接数据库


		m_pConnection.CreateInstance("ADODB.Connection");

		m_pConnection->Open(m_ConnectString.GetString(), "", "", adModeUnknown);
	}
	catch (_com_error e)
	{
		//AfxMessageBox(e.Description());
		return FALSE;
	}

	return TRUE;
}
void CBacnetOutput::OnNMClickListOutput(NMHDR *pNMHDR, LRESULT *pResult)
{
	 
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	long lRow,lCol;
	m_output_list.Set_Edit(true);
	DWORD dwPos=GetMessagePos();//Get which line is click by user.Set the check box, when user enter Insert it will jump to program dialog
	CPoint point( LOWORD(dwPos), HIWORD(dwPos));
	m_output_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_output_list.SubItemHitTest(&lvinfo);



	if((nItem!=-1) && (nItem < BAC_OUTPUT_ITEM_COUNT))
	{
		output_list_line = nItem;
		if((m_Output_data.at(output_list_line).sub_id !=0) &&
			//(m_Output_data.at(output_list_line).sub_number !=0) &&
			(m_Output_data.at(output_list_line).sub_product !=0))
		{
			unsigned char temp_pid = m_Output_data.at(output_list_line).sub_product;
			if((temp_pid == PM_T3PT10) ||
				(temp_pid == PM_T3IOA) ||
				(temp_pid == PM_T332AI) ||
				(temp_pid == PM_T38AI16O) ||
				(temp_pid == PM_T38I13O) ||
				(temp_pid == PM_T34AO) ||
				(temp_pid == PM_T36CT) ||
				(temp_pid == PM_T322AI) ||
				(temp_pid == PM_T38AI8AO6DO))
			{
				m_output_item_info.ShowWindow(true);
				CString temp_name;
				temp_name = GetProductName(m_Output_data.at(output_list_line).sub_product);
				CString show_info;
				CString temp_id;
				CString temp_number;
				temp_id.Format(_T(" Sub ID: %u        "),(unsigned char)m_Output_data.at(output_list_line).sub_id);
				temp_number.Format(_T("Output%d"),(unsigned char)m_Output_data.at(output_list_line).sub_number+1);
				show_info = _T("Module:") + temp_name +_T("        ") + temp_id + temp_number;
				m_output_item_info.SetWindowTextW(show_info);

			}	
			else
			{
				m_output_item_info.ShowWindow(false);
			}
		}
		else
		{
			m_output_item_info.ShowWindow(false);
		}
	}

	lRow = lvinfo.iItem;
	lCol = lvinfo.iSubItem;

	if(lRow>= OUTPUT_LIMITE_ITEM_COUNT)
		return;

	if(lRow>m_output_list.GetItemCount()) //如果点击区超过最大行号,则点击是无效的
		return;
	if(lRow<0)
		return;

	CString New_CString;
	CString temp_task_info;
	CString temp1;
	CStringArray temparray;

	if(lCol == OUTPUT_VALUE)
	{
		if(m_Output_data.at(lRow).auto_manual == BAC_AUTO)	//If it is auto mode, disable to change the value.
		{
			m_output_list.Set_Edit(false);
			return;
		}

		if(m_Output_data.at(lRow).digital_analog != BAC_UNITS_DIGITAL)
			return;



		memcpy_s(&m_temp_output_data[lRow],sizeof(Str_out_point),&m_Output_data.at(lRow),sizeof(Str_out_point));





		if((m_Output_data.at(lRow).range < 23) &&(m_Output_data.at(lRow).range !=0))
			temp1 = Digital_Units_Array[m_Output_data.at(lRow).range];
		else if((m_Output_data.at(lRow).range >=23) && (m_Output_data.at(lRow).range <= 30))
		{
			if(receive_customer_unit)
				temp1 = temp_unit_no_index[m_Output_data.at(lRow).range - 23];
			else
			{
				m_output_list.Set_Edit(false);
				return;
			}
		}
		else
			return;


		//if(m_Output_data.at(lRow).range > 11)
		//	temp1 = Digital_Units_Array[m_Output_data.at(lRow).range - 11];//11 is the sizeof the array
		//else
		//	temp1 = Digital_Units_Array[m_Output_data.at(lRow).range];
		SplitCStringA(temparray,temp1,_T("/"));
		if(m_Output_data.at(lRow).control == 0)
		{
			m_Output_data.at(lRow).control = 1;
			m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(1));
			New_CString = temparray.GetAt(1);
		}
		else
		{
			m_Output_data.at(lRow).control = 0;
			m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(0));
			New_CString = temparray.GetAt(0);
		}
	}
	else if(lCol == OUTPUT_AUTO_MANUAL)
	{
		memcpy_s(&m_temp_output_data[lRow],sizeof(Str_out_point),&m_Output_data.at(lRow),sizeof(Str_out_point));
		if(m_Output_data.at(lRow).auto_manual == 0)
		{
			m_Output_data.at(lRow).auto_manual = 1;
			m_output_list.SetItemText(lRow,OUTPUT_AUTO_MANUAL,_T("Manual"));
			//m_output_list.SetCellEnabled(lRow,OUTPUT_VALUE,TRUE);
			New_CString = _T("Manual");
		}
		else
		{
			m_Output_data.at(lRow).auto_manual = 0;
			m_output_list.SetItemText(lRow,OUTPUT_AUTO_MANUAL,_T("Auto"));
			//m_output_list.SetCellEnabled(lRow,OUTPUT_VALUE,FALSE);
			New_CString = _T("Auto");
		}
	}
	else if(lCol == OUTPUT_RANGE)
	{



			//CString temp_cs = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
			BacnetRange dlg;
			//点击产品的时候 需要读customer units,老的产品firmware 说不定没有 这些,所以不强迫要读到;
			if(!read_customer_unit)
			{

				int temp_invoke_id = -1;
				int send_status = true;
				int	resend_count = 0;
				for (int z=0;z<3;z++)
				{
					do 
					{
						resend_count ++;
						if(resend_count>5)
						{
							send_status = false;
							break;
						}
						temp_invoke_id =  GetPrivateData(
							g_bac_instance,
							READUNIT_T3000,
							0,
							BAC_CUSTOMER_UNITS_COUNT - 1,
							sizeof(Str_Units_element));		

						Sleep(SEND_COMMAND_DELAY_TIME);
					} while (g_invoke_id<0);
					if(send_status)
					{
						for (int z=0;z<1000;z++)
						{
							Sleep(1);
							if(tsm_invoke_id_free(temp_invoke_id))
							{
								read_customer_unit = true;
								break;
							}
							else
								continue;
						}

					}
					if(read_customer_unit)
						break;
				}


			}

			if(m_Output_data.at(lRow).digital_analog == BAC_UNITS_ANALOG)
			{
				bac_ranges_type = OUTPUT_RANGE_ANALOG_TYPE;
				if(m_Output_data.at(lRow).range > (sizeof(Output_Analog_Units_Array) / sizeof(Output_Analog_Units_Array[0])))
				{
					m_Output_data.at(lRow).range = 0;
					bac_range_number_choose = 0;
				}
			}
			else
			{
				bac_ranges_type = OUTPUT_RANGE_DIGITAL_TYPE;
				if(m_Output_data.at(lRow).range > 30)
				{
					m_Output_data.at(lRow).range = 0;
					bac_range_number_choose = 0;
				}
			}


			//if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_ANALOG])==0)
			//{
				initial_dialog = 3;
				bac_range_number_choose = m_Output_data.at(lRow).range;
				//bac_ranges_type = OUTPUT_RANGE_ANALOG_TYPE;
				dlg.DoModal();
				if(range_cancel)
				{
					PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,lRow,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
					return ;
				}
				if(bac_range_number_choose == 0)	//如果选择的是 unused 就认为是analog 的unused;这样 能显示对应的value;
				{
					m_Output_data.at(lRow).digital_analog =  BAC_UNITS_ANALOG;
					bac_ranges_type = OUTPUT_RANGE_ANALOG_TYPE;
				}

				if(bac_ranges_type == OUTPUT_RANGE_ANALOG_TYPE)
				{
					m_Output_data.at(lRow).digital_analog =  BAC_UNITS_ANALOG;
					m_Output_data.at(lRow).range =  bac_range_number_choose;
					m_output_list.SetItemText(lRow,OUTPUT_UNITE,Output_Analog_Units_Show[bac_range_number_choose]);		
					m_output_list.SetItemText(lRow,OUTPUT_RANGE,OutPut_List_Analog_Range[bac_range_number_choose]);	

					//m_output_list.SetItemText(lRow,OUTPUT_0_PERSENT,_T("0"));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_0_PERSENT,1);
					//m_output_list.SetItemText(lRow,OUTPUT_100_PERSENT,_T("10"));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_100_PERSENT,1);
				 
#if 0
					CString cstemp_value;
					float temp_float_value;
					temp_float_value = m_Output_data.at(Changed_Item).value / 1000;
					cstemp_value.Format(_T("%.2f"),temp_float_value);
					m_output_list.SetItemText(Changed_Item,OUTPUT_VALUE,cstemp_value);	
#endif
					CString cstemp_value;
					cstemp_value.Format(_T("%d"),m_Output_data.at(lRow).value);
					m_output_list.SetItemText(lRow,OUTPUT_VALUE,cstemp_value);	
				}
				else if((bac_ranges_type == VARIABLE_RANGE_DIGITAL_TYPE) || (bac_ranges_type == INPUT_RANGE_DIGITAL_TYPE) || (bac_ranges_type == OUTPUT_RANGE_DIGITAL_TYPE))
				{
					m_Output_data.at(lRow).digital_analog =  BAC_UNITS_DIGITAL;
					m_Output_data.at(lRow).range =  bac_range_number_choose;

					//m_output_list.SetItemText(lRow,OUTPUT_0_PERSENT,_T(""));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_0_PERSENT,0);
					//m_output_list.SetItemText(lRow,OUTPUT_100_PERSENT,_T(""));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_100_PERSENT,0);



					CStringArray temparray;

					if((bac_range_number_choose >= 23) && (bac_range_number_choose <= 30))
					{
						//temp1.Format(_T("%s"), temp_unit_no_index[bac_range_number_choose - 23]);
						temp1 = temp_unit_no_index[bac_range_number_choose - 23];
					}
					else
						temp1 = Digital_Units_Array[bac_range_number_choose];//22 is the sizeof the array



					SplitCStringA(temparray,temp1,_T("/"));

					if(m_Output_data.at(lRow).control == 1)
					{
						if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
						{
							m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(1));
						}
					}
					else
					{
						if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
						{
							m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(0));
						}	
					}
					m_output_list.SetItemText(lRow,OUTPUT_RANGE,temp1);
					m_output_list.SetItemText(lRow,OUTPUT_UNITE,_T(""));//如果是数字单位 Unit 要清空;
				}
			
	}
	else
	{
		return;
	}

		//return;



	m_output_list.Set_Edit(false);

	int cmp_ret = memcmp(&m_temp_output_data[lRow],&m_Output_data.at(lRow),sizeof(Str_out_point));
	if(cmp_ret!=0)
	{
		m_output_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Output List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEOUTPUT_T3000,lRow,lRow,sizeof(Str_out_point),m_output_dlg_hwnd,temp_task_info,lRow,lCol);
	}


	*pResult = 0;
}
Example #12
0
LRESULT CBacnetVariable::Fresh_Variable_List(WPARAM wParam,LPARAM lParam)
{

	int Fresh_Item;
	int isFreshOne = (int)lParam;
	if(isFreshOne == REFRESH_ON_ITEM)
	{
		Fresh_Item = (int)wParam;
	}
	else
	{
		if(m_variable_list.IsDataNewer((char *)&m_Variable_data.at(0),sizeof(Str_variable_point) * BAC_VARIABLE_ITEM_COUNT))
		{
			//避免list 刷新时闪烁;在没有数据变动的情况下不刷新List;
			m_variable_list.SetListData((char *)&m_Variable_data.at(0),sizeof(Str_variable_point) * BAC_VARIABLE_ITEM_COUNT);
		}
		else
		{
			return 0;
		}
	}


	for (int i=0;i<(int)m_Variable_data.size();i++)
	{
		CString temp_item,temp_value,temp_cal,temp_filter,temp_status,temp_lable;
		CString temp_des;
		CString temp_units;

		if(isFreshOne)
		{
			i = Fresh_Item;
		}

		if(i>=variable_item_limit_count)
		{
			return 0;
		}

		MultiByteToWideChar( CP_ACP, 0, (char *)m_Variable_data.at(i).description, (int)strlen((char *)m_Variable_data.at(i).description)+1, 
			temp_des.GetBuffer(MAX_PATH), MAX_PATH );
		temp_des.ReleaseBuffer();
		m_variable_list.SetItemText(i,VARIABLE_FULL_LABLE,temp_des);
		if(m_Variable_data.at(i).auto_manual==0)
		{
			m_variable_list.SetItemText(i,VARIABLE_AUTO_MANUAL,_T("Auto"));
		}
		else
		{
			m_variable_list.SetItemText(i,VARIABLE_AUTO_MANUAL,_T("Manual"));
		}


		if(m_Variable_data.at(i).digital_analog == BAC_UNITS_DIGITAL)
		{
			
			if((m_Variable_data.at(i).range == 0) || (m_Variable_data.at(i).range>30))
			{
				CString cstemp_value2;
				float temp_float_value1;
				temp_float_value1 = ((float)m_Variable_data.at(i).value) / 1000;
				cstemp_value2.Format(_T("%.3f"),temp_float_value1);
				m_variable_list.SetItemText(i,VARIABLE_VALUE,cstemp_value2);
				m_variable_list.SetItemText(i,VARIABLE_UNITE,Variable_Analog_Units_Array[0]);
			}
			else
			{
				CString temp1;
				CStringArray temparray;

				if((m_Variable_data.at(i).range < 23) &&(m_Variable_data.at(i).range !=0))
					temp1 = Digital_Units_Array[m_Variable_data.at(i).range];
				else if((m_Variable_data.at(i).range >=23) && (m_Variable_data.at(i).range <= 30))
				{
					if(receive_customer_unit)
						temp1 = temp_unit_no_index[m_Variable_data.at(i).range - 23];
				}
				else
				{
					temp1 = Digital_Units_Array[0];
					m_variable_list.SetItemText(i,VARIABLE_UNITE,temp1);
				}

				SplitCStringA(temparray,temp1,_T("/"));
				if((temparray.GetSize()==2))
				{
					if(m_Variable_data.at(i).control == 0)
						m_variable_list.SetItemText(i,VARIABLE_VALUE,temparray.GetAt(0));
					else
						m_variable_list.SetItemText(i,VARIABLE_VALUE,temparray.GetAt(1));
					m_variable_list.SetItemText(i,VARIABLE_UNITE,temp1);
				}
				
			}
#if 0
			m_variable_list.SetItemText(i,VARIABLE_UNITE,Digital_Units_Array[m_Variable_data.at(i).range]);	//单位 这个要商量 看要怎么搞;
			if((m_Variable_data.at(i).range >= 12)&&(m_Variable_data.at(i).range <= 22))
			{
				CString temp1;
				CStringArray temparray;
				temp1 = Digital_Units_Array[m_Variable_data.at(i).range - 11];//11 is the sizeof the array
				SplitCStringA(temparray,temp1,_T("/"));
				if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
				{
					m_variable_list.SetItemText(i,VARIABLE_VALUE,temparray.GetAt(1));
				}
				m_variable_list.SetItemText(i,VARIABLE_UNITE,temp1);
			}
			else if((m_Variable_data.at(i).range >= 1)&&(m_Variable_data.at(i).range <= 11))
			{
				CString temp1;
				CStringArray temparray;
				temp1 = Digital_Units_Array[m_Variable_data.at(i).range];
				SplitCStringA(temparray,temp1,_T("/"));
				if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
				{
					m_variable_list.SetItemText(i,VARIABLE_VALUE,temparray.GetAt(0));
				}
				m_variable_list.SetItemText(i,VARIABLE_UNITE,temp1);
			}
			else
			{
				m_variable_list.SetItemText(i,VARIABLE_VALUE,_T("0"));
			}
#endif
		}
		else
		{
			if(m_Variable_data.at(i).range == 20)	//如果是时间;
			{
				m_variable_list.SetItemText(i,VARIABLE_UNITE,Variable_Analog_Units_Array[m_Variable_data.at(i).range]);
				char temp_char[50];
				int time_seconds = m_Variable_data.at(i).value / 1000;
				intervaltotextfull(temp_char,time_seconds,0,0);
				CString temp_11;
				MultiByteToWideChar( CP_ACP, 0, temp_char, strlen(temp_char) + 1, 
					temp_11.GetBuffer(MAX_PATH), MAX_PATH );
				temp_11.ReleaseBuffer();		
				m_variable_list.SetItemText(i,VARIABLE_VALUE,temp_11);

				//temp_value.Format(_T("%d"),m_Variable_data.at(i).value);
				//m_variable_list.SetItemText(i,VARIABLE_VALUE,temp_value);
			}
			//else if(m_Variable_data.at(i).range == 0)
			//{
			//	m_variable_list.SetItemText(i,VARIABLE_UNITE,Variable_Analog_Units_Array[0]);
			//}
			else if(m_Variable_data.at(i).range<=sizeof(Variable_Analog_Units_Array)/sizeof(Variable_Analog_Units_Array[0]))
			{
			m_variable_list.SetItemText(i,VARIABLE_UNITE,Variable_Analog_Units_Array[m_Variable_data.at(i).range]);

			CString cstemp_value;
			float temp_float_value;
			temp_float_value = ((float)m_Variable_data.at(i).value) / 1000;
			cstemp_value.Format(_T("%.3f"),temp_float_value);
			m_variable_list.SetItemText(i,VARIABLE_VALUE,cstemp_value);

			//temp_value.Format(_T("%d"),m_Variable_data.at(i).value);
			//m_variable_list.SetItemText(i,VARIABLE_VALUE,temp_value);
			}
			else
			{
				m_variable_list.SetItemText(i,VARIABLE_UNITE,Variable_Analog_Units_Array[0]);

				CString cstemp_value;
				float temp_float_value;
				temp_float_value = ((float)m_Variable_data.at(i).value) / 1000;
				cstemp_value.Format(_T("%.3f"),temp_float_value);
				m_variable_list.SetItemText(i,VARIABLE_VALUE,cstemp_value);
			}

		}
		
		CString temp_des2;
		MultiByteToWideChar( CP_ACP, 0, (char *)m_Variable_data.at(i).label, (int)strlen((char *)m_Variable_data.at(i).label)+1, 
			temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
		temp_des2.ReleaseBuffer();
		m_variable_list.SetItemText(i,VARIABLE_LABLE,temp_des2);


		if(isFreshOne)
		{
			break;
		}

	}
	copy_data_to_ptrpanel(TYPE_VARIABLE);

	return 0;
}
LRESULT CBacnetInput::Fresh_Input_Item(WPARAM wParam,LPARAM lParam)
{
    int cmp_ret ;//compare if match it will 0;
    int Changed_Item = (int)wParam;
    int Changed_SubItem = (int)lParam;

    memcpy_s(&m_temp_Input_data[Changed_Item],sizeof(Str_in_point),&m_Input_data.at(Changed_Item),sizeof(Str_in_point));

    CString temp_task_info;
    CString New_CString =  m_input_list.GetItemText(Changed_Item,Changed_SubItem);
    CString cstemp_value;
    if(Changed_SubItem == INPUT_LABLE)
    {
        CString cs_temp = m_input_list.GetItemText(Changed_Item,Changed_SubItem);
        if(cs_temp.GetLength()>= STR_IN_LABEL)	//长度不能大于结构体定义的长度;
        {
            MessageBox(_T("Length can not higher than 8"),_T("Warning"));
            PostMessage(WM_REFRESH_BAC_INPUT_LIST,NULL,NULL);
            return 0;
        }
        char cTemp1[255];
        memset(cTemp1,0,255);
        WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
        memcpy_s(m_Input_data.at(Changed_Item).label,STR_IN_LABEL,cTemp1,STR_IN_LABEL);
    }

    if(Changed_SubItem == INPUT_FULL_LABLE)
    {
        CString cs_temp = m_input_list.GetItemText(Changed_Item,Changed_SubItem);
        if(cs_temp.GetLength()>= STR_IN_DESCRIPTION_LENGTH)	//长度不能大于结构体定义的长度;
        {
            MessageBox(_T("Length can not higher than 20"),_T("Warning"));
            PostMessage(WM_REFRESH_BAC_INPUT_LIST,NULL,NULL);
            return 0;
        }

        char cTemp1[255];
        memset(cTemp1,0,255);
        WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
        memcpy_s(m_Input_data.at(Changed_Item).description,STR_IN_DESCRIPTION_LENGTH,cTemp1,STR_IN_DESCRIPTION_LENGTH);
    }


    if(Changed_SubItem == INPUT_AUTO_MANUAL)
    {
        CString temp_cs = m_input_list.GetItemText(Changed_Item,Changed_SubItem);
        if(temp_cs.CompareNoCase(_T("Auto"))==0)
        {
            m_input_list.SetCellEnabled(Changed_Item,INPUT_VALUE,0);
            m_Input_data.at(Changed_Item).auto_manual = BAC_AUTO ;
        }
        else
        {
            m_input_list.SetCellEnabled(Changed_Item,INPUT_VALUE,1);
            m_Input_data.at(Changed_Item).auto_manual = BAC_MANUAL ;
        }
    }

    if(Changed_SubItem == INPUT_VALUE)
    {
        CString temp_cs = m_input_list.GetItemText(Changed_Item,Changed_SubItem);

        int temp_int = (int)(_wtof(temp_cs) * 1000);
        //int temp_int = _wtoi(temp_cs);
        m_Input_data.at(Changed_Item).value = temp_int;
    }

    if(Changed_SubItem == INPUT_RANGE)
    {
        CString temp_cs = m_input_list.GetItemText(Changed_Item,Changed_SubItem);
        BacnetRange dlg;
        if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_ANALOG])==0)
        {
            bac_ranges_type = INPUT_RANGE_ANALOG_TYPE;
            dlg.DoModal();
            if(range_cancel)
            {
                PostMessage(WM_REFRESH_BAC_INPUT_LIST,Changed_Item,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
                return 0;
            }
            m_Input_data.at(Changed_Item).digital_analog =  BAC_UNITS_ANALOG;
            m_Input_data.at(Changed_Item).range =  bac_range_number_choose;
            m_input_list.SetItemText(Changed_Item,INPUT_RANGE,Input_Analog_Units_Array[bac_range_number_choose]);
            m_input_list.SetItemText(Changed_Item,INPUT_UNITE,Input_List_Analog_Units[bac_range_number_choose]);

            cstemp_value.Format(_T("%d"),m_Input_data.at(Changed_Item).calibration);
            m_input_list.SetItemText(Changed_Item,INPUT_CAL,cstemp_value);


            m_input_list.SetCellEnabled(Changed_Item,INPUT_CAL,1);
            m_input_list.SetCellEnabled(Changed_Item,INPUT_UNITE,1);
            //m_input_list.SetItemText(Changed_Item,OUTPUT_100_PERSENT,_T("10"));
            //m_input_list.SetCellEnabled(Changed_Item,OUTPUT_100_PERSENT,1);

            CString cstemp_value;
            float temp_float_value;
            temp_float_value = ((float)m_Input_data.at(Changed_Item).value) / 1000;
            cstemp_value.Format(_T("%.2f"),temp_float_value);
            m_input_list.SetItemText(Changed_Item,INPUT_VALUE,cstemp_value);

            //cstemp_value.Format(_T("%d"),m_Input_data.at(Changed_Item).value);
            //m_input_list.SetItemText(Changed_Item,INPUT_VALUE,cstemp_value);
        }
        else if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_DIGITAL])==0)
        {
            bac_range_number_choose = m_Input_data.at(Changed_Item).range;
            bac_ranges_type = INPUT_RANGE_DIGITAL_TYPE;
            dlg.DoModal();
            if(range_cancel)
            {
                PostMessage(WM_REFRESH_BAC_INPUT_LIST,Changed_Item,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
                return 0;
            }
            m_Input_data.at(Changed_Item).digital_analog =  BAC_UNITS_DIGITAL;
            m_Input_data.at(Changed_Item).range =  bac_range_number_choose;
            //m_input_list.SetItemText(Changed_Item,INPUT_RANGE,INPUT_Digital_Units_Show[bac_range_number_choose]);

            m_input_list.SetItemText(Changed_Item,INPUT_CAL,_T(""));
            m_input_list.SetCellEnabled(Changed_Item,INPUT_CAL,0);
            m_input_list.SetItemText(Changed_Item,INPUT_UNITE,_T(""));
            m_input_list.SetCellEnabled(Changed_Item,INPUT_UNITE,0);

            CString temp1;
            CStringArray temparray;
            temp1 = Digital_Units_Array[bac_range_number_choose];//22 is the sizeof the array
            SplitCStringA(temparray,temp1,_T("/"));

            if(m_Input_data.at(Changed_Item).control == 1)
            {
                if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
                {
                    m_input_list.SetItemText(Changed_Item,INPUT_VALUE,temparray.GetAt(1));
                }
            }
            else
            {
                if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
                {
                    m_input_list.SetItemText(Changed_Item,INPUT_VALUE,temparray.GetAt(0));
                }
            }
            m_input_list.SetItemText(Changed_Item,INPUT_RANGE,temp1);


        }
        else if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_CUSTOM])==0)
        {
            bac_ranges_type = OUTPUT_RANGE_CUSTOM_DIG_TYPE;
            //dlg.DoModal();
        }
        else
        {
            PostMessage(WM_REFRESH_BAC_INPUT_LIST,Changed_Item,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
            //m_input_list.SetItemText(Changed_Item,INPUT_RANGE,temp_cs);
        }
    }


    //if(Changed_SubItem==INPUT_RANGE)
    //{
    //	CString temp_cs = m_input_list.GetItemText(Changed_Item,Changed_SubItem);
    //	if(temp_cs.CompareNoCase(_T("Not Used"))==0)
    //	{
    //		m_input_list.SetItemText(Changed_Item,INPUT_UNITE,Input_Unit[_unused]);
    //	}
    //	else if(temp_cs.CompareNoCase(_T("10K(-40->120)"))==0)
    //	{
    //		ListCtrlEx::CStrList strlist;
    //		strlist.clear();
    //		strlist.push_back(Input_Unit[degC]);
    //		//strlist.push_back(Input_Unit[degF]);
    //		m_input_list.SetCellStringList(Changed_Item, INPUT_UNITE, strlist);
    //		m_input_list.SetItemText(Changed_Item,INPUT_UNITE,Input_Unit[degC]);
    //	}
    //	else if(temp_cs.CompareNoCase(_T("I 4->20ma"))==0)
    //	{
    //		ListCtrlEx::CStrList strlist;
    //		strlist.clear();
    //		TRACE(Input_Unit[ma]);
    //		strlist.push_back(Input_Unit[ma]);
    //		m_input_list.SetCellStringList(Changed_Item, INPUT_UNITE, strlist);
    //		m_input_list.SetItemText(Changed_Item,INPUT_UNITE,Input_Unit[ma]);
    //	}
    //	else if(temp_cs.CompareNoCase(_T("V 0->10V"))==0)
    //	{
    //		ListCtrlEx::CStrList strlist;
    //		strlist.clear();
    //		TRACE(Input_Unit[Volts]);
    //		strlist.push_back(Input_Unit[Volts]);
    //		m_input_list.SetCellStringList(Changed_Item, INPUT_UNITE, strlist);
    //		m_input_list.SetItemText(Changed_Item,INPUT_UNITE,Input_Unit[Volts]);
    //	}
    //	else if(temp_cs.CompareNoCase(_T("V 0->5V"))==0)
    //	{
    //		ListCtrlEx::CStrList strlist;
    //		strlist.clear();
    //		TRACE(Input_Unit[Volts]);
    //		strlist.push_back(Input_Unit[Volts]);
    //		m_input_list.SetCellStringList(Changed_Item, INPUT_UNITE, strlist);
    //		m_input_list.SetItemText(Changed_Item,INPUT_UNITE,Input_Unit[Volts]);
    //	}
    //	else if(temp_cs.CompareNoCase(_T("V 0->24AC"))==0)
    //	{
    //		ListCtrlEx::CStrList strlist;
    //		strlist.clear();
    //		strlist.push_back(_T("ON/OFF"));
    //		m_input_list.SetCellStringList(Changed_Item, INPUT_UNITE, strlist);
    //		m_input_list.SetItemText(Changed_Item,INPUT_UNITE,_T("ON/OFF"));
    //	}
    //	else if(temp_cs.CompareNoCase(_T("TST Normal"))==0)
    //	{
    //		ListCtrlEx::CStrList strlist;
    //		strlist.clear();
    //		strlist.push_back(_T("ON/OFF"));
    //		m_input_list.SetCellStringList(Changed_Item, INPUT_UNITE, strlist);
    //		m_input_list.SetItemText(Changed_Item,INPUT_UNITE,_T("ON/OFF"));
    //	}
    //}

    if(Changed_SubItem==INPUT_CAL)
    {
        CString cs_temp=m_input_list.GetItemText(Changed_Item,INPUT_CAL);
        int cal_value = _wtoi(cs_temp);
        m_Input_data.at(Changed_Item).calibration = cal_value;
    }
    else if(Changed_SubItem==INPUT_FITLER)
    {
        CString cs_temp=m_input_list.GetItemText(Changed_Item,INPUT_FITLER);
        int  temp2 = _wtoi(cs_temp);
        m_Input_data.at(Changed_Item).filter = (int8_t)(log((double)temp2)/log((double)2));
    }
    else if(Changed_SubItem==INPUT_DECOM)
    {
        CString cs_temp = m_input_list.GetItemText(Changed_Item,INPUT_DECOM);
        int dec_index=-1;
        for (int m=0; m<(int)sizeof(Decom_Array)/sizeof(Decom_Array[0]); m++)
        {
            if(cs_temp.CompareNoCase(Decom_Array[m])==0)
            {
                dec_index = m;
                break;
            }
        }
        m_Input_data.at(Changed_Item).decom = dec_index;
    }

    cmp_ret = memcmp(&m_temp_Input_data[Changed_Item],&m_Input_data.at(Changed_Item),sizeof(Str_in_point));
    if(cmp_ret!=0)
    {
        m_input_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR);
        temp_task_info.Format(_T("Write Input List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString);
        Post_Write_Message(g_bac_instance,WRITEINPUT_T3000,Changed_Item,Changed_Item,sizeof(Str_in_point),m_input_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem);
    }
    //m_input_list.Invalidate();
    return 0;
}
LRESULT BacnetController::Fresh_Controller_List(WPARAM wParam,LPARAM lParam)
{
	CString temp_des2;
	CString temp_des3;
	CString temp_in_unit;
	CString temp_set_unit;
	int Fresh_Item;
	int isFreshOne = (int)lParam;
	if(isFreshOne == REFRESH_ON_ITEM)
	{
		Fresh_Item = (int)wParam;
	}
	else
	{
#if 1
		if(m_controller_list.IsDataNewer((char *)&m_controller_data.at(0),sizeof(Str_controller_point) * BAC_PID_COUNT))
		{
			//避免list 刷新时闪烁;在没有数据变动的情况下不刷新List;
			m_controller_list.SetListData((char *)&m_controller_data.at(0),sizeof(Str_controller_point) * BAC_PID_COUNT);
		}
		else
		{
			//return 0;
		}
#endif
	}
	


	for (int i=0;i<(int)m_controller_data.size();i++)
	{
		if(i>=controller_item_limit_count)
			break;

		if(isFreshOne)
		{
			i = Fresh_Item;
		}

		temp_des2.Empty();

		if(2 == m_controller_data.at(i).input.point_type)
		{
			if(m_controller_data.at(i).input.number< BAC_INPUT_ITEM_COUNT)
			{	
					MultiByteToWideChar( CP_ACP, 0, (char *)m_Input_data.at(m_controller_data.at(i).input.number ).label, 
						(int)strlen((char *)m_Input_data.at(m_controller_data.at(i).input.number ).label)+1, 
						temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
					temp_des2.ReleaseBuffer();	


					if(temp_des2.GetLength()>9)
						temp_des2.Format(_T("%d-IN%d"),m_controller_data.at(i).input.panel,m_controller_data.at(i).input.number);
					if(temp_des2.IsEmpty())
						temp_des2.Format(_T("%d-IN%d"),m_controller_data.at(i).input.panel,m_controller_data.at(i).input.number);

					//temp_des3.Format(_T("%d"),m_Input_data.at(m_controller_data.at(i).input.number - 1).value);	
					CString cstemp_value;
					float temp_float_value;
					temp_float_value = ((float)m_controller_data.at(i).input_value) / 1000;

					cstemp_value.Format(_T("%.1f"),temp_float_value);
					m_controller_list.SetItemText(i,CONTROLLER_INPUTVALUE,cstemp_value);


					//********************************************************************************************************
					// bind the the input units.
					int x = m_controller_data.at(i).input.number;
					if(m_Input_data.at(x).digital_analog == BAC_UNITS_ANALOG)
					{
						m_controller_list.SetItemText(i,CONTROLLER_INPUTUNITS,Input_List_Analog_Units[m_Input_data.at(x).range]);
					}
			
			}
		}
		else if(3 == m_controller_data.at(i).input.point_type)
		{
			if(m_controller_data.at(i).input.number< BAC_VARIABLE_ITEM_COUNT)
			{	
					MultiByteToWideChar( CP_ACP, 0, (char *)m_Variable_data.at(m_controller_data.at(i).input.number ).label, 
						(int)strlen((char *)m_Variable_data.at(m_controller_data.at(i).input.number ).label)+1, 
						temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
					temp_des2.ReleaseBuffer();	



					if(temp_des2.GetLength()>9)
						temp_des2.Format(_T("%d-VAR%d"),m_controller_data.at(i).input.panel,m_controller_data.at(i).input.number);
					if(temp_des2.IsEmpty())
						temp_des2.Format(_T("%d-VAR%d"),m_controller_data.at(i).input.panel,m_controller_data.at(i).input.number);

					//temp_des3.Format(_T("%d"),m_Input_data.at(m_controller_data.at(i).input.number - 1).value);	
					CString cstemp_value;
					float temp_float_value;
					temp_float_value = ((float)m_controller_data.at(i).input_value) / 1000;

					cstemp_value.Format(_T("%.1f"),temp_float_value);
					m_controller_list.SetItemText(i,CONTROLLER_INPUTVALUE,cstemp_value);


					//********************************************************************************************************
					// bind the the input units.
					int x = m_controller_data.at(i).input.number;
					if(m_Variable_data.at(x).digital_analog == BAC_UNITS_ANALOG)
					{
						if(m_Variable_data.at(x).range <= sizeof(Variable_Analog_Units_Array)/sizeof(Variable_Analog_Units_Array[0]))
							m_controller_list.SetItemText(i,CONTROLLER_INPUTUNITS,Variable_Analog_Units_Array[m_Variable_data.at(x).range]);
					}
			
			}
		}
		else
		{
			m_controller_list.SetItemText(i,CONTROLLER_INPUTVALUE,_T(""));
			m_controller_list.SetItemText(i,CONTROLLER_INPUTUNITS,_T(""));
		}
		
		m_controller_list.SetItemText(i,CONTROLLER_INPUT,temp_des2);

		float persend_data;
		persend_data = ((float)m_controller_data.at(i).value)/ 1000;
		CString temp_output_value;
		temp_output_value.Format(_T("%.1f%%"),persend_data);
		m_controller_list.SetItemText(i,CONTROLLER_OUTPUT,temp_output_value);

		//CString temp_sample_time;
		//temp_sample_time.Format(_T("%u"),m_controller_data.at(i).sample_time);
		//m_controller_list.SetItemText(i,CONTROLLER_SAMPLE_TIME,temp_sample_time);
		//temp_des2.Format(_T("%d"),m_controller_data.at(i).input_value);
		//m_controller_list.SetItemText(i,CONTROLLER_INPUTVALUE,temp_des2);

		//if(m_controller_data.at(i).input.number < BAC_INPUT_ITEM_COUNT)
		//{
		//	if(m_Input_data.at(m_controller_data.at(i).input.number).range < INPUT_ANOLAG_UNITE_COUNT)
		//		m_controller_list.SetItemText(i,CONTROLLER_INPUTUNITS,Input_List_Analog_Units[m_Input_data.at(m_controller_data.at(i).input.number).range]);
		//	else
		//		m_controller_list.SetItemText(i,CONTROLLER_INPUTUNITS,_T(""));
		//}
		
			
		temp_des2.Empty();
		temp_des3.Empty();
		temp_set_unit.Empty();
		if(m_controller_data.at(i).setpoint.point_type == 1) 
		{
			if(m_controller_data.at(i).setpoint.number< BAC_OUTPUT_ITEM_COUNT)
			{

			}
		}
		else if(m_controller_data.at(i).setpoint.point_type == 2) 
		{
			if(m_controller_data.at(i).setpoint.number< BAC_INPUT_ITEM_COUNT)
			{
					int num_point,num_panel,num_net,k;
					Point_T3000 point;
					point.number = m_controller_data.at(i).setpoint.number;
					point.number = point.number + 1;	//input setpoint 是从 0 开始计数的 ,但是要去找point label 要从1开始;
					point.panel = m_controller_data.at(i).setpoint.panel;
					point.point_type = m_controller_data.at(i).setpoint.point_type - 1;	//调用 ispoint的时候要减一;
					byte point_type,var_type;

					int temp_network = 0;
					char buf[255];
					char q[17];
					pointtotext_for_controller(q, &point);

					char * temp1 = ispoint(q,&num_point,&var_type, &point_type, &num_panel, &num_net, temp_network, point.panel, &k);
					if(temp1!=NULL)
					{
						if(strlen(temp1) < 255)
						{
							strcpy(buf,temp1);

							MultiByteToWideChar( CP_ACP, 0, (char *)buf,(int)strlen((char *)buf)+1, 
								temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
							temp_des2.ReleaseBuffer();	

							float temp_float_value;
							temp_float_value = ((float)m_controller_data.at(i).setpoint_value) / 1000;
							temp_des3.Format(_T("%.1f"),temp_float_value);



							int x = m_controller_data.at(i).setpoint.number;
							if(m_Input_data.at(x).digital_analog == BAC_UNITS_ANALOG)
							{

								if(m_Input_data.at(x).range <  (sizeof(Input_List_Analog_Units)/sizeof(Input_List_Analog_Units[0])))
									temp_set_unit = Input_List_Analog_Units[m_Input_data.at(x).range];
									
							}
						}
					}
				
			}
		}
		else if(m_controller_data.at(i).setpoint.point_type == 3)	//Variable
		{
			if(m_controller_data.at(i).setpoint.number< BAC_VARIABLE_ITEM_COUNT)
			{
				int num_point,num_panel,num_net,k;
				Point_T3000 point;
				point.number = m_controller_data.at(i).setpoint.number;
				point.number = point.number + 1;	//input setpoint 是从 0 开始计数的 ,但是要去找point label 要从1开始;
				point.panel = m_controller_data.at(i).setpoint.panel;
				point.point_type = m_controller_data.at(i).setpoint.point_type - 1;	//调用 ispoint的时候要减一;
				byte point_type,var_type;

				int temp_network = 0;
				char buf[255];
				char q[17];
				pointtotext_for_controller(q, &point);

				char * temp1 = ispoint(q,&num_point,&var_type, &point_type, &num_panel, &num_net, temp_network, point.panel, &k);
				if(temp1!=NULL)
				{
					if(strlen(temp1) < 255)
					{
						strcpy(buf,temp1);

						MultiByteToWideChar( CP_ACP, 0, (char *)buf,(int)strlen((char *)buf)+1, 
							temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
						temp_des2.ReleaseBuffer();	

						float temp_float_value;
						temp_float_value = ((float)m_controller_data.at(i).setpoint_value) / 1000;
						temp_des3.Format(_T("%.1f"),temp_float_value);



						int x = m_controller_data.at(i).setpoint.number;
						if(m_Variable_data.at(x).digital_analog == BAC_UNITS_DIGITAL)
						{


							if(m_Variable_data.at(x).range>30)
							{
								temp_set_unit = _T("");
							}
							else
							{
								CString temp1;
								CStringArray temparray;

								if((m_Variable_data.at(x).range < 23) &&(m_Variable_data.at(x).range !=0))
									temp1 = Digital_Units_Array[m_Variable_data.at(x).range];
								else if((m_Variable_data.at(x).range >=23) && (m_Variable_data.at(x).range <= 30))
								{
									if(receive_customer_unit)
										temp1 = temp_unit_no_index[m_Variable_data.at(x).range - 23];
								}

								SplitCStringA(temparray,temp1,_T("/"));
								if((temparray.GetSize()==2))
								{
									if(m_Variable_data.at(x).control == 0)
										temp_set_unit = temparray.GetAt(0);
									else
										temp_set_unit = temparray.GetAt(1);
								}

							}
						}
						else
						{
							if(m_Variable_data.at(x).range == 20)	//如果是时间;
							{
								temp_set_unit = Variable_Analog_Units_Array[m_Variable_data.at(x).range];
								char temp_char[50];
								int time_seconds = m_Variable_data.at(x).value / 1000;
								intervaltotext(temp_char,time_seconds,0,0);
								CString temp_11;
								MultiByteToWideChar( CP_ACP, 0, temp_char, strlen(temp_char) + 1, 
									temp_11.GetBuffer(MAX_PATH), MAX_PATH );
								temp_11.ReleaseBuffer();		
								
								temp_set_unit = temp_11;
								//temp_value.Format(_T("%d"),m_Variable_data.at(i).value);
								//m_variable_list.SetItemText(i,VARIABLE_VALUE,temp_value);
							}
							else if(m_Variable_data.at(x).range<=sizeof(Variable_Analog_Units_Array)/sizeof(Variable_Analog_Units_Array[0]))
							{
								//m_variable_list.SetItemText(i,VARIABLE_UNITE,Variable_Analog_Units_Array[m_Variable_data.at(i).range]);
								temp_set_unit = Variable_Analog_Units_Array[m_Variable_data.at(x).range];
								//CString cstemp_value;
								//float temp_float_value;
								//temp_float_value = ((float)m_Variable_data.at(i).value) / 1000;
								//cstemp_value.Format(_T("%.3f"),temp_float_value);
								//m_variable_list.SetItemText(i,VARIABLE_VALUE,cstemp_value);

								//temp_value.Format(_T("%d"),m_Variable_data.at(i).value);
								//m_variable_list.SetItemText(i,VARIABLE_VALUE,temp_value);
							}
						}





					}
				}
			}
		}
#if 0
		if(m_controller_data.at(i).setpoint.number< BAC_VARIABLE_ITEM_COUNT)
		{	
			if(m_controller_data.at(i).setpoint.point_type == 0 )
				temp_des2.Empty();
			else
			{
				int num_point,num_panel,num_net,k;
				Point_T3000 point;
				point.number = m_controller_data.at(i).setpoint.number;
				point.number = point.number + 1;	//input setpoint 是从 0 开始计数的 ,但是要去找point label 要从1开始;
				point.panel = m_controller_data.at(i).setpoint.panel;
				point.point_type = m_controller_data.at(i).setpoint.point_type;
				byte point_type,var_type;
				
				int temp_network = 0;
				char buf[255];
				char q[17];
				pointtotext_for_controller(q, &point);

				char * temp1 = ispoint(q,&num_point,&var_type, &point_type, &num_panel, &num_net, temp_network, point.panel, &k);
				if(temp1!=NULL)
				{
					if(strlen(temp1) < 255)
					{
						strcpy(buf,temp1);

						MultiByteToWideChar( CP_ACP, 0, (char *)buf,(int)strlen((char *)buf)+1, 
							temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
						temp_des2.ReleaseBuffer();	
					}
				}

#if 0
				MultiByteToWideChar( CP_ACP, 0, (char *)m_Variable_data.at(m_controller_data.at(i).setpoint.number - 1).label, 
					(int)strlen((char *)m_Variable_data.at(m_controller_data.at(i).setpoint.number - 1).label)+1, 
					temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
				temp_des2.ReleaseBuffer();	
				if(temp_des2.GetLength()>9)//如果获取的Var长度大于9,说明获取的Label不对,也要重置;
				{
					temp_des2.Empty();
					temp_des3.Empty();
				}
				else
				{
					CString cstemp_value;
					float temp_float_value;
					temp_float_value = ((float)m_Variable_data.at(m_controller_data.at(i).setpoint.number - 1).value) / 1000;
					temp_des3.Format(_T("%.1f"),temp_float_value);
					

					//temp_des3.Format(_T("%d"),m_Variable_data.at(m_controller_data.at(i).setpoint.number - 1).value);
				}
				if(m_Variable_data.at(i).digital_analog == BAC_UNITS_ANALOG)
				{
					if(m_Variable_data.at(i).range<=sizeof(Variable_Analog_Units_Array)/sizeof(Variable_Analog_Units_Array[0]))
					{
						m_controller_list.SetItemText(i,CONTROLLER_SETPOINTUNITS,Variable_Analog_Units_Array[m_Variable_data.at(m_controller_data.at(i).setpoint.number - 1).range]);
						//temp_value.Format(_T("%d"),m_Variable_data.at(i).value);
						//m_variable_list.SetItemText(i,VARIABLE_VALUE,temp_value);
					}
				}
#endif
			}


			

			
		}
#endif
		m_controller_list.SetItemText(i,CONTROLLER_SETPOINT,temp_des2);
		m_controller_list.SetItemText(i,CONTROLLER_SETVALUE,temp_des3);
		m_controller_list.SetItemText(i,CONTROLLER_SETPOINTUNITS,temp_set_unit);
	
		//if(m_controller_data.at(i).units < VARIABLE_ANALOG_UNITE_COUNT)
		//	m_controller_list.SetItemText(i,CONTROLLER_SETPOINTUNITS,Variable_Analog_Units_Array[m_controller_data.at(i).units]);
		//else
		//	m_controller_list.SetItemText(i,CONTROLLER_SETPOINTUNITS,_T(""));


		if(m_controller_data.at(i).action == 0)
		{
			m_controller_list.SetItemText(i,CONTROLLER_ACTION,_T("-"));
		}
		else if(m_controller_data.at(i).action >= 1)
		{
			m_controller_list.SetItemText(i,CONTROLLER_ACTION,_T("+"));
		}
		//else
		//{
		//	m_controller_list.SetItemText(i,CONTROLLER_SETPOINTUNITS,_T(""));
		//}

		temp_des3.Format(_T("%d"),m_controller_data.at(i).proportional);
		m_controller_list.SetItemText(i,CONTROLLER_PROPORTIONAL,temp_des3);

		temp_des3.Format(_T("%d"),m_controller_data.at(i).reset);
		m_controller_list.SetItemText(i,CONTROLLER_RESET,temp_des3);


		if(m_controller_data.at(i).auto_manual==0)
		{
			m_controller_list.SetItemText(i,CONTROLLER_AUTO_MANUAL,_T("Auto"));
			m_controller_list.SetCellEnabled(i,CONTROLLER_OUTPUT,0);
		}
		else
		{
			m_controller_list.SetItemText(i,CONTROLLER_AUTO_MANUAL,_T("Manual"));
			m_controller_list.SetCellEnabled(i,CONTROLLER_OUTPUT,1);
		}


		if(m_controller_data.at(i).bias<=100)
		{
			temp_des3.Format(_T("%d"),m_controller_data.at(i).bias);
			m_controller_list.SetItemText(i,CONTROLLER_BIAS,temp_des3);
		}
		else
		{
			m_controller_data.at(i).bias = 0;
			m_controller_list.SetItemText(i,CONTROLLER_BIAS,_T("0"));
		}

		if(m_controller_data.at(i).rate<=200)
		{
			temp_des3.Format(_T("%.2f"),((float)m_controller_data.at(i).rate)/100);
			m_controller_list.SetItemText(i,CONTROLLER_RATE,temp_des3);
		}
		else
		{
			m_controller_data.at(i).rate = 0;
			m_controller_list.SetItemText(i,CONTROLLER_RATE,_T("0"));
		}

		if(isFreshOne)
		{
			break;
		}
	
	}
	
	return	 0;
}
int GetOutputValue(int index ,CString &ret_cstring,CString &ret_unit,CString &Auto_M,int &digital_value)
{
	CStringArray temparray;
	CString temp1;
	if(index >= BAC_OUTPUT_ITEM_COUNT)
	{
		ret_cstring.Empty();
		ret_unit.Empty();
		Auto_M.Empty();
		return -1;
	}
	int i = index;

	if(m_Output_data.at(i).auto_manual == 1)
	{
		Auto_M = _T("M");
	}
	else
	{
		Auto_M.Empty();
	}


	if(m_Output_data.at(i).digital_analog == BAC_UNITS_ANALOG)
	{

		if(m_Output_data.at(i).range < (sizeof(OutPut_List_Analog_Units)/sizeof(OutPut_List_Analog_Units[0])))
			ret_unit = OutPut_List_Analog_Units[m_Output_data.at(i).range];
		else
		{
			ret_unit.Empty();
			return -1;
		}

		CString temp_value;
		ret_cstring.Format(_T("%.2f"),((float)m_Output_data.at(i).value) / 1000);
		digital_value = 2;//analog;
	}
	else if(m_Output_data.at(i).digital_analog == BAC_UNITS_DIGITAL)
	{
		ret_unit.Empty();

		if(m_Output_data.at(i).range>30)
		{
			ret_cstring.Empty();
			return -1;
		}
		else
		{
			if((m_Output_data.at(i).range < 23) &&(m_Output_data.at(i).range !=0))
				temp1 = Digital_Units_Array[m_Output_data.at(i).range];
			else if((m_Output_data.at(i).range >=23) && (m_Output_data.at(i).range <= 30))
			{
				if(receive_customer_unit)
					temp1 = temp_unit_no_index[m_Output_data.at(i).range - 23];
			}
			else
			{
				temp1.Empty();
				ret_cstring.Empty();
				return -1;
			}

			SplitCStringA(temparray,temp1,_T("/"));
			if((temparray.GetSize()==2))
			{
				if(m_Output_data.at(i).control == 0)
				{
					digital_value = 0;
					ret_cstring = temparray.GetAt(0);
					return 1;
				}
				else
				{
					digital_value = 1;
					ret_cstring = temparray.GetAt(1);
					return 1;
				}
			}
		}
	}

	return 1;
}
void CAddBuilding::OnEnKillfocusAddbuidingSetedit()
{
#if 1
		CString strText;
		m_AddBuiding_SetEditCtrl.GetWindowText(strText);
		m_strMainBuildingName = m_AddBuiding_FlexGrid.get_TextMatrix(m_nCurRow, AB_MAINNAME);
		if (m_nCurRow==m_AddBuiding_FlexGrid.get_Rows()-1)
		{
			if(m_nCurCol==AB_NAME)
			{
				CString strTemp;
				//for(UINT i=0;i++;i<m_BuildNameLst.size())  // commented by zgq;2010-12-06,不知道这种写法是什么意思?				
				for(UINT i=0;i<m_BuildNameLst.size();i++) 
				{
					strTemp=m_BuildNameLst.at(i).strSubBuildName;
					if(strText.CompareNoCase(strTemp)==0 && m_BuildNameLst.at(i).strMainBuildName.CompareNoCase(m_strMainBuildingName)==0) 
					{
						AfxMessageBox(_T("The Subnet Name has existed, please input a unused name."));
						return;
					}
				}

				m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);

				m_strBuildingName=strText;
				m_strBuilding_Name2=strText;
			}
			
			if(m_nCurCol==AB_IPADDRESS)
			{
				CString strIP;
				bool is_domain = false;
				strIP = strText;
				if(strIP.IsEmpty())
					return;
				CStringArray temparray;
				SplitCStringA(temparray,strIP,_T("."));
				if((temparray.GetSize()==4))	//有3个  . 4段
				{
					CString temp_0;
					CString temp_1;
					CString temp_2;
					CString temp_3;
					temp_0 = temparray.GetAt(0);
					temp_1 = temparray.GetAt(1);
					temp_2 = temparray.GetAt(2);
					temp_3 = temparray.GetAt(3);

					if((Is_Dig_Num(temp_0)) && (Is_Dig_Num(temp_1)) && (Is_Dig_Num(temp_2)) && (Is_Dig_Num(temp_3)))
					{
						if(::ValidAddress(strIP) == false)
						{
							MessageBox(_T("Warning!IP address error!"));
							return;
						}

					}
					else	//否则判断为 域名;
					{
						is_domain = true;
					}
				}
				else	//判断为 域名;
				{
					is_domain = true;
				}

				if(is_domain)
				{
					CString temp_host_ip;
					if(!GetIPbyHostName(strText,temp_host_ip))
					{
						AfxMessageBox(_T("Can not get a validate IP adreess from the domain name!"));
						return;
					}
					strText = temp_host_ip;
					//char temp_domain[200];
					//WideCharToMultiByte( CP_ACP, 0, strIP.GetBuffer(), -1, temp_domain, 255, NULL, NULL );
					//strIP.ReleaseBuffer();
					//hostent* host = gethostbyname(temp_domain);
					//if(host == NULL)
					//{
					//	if(IDYES == MessageBox(_T("The domain is unreachable .Continue?"),_T("Warning"),MB_YESNO))
					//	{

					//	}
					//	else
					//	{
					//		return;
					//	}
					//}
				}


#if 0
				if(!ValidAddress(strText))
				{
					if(strText.IsEmpty())
					{
						AfxMessageBox(_T("Please input a validate IP adreess or domain name!"));
						return;
					}
					/*
					CStringIP;
					if(!GetIPbyHostName(strText,CStringIP))
					{
						AfxMessageBox(_T("Can not get a validate IP adreess from the domain name!"));
						return;
					}
					m_strIpAddress=CStringIP;
					m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
					return;
					*/

					
				}
				//if(m_strIpAddress.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
#endif
				m_strIpAddress=strText;
				m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
			}


			if(m_nCurCol==AB_IPPORT)
			{
				//if(m_strIpPort.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
				m_strIpPort=strText;
				m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
			}			
		}
		else
		{		
			if(m_nCurCol==AB_NAME && m_strBuilding_Name2.CompareNoCase(strText)!=0)
			{
				CString strTemp;
				for(UINT i=0;i<m_BuildNameLst.size();i++)
				{
					strTemp=m_BuildNameLst.at(i).strSubBuildName;
					if(strText.CompareNoCase(strTemp)==0&&m_strMainBuildingName2.CompareNoCase(m_BuildNameLst.at(i).strMainBuildName)==0)
					{
						AfxMessageBox(_T("The building Name has exist, please change another one."));
						return;
					}
				}
				/*Good Code//using Format is OK, use strSql= Error..??
				CString strSql;
				//strSql.Format(_T("update Building set Building_Name = '%s', where Building_Name = '%s'"),strText,m_strBuildingName);//erro
				 strSql.Format(_T("update Building set Building_Name = '"+strText+"'  where Building_Name =  '"+m_strBuildingName+"'"));
				_pCon->Execute(strSql.GetString(),NULL,adCmdText);	
				m_strBuildingName=strText;
				*/
				m_strBuildingName=strText;
				
			}
			if(m_nCurCol==AB_IPADDRESS)
			{
		
				if(!::ValidAddress(strText))
				{
					
					//if(strText.CompareNoCase((CString)NO_APPLICATION)==0)
					//return;

					if(strText.IsEmpty())
					{
						//AfxMessageBox(_T("Please input a validate IP adreess or domain name!"));
						return;
					}
				
					/*
					CStringIP;
					if(!GetIPbyHostName(strText,CStringIP))
					{
						AfxMessageBox(_T("Can not get a validate IP adreess from the domain name!"));
						return;
					}
					m_strIpAddress=CStringIP;
					m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
					*/
					//return;
				}
				//if(m_strIpAddress.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
				m_strIpAddress=strText;
			}

			if(m_nCurCol==AB_IPPORT)
			{
				//if(m_strIpPort.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
				m_strIpPort=strText;
			}
			Update_Recorder();
		}
	
		m_AddBuiding_SetEditCtrl.ShowWindow(SW_HIDE);

		OnBnClickedAddbuiding();
#endif
}
void CBacnetProgramEdit::OnSend()
{
	// TODO: Add your command handler code here
	renumvar = 1;
	error = -1; //Default no error;
	CString tempcs;
	((CRichEditCtrl *)GetDlgItem(IDC_RICHEDIT2_PROGRAM))->GetWindowTextW(tempcs);

	char*     pElementText;
	int    iTextLen;
	// wide char to multi char
	iTextLen = WideCharToMultiByte( CP_ACP,0,tempcs,-1,NULL,0,NULL,NULL );
	memset( ( void* )editbuf, 0, sizeof( char ) * ( iTextLen + 1 ) );
	::WideCharToMultiByte( CP_ACP,0,tempcs,-1,editbuf,iTextLen,NULL,NULL );
	Encode_Program();
	if(error == -1)
	{
		TRACE(_T("Encode_Program length is %d ,copy length is %d\r\n"),program_code_length[program_list_line],my_lengthcode + 10);
		if(my_lengthcode+10 <400)
		memcpy_s(program_code[program_list_line],my_lengthcode+10,mycode,my_lengthcode + 10);
		else
		{
			CString temp_mycs;//如果npdu的长度过长,大于 400了,目前是通过换一个page来存;
			temp_mycs.Format(_T("Encode Program Code Length is %d,Please Try to code in another page."),my_lengthcode+10);
			MessageBox(temp_mycs);
			memset(program_code[program_list_line],0,400);
			return;
		}
			

		g_invoke_id =WritePrivateData(g_bac_instance,WRITEPROGRAMCODE_T3000,program_list_line,program_list_line/*,my_lengthcode*/);
		if(g_invoke_id>=0)
		{
			CString temp_cs_show;
			temp_cs_show.Format(_T("Task ID = %d. Write program code to item %d "),g_invoke_id,program_list_line);
			Post_Invoke_ID_Monitor_Thread(MY_INVOKE_ID,g_invoke_id,this->m_hWnd/*BacNet_hwd*/,temp_cs_show);
		}

	}
	else
	{
		CString cstring_error;

		int len = strlen(mesbuf);
		int  unicodeLen = ::MultiByteToWideChar( CP_ACP,0, mesbuf,-1,NULL,0 ); 
		::MultiByteToWideChar( CP_ACP,  0,mesbuf,-1,cstring_error.GetBuffer(MAX_PATH),unicodeLen );  
		cstring_error.ReleaseBuffer();


//		MessageBox(cstring_error);
		CStringArray  Error_info;  
		SplitCStringA(Error_info,cstring_error,_T("\r\n"));//Splite the CString with "\r\n" and then add to the list.(Fance)
		Sleep(1);
		m_information_window.ResetContent();
		for (int i=0;i<(int)Error_info.GetSize();i++)
		{
			m_information_window.InsertString(i,Error_info.GetAt(i));
		}

		MessageBox(_T("Errors,program NOT Sent!"));
	}

}
Example #18
-1
void CBacnetVariable::OnNMClickListVariable(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	long lRow,lCol;
	m_variable_list.Set_Edit(true);
	DWORD dwPos=GetMessagePos();//Get which line is click by user.Set the check box, when user enter Insert it will jump to program dialog
	CPoint point( LOWORD(dwPos), HIWORD(dwPos));
	m_variable_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_variable_list.SubItemHitTest(&lvinfo);

	lRow = lvinfo.iItem;
	lCol = lvinfo.iSubItem;


	if(lRow>m_variable_list.GetItemCount()) //如果点击区超过最大行号,则点击是无效的
		return;
	if(lRow<0)
		return;



	CString temp1;
	m_row = lRow;
	m_col = lCol;

	memcpy_s(&m_temp_variable_data[lRow],sizeof(Str_variable_point),&m_Variable_data.at(lRow),sizeof(Str_variable_point));
	CString New_CString;
	CString temp_task_info;
	if((lCol == VARIABLE_VALUE) &&(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_DIGITAL ) && (m_Variable_data.at(lRow).auto_manual != BAC_AUTO))
	{
		
		
		CString temp1;
		CStringArray temparray;

		if((m_Variable_data.at(lRow).range < 23) &&(m_Variable_data.at(lRow).range !=0))
			temp1 = Digital_Units_Array[m_Variable_data.at(lRow).range];
		else if((m_Variable_data.at(lRow).range >=23) && (m_Variable_data.at(lRow).range <= 30))
		{
			if(receive_customer_unit)
				temp1 = temp_unit_no_index[m_Variable_data.at(lRow).range - 23];
			else
			{
				m_variable_list.Set_Edit(false);
				return;
			}
		}
		else
			return;
		SplitCStringA(temparray,temp1,_T("/"));



		if(m_Variable_data.at(lRow).control == 0)
		{
			m_Variable_data.at(lRow).control = 1;
			m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(1));
			New_CString = temparray.GetAt(1);
		}
		else
		{
			m_Variable_data.at(lRow).control = 0;
			m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(0));
			New_CString = temparray.GetAt(0);
		}
		m_variable_list.Set_Edit(false);

		temp_task_info.Format(_T("Write Variable List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
	}
	else if((lCol == VARIABLE_VALUE) &&(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_ANALOG ) && (m_Variable_data.at(lRow).auto_manual == BAC_MANUAL) && (m_Variable_data.at(lRow).range == 20))
	{
		m_variable_list.Set_Edit(false);
		m_variable_time_picker.ShowWindow(SW_SHOW);
		CRect list_rect,win_rect;
		m_variable_list.GetWindowRect(list_rect);
		GetWindowRect(win_rect);
		CRect myrect;
		m_variable_list.GetSubItemRect(lRow,lCol,LVIR_BOUNDS,myrect);


		myrect.left = myrect.left + list_rect.left - win_rect.left  +2 ;
		myrect.right = myrect.right + list_rect.left - win_rect.left + 2;
		myrect.top = myrect.top + 24;
		myrect.bottom = myrect.bottom + 26;
		m_variable_time_picker.BringWindowToTop();
		m_variable_time_picker.MoveWindow(myrect);

		
		CString Temp_CString =  m_variable_list.GetItemText(lRow,lCol);

		CStringArray TEMPCS;
		int temp_hour,temp_minute,temp_second;
		SplitCStringA(TEMPCS, Temp_CString, _T(":"));
		if((int)TEMPCS.GetSize() <3)
		{
			temp_hour = 0;
			temp_minute = 0;
			temp_second = 0;
			CTime TimeTemp(2016,1,1,temp_hour,temp_minute,0);
			m_variable_time_picker.SetFormat(_T("HH:mm:ss"));
			m_variable_time_picker.SetTime(&TimeTemp);
			m_variable_time_picker.SetFocus();
		}
		else
		{
			temp_hour = _wtoi(TEMPCS.GetAt(0));
			temp_minute = _wtoi(TEMPCS.GetAt(1));
			temp_second = _wtoi(TEMPCS.GetAt(2));
			if(temp_hour >=24)
				temp_hour = 0;
			if(temp_minute >=60)
				temp_minute = 0;
			if(temp_second >= 60)
				temp_second = 0;
			CTime TimeTemp(2016,1,1,temp_hour,temp_minute,temp_second);
			m_variable_time_picker.SetFormat(_T("HH:mm:ss"));
			m_variable_time_picker.SetTime(&TimeTemp);
			m_variable_time_picker.SetFocus();
		}
		m_variable_list.SetItemText(lRow,lCol,_T(""));
		m_variable_time_picker.Invalidate();
		SetTimer(2,100,NULL);
	}
	else if(lCol == VARIABLE_VALUE)
	{
		if(m_Variable_data.at(lRow).auto_manual == BAC_AUTO)
		{
			m_variable_list.Set_Edit(false);
			return;
		}
	}
	else if(lCol == VARIABLE_AUTO_MANUAL)
	{
		if(m_Variable_data.at(lRow).auto_manual == 0)
		{
			m_Variable_data.at(lRow).auto_manual = 1;
			m_variable_list.SetItemText(lRow,VARIABLE_AUTO_MANUAL,_T("Manual"));
			New_CString = _T("Manual");
		}
		else
		{
			m_Variable_data.at(lRow).auto_manual = 0;
			m_variable_list.SetItemText(lRow,VARIABLE_AUTO_MANUAL,_T("Auto"));
			New_CString = _T("Auto");
		}
		temp_task_info.Format(_T("Write Variable List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
	}
	else if(lCol == VARIABLE_UNITE)
	{


		BacnetRange dlg;

		//点击产品的时候 需要读customer units,老的产品firmware 说不定没有 这些,所以不强迫要读到;
		if(!read_customer_unit)
		{

			int temp_invoke_id = -1;
			int send_status = true;
			int	resend_count = 0;
			for (int z=0;z<3;z++)
			{
				do 
				{
					resend_count ++;
					if(resend_count>5)
					{
						send_status = false;
						break;
					}
					temp_invoke_id =  GetPrivateData(
						g_bac_instance,
						READUNIT_T3000,
						0,
						BAC_CUSTOMER_UNITS_COUNT - 1,
						sizeof(Str_Units_element));		

					Sleep(SEND_COMMAND_DELAY_TIME);
				} while (g_invoke_id<0);
				if(send_status)
				{
					for (int z=0;z<1000;z++)
					{
						Sleep(1);
						if(tsm_invoke_id_free(temp_invoke_id))
						{
							read_customer_unit = true;
							break;
						}
						else
							continue;
					}

				}
				if(read_customer_unit)
					break;
			}

		}
		if(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_ANALOG)
		{
			bac_ranges_type = VARIABLE_RANGE_ANALOG_TYPE;
			if(m_Variable_data.at(lRow).range > (sizeof(Variable_Analog_Units_Array) / sizeof(Variable_Analog_Units_Array[0])))
			{
				m_Variable_data.at(lRow).range = 0;
				bac_range_number_choose = 0;
			}
		}
		else
		{
			bac_ranges_type = VARIABLE_RANGE_DIGITAL_TYPE;
			if(m_Variable_data.at(lRow).range > 30)
			{
				m_Variable_data.at(lRow).range = 0;
				bac_range_number_choose = 0;
			}
		}


			initial_dialog = 1;
			bac_range_number_choose = m_Variable_data.at(lRow).range;
			dlg.DoModal();
			if(range_cancel)
			{
				PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,lRow,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
				return ;
			}
			if(bac_range_number_choose == 0)	//如果选择的是 unused 就认为是analog 的unused;这样 能显示对应的value;
			{
				m_Variable_data.at(lRow).digital_analog =  BAC_UNITS_ANALOG;
				bac_ranges_type = VARIABLE_RANGE_ANALOG_TYPE;
			}

			if(bac_ranges_type == VARIABLE_RANGE_ANALOG_TYPE)
			{
				m_Variable_data.at(lRow).digital_analog = BAC_UNITS_ANALOG;
				m_Variable_data.at(lRow).range = bac_range_number_choose;
				m_variable_list.SetItemText(lRow,lCol,Variable_Analog_Units_Array[bac_range_number_choose]);



				if(m_Variable_data.at(lRow).range == 20)	//如果是时间;
				{
					char temp_char[50];
					int time_seconds = m_Variable_data.at(lRow).value / 1000;
					intervaltotextfull(temp_char,time_seconds,0,0);

					CString temp_11;
					MultiByteToWideChar( CP_ACP, 0, temp_char, strlen(temp_char) + 1, 
						temp_11.GetBuffer(MAX_PATH), MAX_PATH );
					temp_11.ReleaseBuffer();		
					m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temp_11);

				}
				else
				{
					CString cstemp_value;
					float temp_float_value;
					temp_float_value = ((float)m_Variable_data.at(lRow).value) / 1000;
					cstemp_value.Format(_T("%.3f"),temp_float_value);
					m_variable_list.SetItemText(lRow,VARIABLE_VALUE,cstemp_value);

					/*				cstemp_value.Format(_T("%d"),m_Variable_data.at(Changed_Item).value);
					m_variable_list.SetItemText(Changed_Item,VARIABLE_VALUE,cstemp_value);*/	
				}
			}
			else if((bac_ranges_type == VARIABLE_RANGE_DIGITAL_TYPE) || (bac_ranges_type == INPUT_RANGE_DIGITAL_TYPE) || (bac_ranges_type == OUTPUT_RANGE_DIGITAL_TYPE))
			{
				m_Variable_data.at(lRow).digital_analog = BAC_UNITS_DIGITAL;
				m_Variable_data.at(lRow).range = bac_range_number_choose;


				CStringArray temparray;
				if((bac_range_number_choose >= 23) && (bac_range_number_choose <= 30))
				{
					//temp1.Format(_T("%s"), temp_unit_no_index[bac_range_number_choose - 23]);
					temp1 = temp_unit_no_index[bac_range_number_choose - 23];
				}
				else
					temp1 = Digital_Units_Array[bac_range_number_choose];//22 is the sizeof the array

				SplitCStringA(temparray,temp1,_T("/"));





				if(m_Variable_data.at(lRow).control == 1)
				{
					if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
					{
						m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(1));
					}
				}
				else
				{
					if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
					{
						m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(0));
					}			
				}
				m_variable_list.SetItemText(lRow,VARIABLE_UNITE,temp1);
			}
		
	
	}
	else
	{
		return;
	}

	int cmp_ret = memcmp(&m_temp_variable_data[lRow],&m_Variable_data.at(lRow),sizeof(Str_variable_point));
	if(cmp_ret!=0)
	{
		m_variable_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,lRow,lRow,sizeof(Str_variable_point),m_variable_dlg_hwnd,temp_task_info,lRow,lCol);
	}
	*pResult = 0;
}