void CBacnetCustomerDigitalRange::OnNMClickListCustomerDigitalRange(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here

	long lRow,lCol;
	m_customer_dig_range_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_customer_dig_range_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_customer_dig_range_list.SubItemHitTest(&lvinfo);

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


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

	if(lCol == CUSTOMER_DIGITAL_RANGE_DIRECT_INV)
	{
		memcpy_s(&m_temp_customer_unite_data[lRow],sizeof(Str_Units_element),&m_customer_unit_data.at(lRow),sizeof(Str_Units_element));

		if(m_customer_unit_data.at(lRow).direct == 0)
		{

			m_customer_unit_data.at(lRow).direct = 1;
			m_customer_dig_range_list.SetItemText(lRow,CUSTOMER_DIGITAL_RANGE_DIRECT_INV,_T("Invers"));
			New_CString = _T("Invers");
		}
		else
		{
			m_customer_unit_data.at(lRow).direct = 0;
			m_customer_dig_range_list.SetItemText(lRow,CUSTOMER_DIGITAL_RANGE_DIRECT_INV,_T("Direct"));
			New_CString = _T("Direct");
		}

	}
	else
		return;

	m_customer_dig_range_list.Set_Edit(false);

	int cmp_ret = memcmp(&m_temp_customer_unite_data[lRow],&m_customer_unit_data.at(lRow),sizeof(Str_Units_element));
	if(cmp_ret!=0)
	{
		m_customer_dig_range_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Customer Digital Units Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEUNIT_T3000,(int8_t)lRow,(int8_t)lRow,sizeof(Str_Units_element),m_customer_digital_range_dlg_hwnd,temp_task_info,lRow,lCol);
	}

	*pResult = 0;
}
Exemple #2
0
void CBacnetVariable::OnNMKillfocusDatetimepicker2Variable(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	CTime temp_time;CString temp_cs;
	int chour,cmin,csend;
	m_variable_time_picker.GetTime(temp_time);
	chour = temp_time.GetHour();
	cmin = temp_time.GetMinute();
	csend = temp_time.GetSecond();


	if((chour == 0) &&(cmin	==0) && (csend == 0))
	{
		temp_cs.Empty();
	}
	else
		temp_cs.Format(_T("%02d:%02d:%02d"),chour,cmin,csend);
	m_variable_list.SetItemText(m_row,m_col,temp_cs);

	m_variable_time_picker.ShowWindow(SW_HIDE);

	int write_value;
	write_value =( chour*3600 + cmin * 60 + csend) * 1000;
	m_Variable_data.at(m_row).value = write_value;
	CString temp_task_info;
	temp_task_info.Format(_T("Write Variable Time Item%d .Changed Time to \"%s\" "),m_row + 1,temp_cs);
	Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,m_row,m_row,sizeof(Str_variable_point),BacNet_hwd,temp_task_info);



	*pResult = 0;
}
Exemple #3
0
void CBacnetVariable::OnBnClickedButtonVariableApply()
{
	// TODO: Add your control notification handler code here
	for (int i=0;i<(int)m_Variable_data.size();i++)
	{
		CString cs_temp=m_variable_list.GetItemText(i,VARIABLE_FULL_LABLE);
		char cTemp[255];
		memset(cTemp,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp, 255, NULL, NULL );
		memcpy_s(m_Variable_data.at(i).description,21,cTemp,21);

		cs_temp=m_variable_list.GetItemText(i,VARIABLE_AUTO_MANUAL);
		if(cs_temp.CompareNoCase(_T("Auto"))==0)
		{
			m_Variable_data.at(i).auto_manual= BAC_AUTO;
		}
		else
		{
			m_Variable_data.at(i).auto_manual = BAC_MANUAL;
		}


		cs_temp=m_variable_list.GetItemText(i,VARIABLE_UNITE);
		int index_number=0;

		cs_temp=m_variable_list.GetItemText(i,VARIABLE_LABLE);
		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(i).label,STR_IN_LABEL,cTemp1,STR_IN_LABEL);
	}
	Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,0,19,sizeof(Str_variable_point),BacNet_hwd);
		
}
void CBacnetScheduleTime::OnNMKillfocusDatetimepicker1Schedual(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	CTime temp_time;CString temp_cs;
	int chour,cmin;
	m_schedual_time_picker.GetTime(temp_time);
	chour = temp_time.GetHour();
	cmin = temp_time.GetMinute();
	m_Schedual_Time_data.at(weekly_list_line).Schedual_Day_Time[m_row][m_col - 1].time_hours = chour;
	m_Schedual_Time_data.at(weekly_list_line).Schedual_Day_Time[m_row][m_col - 1].time_minutes = cmin;
	if((chour == 0) &&(cmin	==0))
	{
		temp_cs.Empty();
	}
	else
		temp_cs.Format(_T("%02d:%02d"),chour,cmin);
	m_schedule_time_list.SetItemText(m_row,m_col,temp_cs);

	m_schedual_time_picker.ShowWindow(SW_HIDE);
	CString temp_task_info;
	temp_task_info.Format(_T("Write Schedule Time Item%d .Changed Time to \"%s\" "),weekly_list_line + 1,temp_cs);
	Post_Write_Message(g_bac_instance,WRITETIMESCHEDULE_T3000,weekly_list_line,weekly_list_line,WEEKLY_SCHEDULE_SIZE,BacNet_hwd,temp_task_info);

	*pResult = 0;
}
BOOL BacnetScreen::PreTranslateMessage(MSG* pMsg)
{
	
	if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN) 
	{

		CRect list_rect,win_rect;
		m_screen_list.GetWindowRect(list_rect);
		ScreenToClient(&list_rect);
		::GetWindowRect(m_screen_dlg_hwnd,win_rect);
		m_screen_list.Set_My_WindowRect(win_rect);
		m_screen_list.Set_My_ListRect(list_rect);

		m_screen_list.Get_clicked_mouse_position();
		return TRUE;
	}
	if((pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_DELETE) ||
		(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_BACK))
	{
		int temp_item = -1;
		int temp_sub_item = -1;
		m_screen_list.Get_Selected_Item(temp_item,temp_sub_item);
		if((temp_item >=0) && (temp_item < BAC_SCREEN_COUNT))
		{
			if(temp_sub_item == SCREEN_PIC_FILE)
			{
				CString temp_task_info;
				memset(&m_screen_data.at(temp_item).picture_file,0,11);
				m_screen_list.SetItemText(temp_item,temp_sub_item,_T(""));
					m_screen_list.SetItemBkColor(temp_item,temp_sub_item,LIST_ITEM_CHANGED_BKCOLOR);
					temp_task_info.Format(_T("Write Screen List Item%d .Delete picture file "),temp_item + 1);
					Post_Write_Message(g_bac_instance,WRITESCREEN_T3000,temp_item,temp_item,sizeof(Control_group_point),m_screen_dlg_hwnd ,temp_task_info,temp_item,temp_sub_item);

			}
		}
	}
	if(pMsg->message==WM_NCLBUTTONDBLCLK)
	{
		if(!window_max)
		{
			window_max = true;
			CRect temp_mynew_rect;
			::GetWindowRect(BacNet_hwd,&temp_mynew_rect);	//获取 view的窗体大小;
			::SetWindowPos(this->m_hWnd,NULL,temp_mynew_rect.left,temp_mynew_rect.top,temp_mynew_rect.Width(),temp_mynew_rect.Height(), SWP_SHOWWINDOW);
		}
		else
		{
			window_max = false;
			CRect temp_mynew_rect;
			::GetWindowRect(BacNet_hwd,&temp_mynew_rect);	//获取 view的窗体大小;
			::SetWindowPos(this->m_hWnd,NULL,temp_mynew_rect.left  + 90 ,temp_mynew_rect.top + 70,500,700,SWP_SHOWWINDOW);
		}

		return 1; 
	}
	

	return CDialogEx::PreTranslateMessage(pMsg);
}
LRESULT CBacnetCustomerDigitalRange::Fresh_Customer_Digital_Range_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_customer_unite_data[Changed_Item],sizeof(Str_Units_element),&m_customer_unit_data.at(Changed_Item),sizeof(Str_Units_element));

	CString temp_task_info;
	CString New_CString =  m_customer_dig_range_list.GetItemText(Changed_Item,Changed_SubItem);
	CString cstemp_value;
	if(Changed_SubItem == CUSTOMER_DIGITAL_RANGE_OFF)
	{
		CString cs_temp = m_customer_dig_range_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= 12)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("String length can not greater than 11"),_T("Warning"));
			PostMessage(WM_REFRESH_BAC_CUSTOMER_DIGITAL_RANGE_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_customer_unit_data.at(Changed_Item).digital_units_off,12,cTemp1,12);
	}

	if(Changed_SubItem == CUSTOMER_DIGITAL_RANGE_ON)
	{
		CString cs_temp = m_customer_dig_range_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= 12)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("String length can not greater than 11"),_T("Warning"));
			PostMessage(WM_REFRESH_BAC_CUSTOMER_DIGITAL_RANGE_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_customer_unit_data.at(Changed_Item).digital_units_on,12,cTemp1,12);
	}


	cmp_ret = memcmp(&m_temp_customer_unite_data[Changed_Item],&m_customer_unit_data.at(Changed_Item),sizeof(Str_Units_element));
	if(cmp_ret!=0)
	{
		m_customer_dig_range_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,WRITEUNIT_T3000,Changed_Item,Changed_Item,sizeof(Str_Units_element),m_customer_digital_range_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem);
	}
	//m_input_list.Invalidate();
	return 0;
}
void CBacnetAlarmLog::OnClickListAlarmlog(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	long lRow,lCol;
	m_alarmlog_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_alarmlog_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_alarmlog_list.SubItemHitTest(&lvinfo);

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


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

	if(lCol != ALARMLOG_DEL)	
		return;

	if(m_alarmlog_data.at(lRow).ddelete == 1)	//如果已经是delete 了就不在变了;
		return;
	CString temp_task_info;
	CString New_CString;
	memcpy_s(&m_temp_alarmlog_data[lRow],sizeof(Alarm_point),&m_alarmlog_data.at(lRow),sizeof(Alarm_point));

	m_alarmlog_data.at(lRow).ddelete = 1;
	m_alarmlog_list.SetItemText(lRow,ALARMLOG_DEL,Yes_No[1]);
	New_CString = Yes_No[1];
	m_alarmlog_list.Set_Edit(false);

	int cmp_ret = memcmp(&m_temp_alarmlog_data[lRow],&m_alarmlog_data.at(lRow),sizeof(Alarm_point));
	if(cmp_ret!=0)
	{
		m_alarmlog_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Alarmlog List Item %d .Changed to \"%s\" "),lRow + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEALARM_T3000,lRow,lRow,sizeof(Alarm_point),m_alarmlog_dlg_hwnd,temp_task_info,lRow,lCol);
	}

	*pResult = 0;
}
void CBacnetProgram::OnBnClickedButtonProgramApply()
{
	// TODO: Add your control notification handler code here
	for (int i=0;i<(int)m_Program_data.size();i++)
	{
		CString cs_temp=m_program_list.GetItemText(i,PROGRAM_FULL_LABLE);
		char cTemp[255];
		memset(cTemp,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp, 255, NULL, NULL );
		memcpy_s(m_Program_data.at(i).description,STR_PROGRAM_DESCRIPTION_LENGTH,cTemp,STR_PROGRAM_DESCRIPTION_LENGTH);

		cs_temp=m_program_list.GetItemText(i,PROGRAM_STATUS);
		if(cs_temp.CompareNoCase(_T("OFF"))==0)
		{
			m_Program_data.at(i).on_off=0;
		}
		else
		{
			m_Program_data.at(i).on_off=1;
		}

		cs_temp=m_program_list.GetItemText(i,PROGRAM_AUTO_MANUAL);
		if(cs_temp.CompareNoCase(_T("Auto"))==0)
		{
			m_Program_data.at(i).auto_manual=0;
		}
		else
		{
			m_Program_data.at(i).auto_manual=1;
		}

		cs_temp=m_program_list.GetItemText(i,PROGRAM_LABEL);
		char cTemp1[255];
		memset(cTemp1,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
		memcpy_s(m_Program_data.at(i).label,STR_PROGRAM_LABEL_LENGTH,cTemp1,STR_PROGRAM_LABEL_LENGTH);


	}
	Post_Write_Message(g_bac_instance,WRITEPROGRAM_T3000,0,15,sizeof(Str_program_point),BacNet_hwd);

}
LRESULT CBacnetOutput::Fresh_Output_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_output_list.GetItemText(Changed_Item,Changed_SubItem);
	CString cstemp_value;


	if(Changed_Item>= OUTPUT_LIMITE_ITEM_COUNT)
	{
		m_output_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
		return 0;
	}

	//先保存 原来的值,等结束的时候来比对,看是否有改变,有改变就进行写动作;
	memcpy_s(&m_temp_output_data[Changed_Item],sizeof(Str_out_point),&m_Output_data.at(Changed_Item),sizeof(Str_out_point));

	if(Changed_SubItem == OUTPUT_PWM_PERIOD)
	{
		CString temp_cs = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_int = (int)(_wtof(temp_cs));
		if((temp_int<0) || (temp_int >=256))
		{
			SetPaneString(BAC_SHOW_MISSION_RESULTS,_T("Data out of range!"));
			PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,Changed_Item,REFRESH_ON_ITEM);
			return 0;
		}
		m_Output_data.at(Changed_Item).pwm_period = (unsigned char)temp_int;
	}

	if(Changed_SubItem == OUTPUT_LABLE)
	{
		CString cs_temp = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_OUT_LABEL)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Length can not higher than 8"),_T("Warning"));
			PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,NULL,NULL);
			return 0;
		}
		cs_temp.Replace(_T("-"),_T("_"));
		cs_temp.MakeUpper();
		if(Check_Label_Exsit(cs_temp))
		{
			PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,Changed_Item,REFRESH_ON_ITEM);
			return 0;
		}
		char cTemp1[255];
		memset(cTemp1,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
		memcpy_s(m_Output_data.at(Changed_Item).label,STR_OUT_LABEL,cTemp1,STR_OUT_LABEL);
	}

	if(Changed_SubItem == OUTPUT_FULL_LABLE)
	{
		CString cs_temp = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_OUT_DESCRIPTION_LENGTH)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Length can not higher than 20"),_T("Warning"));
			PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,NULL,NULL);
			return 0;
		}
		if(Check_FullLabel_Exsit(cs_temp))
		{
			PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,Changed_Item,REFRESH_ON_ITEM);
			return 0;
		}
		char cTemp1[255];
		memset(cTemp1,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
		memcpy_s(m_Output_data.at(Changed_Item).description,STR_OUT_DESCRIPTION_LENGTH,cTemp1,STR_OUT_DESCRIPTION_LENGTH);
	}

	if(Changed_SubItem==OUTPUT_AUTO_MANUAL)	//If auto man changed to mannul , the value can be edit by user
	{
		CString temp_cs = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
		if(temp_cs.CompareNoCase(_T("Auto"))==0)
		{
			//m_output_list.SetCellEnabled(Changed_Item,OUTPUT_VALUE,0);
			m_Output_data.at(Changed_Item).auto_manual = BAC_AUTO ;
		}
		else
		{
			//m_output_list.SetCellEnabled(Changed_Item,OUTPUT_VALUE,1);
			m_Output_data.at(Changed_Item).auto_manual = BAC_MANUAL ;
		}
	}

	if(Changed_SubItem == OUTPUT_VALUE)
	{
		CString temp_cs = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
#if 0
		int temp_int = (int)(_wtof(temp_cs) * 1000);
		m_Output_data.at(Changed_Item).value = temp_int;
#endif
	//	int temp_int = _wtoi(temp_cs);
		int temp_int = (int)(_wtof(temp_cs) * 1000);
		m_Output_data.at(Changed_Item).value = temp_int;
	}


	if(Changed_SubItem == OUTPUT_DECOM)
	{
		CString temp_cs = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
		if(temp_cs.CompareNoCase(_T("OK"))==0)
		{
			m_Output_data.at(Changed_Item).decom = BAC_DECOM_YES ;
		}
		else if(temp_cs.CompareNoCase(_T("-"))==0)
		{
			m_Output_data.at(Changed_Item).decom = BAC_DECOM_NO ;
		}
	}

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


	return 0;
}
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;
}
void CBacnetInput::OnBnClickedButtonApply()
{
    // TODO: Add your control notification handler code here
    for (int i=0; i<(int)m_Input_data.size(); i++)
    {
        CString cs_temp=m_input_list.GetItemText(i,INPUT_FULL_LABLE);
        char cTemp[255];
        memset(cTemp,0,255);
        WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp, 255, NULL, NULL );
        memcpy_s(m_Input_data.at(i).description,21,cTemp,21);

        cs_temp=m_input_list.GetItemText(i,INPUT_AUTO_MANUAL);
        if(cs_temp.CompareNoCase(_T("Auto"))==0)
        {
            m_Input_data.at(i).auto_manual=0;
        }
        else
        {
            m_Input_data.at(i).auto_manual=1;
        }

        cs_temp=m_input_list.GetItemText(i,INPUT_RANGE);
        int index_number=0;
        for(int j=0; j<(int)sizeof(Input_Range_Array)/sizeof(Input_Range_Array[0]); j++)
        {
            if(cs_temp.CompareNoCase(Input_Range_Array[j])==0)
            {
                index_number=j;
                break;
            }
        }
        m_Input_data.at(i).range = index_number;

        cs_temp=m_input_list.GetItemText(i,INPUT_UNITE);
        index_number=0;
        for(int j=0; j<(int)sizeof(Input_Unit)/sizeof(Input_Unit[0]); j++) //unit单位很多,在列表中查找
        {
            if(cs_temp.CompareNoCase(Input_Unit[j])==0)
            {
                index_number=j;
                break;
            }
        }

        cs_temp = m_input_list.GetItemText(i,INPUT_VALUE);
        m_Input_data.at(i).value = _wtoi(cs_temp);


        cs_temp=m_input_list.GetItemText(i,INPUT_CAL);
        int cal_value = _wtoi(cs_temp);
        m_Input_data.at(i).calibration = cal_value;


        cs_temp=m_input_list.GetItemText(i,INPUT_FITLER);
        int  temp2 = _wtoi(cs_temp);
        m_Input_data.at(i).filter =(int8_t) (log((double)temp2)/log((double)2));


        cs_temp = m_input_list.GetItemText(i,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(i).decom = dec_index;

        cs_temp=m_input_list.GetItemText(i,INPUT_LABLE);
        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(i).label,STR_IN_LABEL,cTemp1,STR_IN_LABEL);
    }
    Post_Write_Message(g_bac_instance,WRITEINPUT_T3000,0,19,sizeof(Str_in_point),BacNet_hwd);

}
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;
}
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;
}
LRESULT CBacnetProgram::Fresh_Program_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_program_data[Changed_Item],sizeof(Str_program_point),&m_Program_data.at(Changed_Item),sizeof(Str_program_point));


	CString temp_task_info;
	CString New_CString =  m_program_list.GetItemText(Changed_Item,Changed_SubItem);


	if(Changed_SubItem == PROGRAM_LABEL)
	{
		CString cs_temp = m_program_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_PROGRAM_LABEL_LENGTH)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Length can not higher than 8"),_T("Warning"),MB_OK | MB_ICONINFORMATION);
			PostMessage(WM_REFRESH_BAC_PROGRAM_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_Program_data.at(Changed_Item).label,STR_PROGRAM_LABEL_LENGTH,cTemp1,STR_PROGRAM_LABEL_LENGTH);
	}

	if(Changed_SubItem == PROGRAM_FULL_LABLE)
	{
		CString cs_temp = m_program_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_PROGRAM_DESCRIPTION_LENGTH)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Length can not higher than 20"),_T("Warning"),MB_OK | MB_ICONINFORMATION);
			PostMessage(WM_REFRESH_BAC_PROGRAM_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_Program_data.at(Changed_Item).description,STR_PROGRAM_DESCRIPTION_LENGTH,cTemp1,STR_PROGRAM_DESCRIPTION_LENGTH);
	}

	if(Changed_SubItem == PROGRAM_STATUS)
	{
		CString cs_temp=m_program_list.GetItemText(Changed_Item,PROGRAM_STATUS);
		if(cs_temp.CompareNoCase(_T("OFF"))==0)
		{
			m_Program_data.at(Changed_Item).on_off=0;
		}
		else
		{
			m_Program_data.at(Changed_Item).on_off=1;
		}
	}
	if(Changed_SubItem == PROGRAM_AUTO_MANUAL)
	{
		CString cs_temp=m_program_list.GetItemText(Changed_Item,PROGRAM_AUTO_MANUAL);
		if(cs_temp.CompareNoCase(_T("Auto"))==0)
		{
			m_Program_data.at(Changed_Item).auto_manual=0;
		}
		else
		{
			m_Program_data.at(Changed_Item).auto_manual=1;
		}
	}
	cmp_ret = memcmp(&m_temp_program_data[Changed_Item],&m_Program_data.at(Changed_Item),sizeof(Str_program_point));
	if(cmp_ret!=0)
	{
		m_program_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Program List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEPROGRAM_T3000,Changed_Item,Changed_Item,sizeof(Str_program_point),m_pragram_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem);
	}

	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;
}
Exemple #17
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"));

#pragma region note_what_do	
			//如下所做的事 达到 ,在弹窗后 继续选中客户输入的部分 ,毛总的要求;
			CRect list_rect,win_rect;
			m_variable_list.GetWindowRect(list_rect);
			ScreenToClient(&list_rect);
			::GetWindowRect(m_variable_dlg_hwnd,win_rect);
			m_variable_list.Set_My_WindowRect(win_rect);
			m_variable_list.Set_My_ListRect(list_rect);

			m_variable_list.Get_clicked_mouse_position();
#pragma endregion note_what_do

			PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,NULL,NULL);
			return 0;
		}
		cs_temp.Replace(_T("-"),_T("_"));
		cs_temp.MakeUpper();
		if(Check_Label_Exsit(cs_temp))
		{
			PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,Changed_Item,REFRESH_ON_ITEM);
			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"));
#pragma region note_what_do	
			//如下所做的事 达到 ,在弹窗后 继续选中客户输入的部分 ,毛总的要求;
			CRect list_rect,win_rect;
			m_variable_list.GetWindowRect(list_rect);
			ScreenToClient(&list_rect);
			::GetWindowRect(m_variable_dlg_hwnd,win_rect);
			m_variable_list.Set_My_WindowRect(win_rect);
			m_variable_list.Set_My_ListRect(list_rect);

			m_variable_list.Get_clicked_mouse_position();
#pragma endregion note_what_do
			PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,NULL,NULL);
			return 0;
		}
		if(Check_FullLabel_Exsit(cs_temp))
		{
			PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,Changed_Item,REFRESH_ON_ITEM);
			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;
	}

	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;
}
void BacnetController::OnNMClickListController(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	long lRow,lCol;
	m_controller_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_controller_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_controller_list.SubItemHitTest(&lvinfo);

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


	if(lRow>m_controller_list.GetItemCount()) //如果点击区超过最大行号,则点击是无效的
		return;
	if(lRow<0)
		return;
	CString New_CString;
	CString temp_task_info;
	if(lCol == CONTROLLER_ACTION)	
	{
		memcpy_s(&m_temp_controller_data[lRow],sizeof(Str_controller_point),&m_controller_data.at(lRow),sizeof(Str_controller_point));
		if(m_controller_data.at(lRow).action == 0)
		{
			m_controller_data.at(lRow).action = 1;
			m_controller_list.SetItemText(lRow,lCol,_T("+"));
			New_CString.Format(_T("+"));
		}
		else
		{
			m_controller_data.at(lRow).action = 0;
			m_controller_list.SetItemText(lRow,lCol,_T("-"));
			New_CString.Format(_T("-"));
		}
	}
	else if(lCol == CONTROLLER_AUTO_MANUAL)
	{
		memcpy_s(&m_temp_controller_data[lRow],sizeof(Str_controller_point),&m_controller_data.at(lRow),sizeof(Str_controller_point));
		if(m_controller_data.at(lRow).auto_manual == 0)
		{
			m_controller_data.at(lRow).auto_manual = 1;
			m_controller_list.SetItemText(lRow,CONTROLLER_AUTO_MANUAL,_T("Manual"));
			New_CString = _T("Manual");

			m_controller_list.SetCellEnabled(lRow,CONTROLLER_OUTPUT,1);


		}
		else
		{
			m_controller_data.at(lRow).auto_manual = 0;
			m_controller_list.SetItemText(lRow,CONTROLLER_AUTO_MANUAL,_T("Auto"));
			New_CString = _T("Auto");
			m_controller_list.SetCellEnabled(lRow,CONTROLLER_OUTPUT,0);

		}
	}
	else
		return;

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

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



	m_controller_list.Set_Edit(false);

	int cmp_ret = memcmp(&m_temp_controller_data[lRow],&m_controller_data.at(lRow),sizeof(Str_controller_point));
	if(cmp_ret!=0)
	{
		m_controller_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Controller List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEPID_T3000,(int8_t)lRow,(int8_t)lRow,sizeof(Str_controller_point),m_controller_dlg_hwnd,temp_task_info,lRow,lCol);

	}


	*pResult = 0;
}
LRESULT CBacnetTstat::Fresh_Tstat_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_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
	CString cstemp_value;
	//先保存 原来的值,等结束的时候来比对,看是否有改变,有改变就进行写动作;
	memcpy_s(&m_temp_tstat_data[Changed_Item],sizeof(Str_TstatInfo_point),&m_Tstat_data.at(Changed_Item),sizeof(Str_TstatInfo_point));
	if((m_Tstat_data.at(Changed_Item).product_model == 255) || (m_Tstat_data.at(Changed_Item).tst_db.id == 0))
	{
		for (int x = 1; x < TSTAT_COL_NUMBER ; x++)
		{
			m_tstat_list.SetItemText(Changed_Item,x,_T(""));
		}
		return 0;
	}

	if(Changed_SubItem == TSTAT_COOL_SETPOINT )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = (int)(_wtof(cs_temp) * 10);
		if(temp_value >= 65535)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}

		m_Tstat_data.at(Changed_Item).cool_setpoint = temp_value;
	}

	if(Changed_SubItem == TSTAT_HEAT_SETPOINT )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = (int)(_wtof(cs_temp) * 10);
		if(temp_value >= 65535)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}

		m_Tstat_data.at(Changed_Item).heat_setpoint = temp_value;
	}
	
	if(Changed_SubItem == TSTAT_ROOM_SETPOINT )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = (int)(_wtof(cs_temp) * 10);
		if(temp_value >= 65535)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}

		m_Tstat_data.at(Changed_Item).setpoint = temp_value;
	}


	if(Changed_SubItem == TSTAT_ROOM_TEM )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = (int)(_wtof(cs_temp) * 10);
		if(temp_value >= 65535)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}

		m_Tstat_data.at(Changed_Item).temperature = temp_value;
	}

	if(Changed_SubItem == TSTAT_NIGHT_HEAT_DB )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = _wtoi(cs_temp);
		if(temp_value >= 255)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}

		m_Tstat_data.at(Changed_Item).night_heat_db = temp_value;
	}

	if(Changed_SubItem == TSTAT_NIGHT_COOL_DB )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = _wtoi(cs_temp);
		if(temp_value >= 255)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}

		m_Tstat_data.at(Changed_Item).night_cool_db = temp_value;
	}

	if(Changed_SubItem == TSTAT_NIGHT_HEAT_SP )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = _wtoi(cs_temp);
		if(temp_value >= 255)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}

		m_Tstat_data.at(Changed_Item).night_heat_sp = temp_value;
	}

	if(Changed_SubItem == TSTAT_NIGHT_COOL_SP )
	{
		CString cs_temp = m_tstat_list.GetItemText(Changed_Item,Changed_SubItem);
		int temp_value = _wtoi(cs_temp);
		if(temp_value >= 255)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Please input An effective value "),_T("Warning"));
			return 0;
		}
		m_Tstat_data.at(Changed_Item).night_cool_sp = temp_value;
	}

	

	
	
	


	cmp_ret = memcmp(&m_temp_tstat_data[Changed_Item],&m_Tstat_data.at(Changed_Item),sizeof(Str_TstatInfo_point));
	if(cmp_ret!=0)
	{
		m_tstat_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Tstat List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITETSTAT_T3000,Changed_Item,Changed_Item,sizeof(Str_TstatInfo_point),m_tstat_dlg_hwnd,temp_task_info,Changed_Item,Changed_SubItem);
	}

	return 1;
}
LRESULT BacnetController::Fresh_Controller_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_controller_list.GetItemText(Changed_Item,Changed_SubItem);
	CString cstemp_value;

	//先保存 原来的值,等结束的时候来比对,看是否有改变,有改变就进行写动作;
	memcpy_s(&m_temp_controller_data[Changed_Item],sizeof(Str_controller_point),&m_controller_data.at(Changed_Item),sizeof(Str_controller_point));


	if(Changed_SubItem == CONTROLLER_INPUT)
	{
		CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.IsEmpty() == false)
		{
			cs_temp.MakeUpper();

			char cTemp1[255];
			char temp_input[250];
			char * tempcs=NULL;
			memset(cTemp1,0,255);
			WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
			//Search the input label from the list.

			int temp_number=-1;
			byte temp_value_type = -1;
			byte temp_point_type=-1;
			int temp_panel = -1;
			int temp_net = -1;
			int k=0;
			//int temp1;
			tempcs = ispoint(cTemp1,&temp_number,&temp_value_type,&temp_point_type,&temp_panel,&temp_net,0,Station_NUM,&k);
			if(tempcs!=NULL)
			{
				strcpy(temp_input,tempcs);
				CString temp_des2;
				temp_des2.Empty();

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

				m_controller_list.SetItemText(Changed_Item,CONTROLLER_INPUT,temp_des2);

				if(temp_panel != Station_NUM)
				{
					MessageBox(_T("Don't support other panel currently!"),_T("Warning"),MB_OK | MB_ICONINFORMATION);
					m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
					return 0;
				}
				if(temp_number > 0);	//因为Input2  的number 是1;
					temp_number = temp_number - 1;
				temp_point_type = temp_point_type + 1;
				if(2 == temp_point_type)
				{
					m_controller_data.at(Changed_Item).input.number = temp_number;
					m_controller_data.at(Changed_Item).input.panel = temp_panel;//bac_gloab_panel;
					m_controller_data.at(Changed_Item).input.point_type = temp_point_type;//1 means input point

					CString temp_des3;
					if(temp_number < BAC_INPUT_ITEM_COUNT)
					{
						//temp_des3.Format(_T("%d"),m_Input_data.at(temp_number - 1).value);

						CString cstemp_value;
						float temp_float_value;
						temp_float_value = ((float)m_Input_data.at(temp_number).value) / 1000;
						temp_des3.Format(_T("%.1f"),temp_float_value);


						m_controller_data.at(Changed_Item).input_value = m_Input_data.at(temp_number).value;	

						m_controller_list.SetItemText(Changed_Item,CONTROLLER_INPUTVALUE,temp_des3);
					}
				}
				else if(3 == temp_point_type)
				{
					m_controller_data.at(Changed_Item).input.number = temp_number;
					m_controller_data.at(Changed_Item).input.panel = temp_panel;//bac_gloab_panel;
					m_controller_data.at(Changed_Item).input.point_type = temp_point_type;//1 means input point

					CString temp_des3;
					if(temp_number < BAC_VARIABLE_ITEM_COUNT)
					{
						//temp_des3.Format(_T("%d"),m_Input_data.at(temp_number - 1).value);

						CString cstemp_value;
						float temp_float_value;
						temp_float_value = ((float)m_Variable_data.at(temp_number).value) / 1000;
						temp_des3.Format(_T("%.1f"),temp_float_value);


						m_controller_data.at(Changed_Item).input_value = m_Variable_data.at(temp_number).value;	

						m_controller_list.SetItemText(Changed_Item,CONTROLLER_INPUTVALUE,temp_des3);
					}
				}
				else
				{
					m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
					return 0;
				}


			}
			else
			{
				CString temp_message;
				temp_message.Format(_T("%s character not allowed in labels!"),cs_temp.GetString());
				
				MessageBox(temp_message,_T("Information"),MB_OK |MB_ICONINFORMATION);
				m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
				return 0;
			}
		}


	}

	if(Changed_SubItem == CONTROLLER_INPUTVALUE)
	{
		//int temp_value = _wtoi(New_CString);
		int temp_value = (int)(_wtof(New_CString) * 1000);

		if(m_controller_data.at(Changed_Item).input.number == 0 )
			return 0;
		if((m_controller_data.at(Changed_Item).input.number -1 )< BAC_INPUT_ITEM_COUNT)
			m_Input_data.at(m_controller_data.at(Changed_Item).input.number - 1).value = temp_value;
		
		temp_task_info.Format(_T("Write Controllers List Item%d .Changed the input value to \"%s\" "),Changed_Item + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEINPUT_T3000,Changed_Item,Changed_Item,sizeof(Str_in_point),BacNet_hwd ,temp_task_info);
		return 0;
	}




	if(Changed_SubItem == CONTROLLER_SETVALUE)
	{
	//	int temp_value = _wtoi(New_CString);
		int temp_value = (int)(_wtof(New_CString) * 1000);
		if(m_controller_data.at(Changed_Item).setpoint.number == 0 )
			return 0;
		if((m_controller_data.at(Changed_Item).setpoint.number -1 )< BAC_VARIABLE_ITEM_COUNT)
			m_Variable_data.at(m_controller_data.at(Changed_Item).setpoint.number - 1).value = temp_value;

		temp_task_info.Format(_T("Write Controllers List Item%d .Changed the variable value to \"%s\" "),Changed_Item + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,Changed_Item,Changed_Item,sizeof(Str_in_point),BacNet_hwd ,temp_task_info);
		return 0;
	}

	if(Changed_SubItem == CONTROLLER_AUTO_MANUAL)
	{
		CString temp_cs = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);
		if(temp_cs.CompareNoCase(_T("Auto"))==0)
		{
			m_controller_list.SetCellEnabled(Changed_Item,CONTROLLER_OUTPUT,0);
			m_controller_data.at(Changed_Item).auto_manual = BAC_AUTO ;
		}
		else
		{
			m_controller_list.SetCellEnabled(Changed_Item,CONTROLLER_OUTPUT,1);
			m_controller_data.at(Changed_Item).auto_manual = BAC_MANUAL ;
		}
	}

	if(Changed_SubItem == CONTROLLER_OUTPUT)
	{
		CString temp_cs = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);

		int temp_int = (int)(_wtof(temp_cs) * 1000);
		m_controller_data.at(Changed_Item).value = temp_int;
	}

	if(Changed_SubItem == CONTROLLER_SETPOINT)
	{
		CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);
		char cTemp1[255];
		char temp_setpoint[250];
		char * tempcs=NULL;
		memset(cTemp1,0,255);
		memset(temp_setpoint,0,250);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );

		int temp_number=-1;
		byte temp_value_type = -1;
		byte temp_point_type=-1;
		int temp_panel = -1;
		int temp_net = -1;
		int k=0;
		//int temp1;
		//Change the lable.ex: Change the
		tempcs = ispoint(cTemp1,&temp_number,&temp_value_type,&temp_point_type,&temp_panel,&temp_net,0,bac_gloab_panel,&k);
		if(tempcs!=NULL)
		{
			memcpy_s(temp_setpoint,250,tempcs,9);
			//strcpy_s(temp_setpoint,tempcs);
			//strcpy(temp_setpoint,tempcs);
			CString temp_des2;
			temp_des2.Empty();

			MultiByteToWideChar( CP_ACP, 0, temp_setpoint, STR_VARIABLE_LABEL+1, 
				temp_des2.GetBuffer(MAX_PATH), MAX_PATH );
			temp_des2.ReleaseBuffer();		
			
			m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETPOINT,temp_des2);


			if(temp_panel != bac_gloab_panel)
			{
				MessageBox(_T("Don't support other panel currently!"),_T("Warning"),MB_OK | MB_ICONINFORMATION);
				m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
				return 0;
			}
			if(temp_number > 0)	//Setpoint 也是这样;从0 开始的;
				temp_number = temp_number - 1;
			temp_point_type = temp_point_type + 1; //OUTPUT=1, INPUT, VARIABLE 要错位;
			m_controller_data.at(Changed_Item).setpoint.number = temp_number;
			m_controller_data.at(Changed_Item).setpoint.panel = temp_panel;//bac_gloab_panel;
			m_controller_data.at(Changed_Item).setpoint.point_type = temp_point_type;//1 means input point

			CString temp_des3;
			if(temp_number < BAC_VARIABLE_ITEM_COUNT)
			{
				if(m_Variable_data.at(temp_number).range < VARIABLE_ANALOG_UNITE_COUNT)
					temp_des3 = Variable_Analog_Units_Array[m_Variable_data.at(temp_number).range];
				m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETPOINTUNITS,temp_des3);
			}
			char tempAAAA[250];
			memset(tempAAAA,0,250);
			temp_des3.Empty();
			if(m_Variable_data.at(temp_number).range  == 20 )
			{
				if((m_controller_data.at(Changed_Item).setpoint_value>=0)&&(m_controller_data.at(Changed_Item).setpoint_value<86400))
					intervaltotext( tempAAAA, m_controller_data.at(Changed_Item).setpoint_value ,0 , 0);

				MultiByteToWideChar( CP_ACP, 0, tempAAAA, strlen(tempAAAA) + 1, 
					temp_des3.GetBuffer(MAX_PATH), MAX_PATH );
				temp_des3.ReleaseBuffer();	
			}
			else
			{
				CString cstemp_value;
				float temp_float_value;
				temp_float_value = ((float)m_Variable_data.at(m_controller_data.at(Changed_Item).setpoint.number).value) / 1000;
				temp_des3.Format(_T("%.1f"),temp_float_value);

			}
	
			m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETVALUE,temp_des3);

		}
		else
		{
			CString temp_show_ret;
			temp_show_ret = _T("\"") + cs_temp + _T("\"") + _T(" is a invalid label or keyword .");
			SetPaneString(BAC_SHOW_MISSION_RESULTS,temp_show_ret);
			m_controller_list.SetItemText(Changed_Item,CONTROLLER_SETPOINT,_T(""));
		}
	}

	if(Changed_SubItem == CONTROLLER_PROPORTIONAL)
	{
		int temp_proportional=0;
		CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);
		if((cs_temp.GetLength()>3) || (_wtoi(cs_temp)>255) )
		{
			MessageBox(_T("Please input a effective value"),_T("Information"),MB_OK |MB_ICONINFORMATION);
			m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
		}
		else
		{
			m_controller_data.at(Changed_Item).proportional = _wtoi(cs_temp);
		}
	}
	if(Changed_SubItem == CONTROLLER_RESET)
	{
		int temp_reset=0;
		CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);
		if((cs_temp.GetLength()>3) || (_wtoi(cs_temp)>255) )
		{
			MessageBox(_T("Please input a effective value"),_T("Information"),MB_OK |MB_ICONINFORMATION);
			m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
		}
		else
		{
			m_controller_data.at(Changed_Item).reset = _wtoi(cs_temp);
		}
	}

	if(Changed_SubItem == CONTROLLER_RATE)
	{
		int temp_rate=0;
		CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);

		int i_value =  (int)(_wtof(cs_temp) * 100) ;

		if((i_value > 200) || (i_value < 0))
		//if((cs_temp.GetLength()>1) || (_wtoi(cs_temp)>2) )
		{
			MessageBox(_T("Please input a effective value  0.00 - 2.00"),_T("Information"),MB_OK |MB_ICONINFORMATION);
			m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
		}
		else
		{
			m_controller_data.at(Changed_Item).rate = i_value;
		}
	}

	if(Changed_SubItem == CONTROLLER_BIAS)
	{
		int temp_bias=0;
		CString cs_temp = m_controller_list.GetItemText(Changed_Item,Changed_SubItem);
		if((cs_temp.GetLength()>3) || (_wtoi(cs_temp)>100) )
		{
			MessageBox(_T("Please input a effective value"),_T("Information"),MB_OK |MB_ICONINFORMATION);
			m_controller_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
		}
		else
		{
			m_controller_data.at(Changed_Item).bias = _wtoi(cs_temp);
		}
	}



	cmp_ret = memcmp(&m_temp_controller_data[Changed_Item],&m_controller_data.at(Changed_Item),sizeof(Str_controller_point));
	if(cmp_ret!=0)
	{
		m_controller_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Controllers List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEPID_T3000,Changed_Item,Changed_Item,sizeof(Str_controller_point),m_controller_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem);

	}


	
	return 0;
}
LRESULT BacnetScreen::Fresh_Screen_Item(WPARAM wParam,LPARAM lParam)
{
	int Changed_Item = (int)wParam;
	int Changed_SubItem = (int)lParam;

	CString temp_task_info;
	CString New_CString =  m_screen_list.GetItemText(Changed_Item,Changed_SubItem);
	CString cstemp_value;

	memcpy_s(&m_temp_screen_data[Changed_Item],sizeof(Control_group_point),&m_screen_data.at(Changed_Item),sizeof(Control_group_point));

	if(Changed_SubItem == SCREEN_DESCRIPTION)
	{


		CString cs_temp = m_screen_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_SCREEN_DESCRIPTION_LENGTH)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Warning"),_T("Length can not higher than 20"));
			PostMessage(WM_REFRESH_BAC_SCREEN_LIST,NULL,NULL);
			return 0;
		}
		if(Check_FullLabel_Exsit(cs_temp))
		{
			PostMessage(WM_REFRESH_BAC_SCREEN_LIST,Changed_Item,REFRESH_ON_ITEM);
			return 0;
		}
		char cTemp1[255];
		memset(cTemp1,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
		memcpy_s(m_screen_data.at(Changed_Item).description,STR_SCREEN_DESCRIPTION_LENGTH,cTemp1,STR_SCREEN_DESCRIPTION_LENGTH);
	}
	else if(Changed_SubItem == SCREEN_LABEL)
	{
		CString cs_temp = m_screen_list.GetItemText(Changed_Item,Changed_SubItem);
		if(cs_temp.GetLength()>= STR_SCREEN_LABLE_LENGTH)	//长度不能大于结构体定义的长度;
		{
			MessageBox(_T("Length can not higher than 8"),_T("Warning"));
			PostMessage(WM_REFRESH_BAC_SCREEN_LIST,NULL,NULL);
			return 0;
		}
		cs_temp.MakeUpper();
		if(Check_Label_Exsit(cs_temp))
		{
			PostMessage(WM_REFRESH_BAC_SCREEN_LIST,Changed_Item,REFRESH_ON_ITEM);
			return 0;
		}
		char cTemp1[255];
		memset(cTemp1,0,255);
		WideCharToMultiByte( CP_ACP, 0, cs_temp.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
		memcpy_s(m_screen_data.at(Changed_Item).label,STR_SCREEN_LABLE_LENGTH,cTemp1,STR_SCREEN_LABLE_LENGTH);
	}
	else if(Changed_SubItem == SCREEN_PIC_FILE)
	{
		//CString cs_temp = m_screen_list.GetItemText(Changed_Item,Changed_SubItem);
		//CFileFind temp_find;
		//bool find_full_name = false;
		//bool find_relatice_path = false;
		//find_full_name = temp_find.FindFile(cs_temp);
		//if(find_full_name)
		//{

		//}
		//else
		//{
		//	CString folder_temp_file;
		//	folder_temp_file = g_strBuildingFolder + _T("\\image\\") + cs_temp;
		//	CFileFind find_relatice_file;
		//	find_relatice_path = find_relatice_file.FindFile(folder_temp_file);
		//	if(find_relatice_path == false)
		//	{
		//		MessageBox(_T("Please input an valid path or double click to select file."));
		//		m_screen_list.SetItemText(Changed_Item,Changed_SubItem,_T(""));
		//		return 0;
		//	}
		//}
	}
	else if (Changed_SubItem == SCREEN_ELEMENT_COUNT)
	{
		int temp_value;
		if((New_CString.GetLength()>=4) || (_wtoi(New_CString)>255))
		{
			MessageBox(_T("Please input a value between 0 - 255"),_T("Warning"),MB_OK | MB_ICONINFORMATION);
			PostMessage(WM_REFRESH_BAC_SCREEN_LIST,NULL,NULL);//restore the list.
			return 0;
		}
		temp_value = _wtoi(New_CString);
		m_screen_data.at(Changed_Item).update = temp_value;
	}
	int cmp_ret = memcmp(&m_temp_screen_data[Changed_Item],&m_screen_data.at(Changed_Item),sizeof(Control_group_point));
	if(cmp_ret!=0)
	{
		m_screen_list.SetItemBkColor(Changed_Item,Changed_SubItem,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Screen List Item%d .Changed to \"%s\" "),Changed_Item + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITESCREEN_T3000,Changed_Item,Changed_Item,sizeof(Control_group_point),m_screen_dlg_hwnd ,temp_task_info,Changed_Item,Changed_SubItem);

	}


	
	return 0;
}
void BacnetScreen::OnNMDblclkListScreen(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	
	int device_obj_instance = g_bac_instance;
	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_screen_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_screen_list.SubItemHitTest(&lvinfo);
	if(nItem!=-1)
	{ 
		m_screen_list.SetCellChecked(nItem,0,1);
		screen_list_line = nItem;
		for (int i=0;i<m_screen_list.GetItemCount();++i)
		{
			if(i == nItem)
				continue;
			m_screen_list.SetCellChecked(i,0,FALSE);
		}
	}
	int lRow = 0;
	int lCol = 0;
	lRow = lvinfo.iItem;
	lCol = lvinfo.iSubItem;


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

	if(lCol == SCREEN_PIC_FILE)
	{
		TRACE(_T("Double"));
		CString FilePath;
		CString image_fordor;
		CString ApplicationFolder;
		GetModuleFileName(NULL, ApplicationFolder.GetBuffer(MAX_PATH), MAX_PATH);
		PathRemoveFileSpec(ApplicationFolder.GetBuffer(MAX_PATH));
		ApplicationFolder.ReleaseBuffer();
		//image_fordor = ApplicationFolder + _T("\\Database\\image");
		CMainFrame* pFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
		CString temp_now_building_name= g_strCurBuildingDatabasefilePath;
		PathRemoveFileSpec(temp_now_building_name.GetBuffer(MAX_PATH));
		temp_now_building_name.ReleaseBuffer();
		image_fordor = temp_now_building_name  + _T("\\image");
		
		WIN32_FIND_DATA fd;
		BOOL ret = FALSE;
		HANDLE hFind = FindFirstFile(image_fordor, &fd);
		if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
		{
			//目录存在
			ret = TRUE;
		}
		else
		{
			SECURITY_ATTRIBUTES attrib;
			attrib.bInheritHandle = FALSE;
			attrib.lpSecurityDescriptor = NULL;
			attrib.nLength = sizeof(SECURITY_ATTRIBUTES);

			CreateDirectory( image_fordor, &attrib);
		}



		SetCurrentDirectoryW(image_fordor);
		//选择图片,如果选的不在database目录下就copy一份过来;如果在的话就重命名,因为文件名长度不能超过10个字节;
		CString strFilter = _T("jpg file;bmp file;png file|*.jpg;*.bmp;*.png|all File|*.*||");
		CFileDialog dlg(true,_T("bmp"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,strFilter);
		if(IDOK==dlg.DoModal())
		{
			FilePath=dlg.GetPathName();
			CString FileName;
			GetFileNameFromPath(FilePath,FileName);
			
			CString temp1;
			temp1 = FilePath;
			PathRemoveFileSpec(temp1.GetBuffer(MAX_PATH));
			temp1.ReleaseBuffer();

			//The next part of code change file name length larger than 11 and rename it  move to image folder.
			// Eg : T3000Building.bmp  ->  T3000B.bmp
			CString extension_name;
			extension_name = PathFindExtension(FileName.GetBuffer());
			int extension_length = extension_name.GetLength();
			if(extension_length > 10)
				return;
			PathRemoveExtension(FileName.GetBuffer(MAX_PATH));
			FileName.ReleaseBuffer();
			if(FileName.GetLength() >=11 - extension_length)
			{
				FileName = FileName.Left(10 - extension_length);
				FileName = FileName + extension_name;
			}
			CString new_file_path;
			new_file_path = image_fordor + _T("\\") + FileName;
			Change_File_Path = new_file_path;
			if(temp1.CompareNoCase(image_fordor) != 0)//如果就在当前目录就不用copy过来了;
			{
				CopyFile(FilePath,new_file_path,false);
			}
			else
			{
				CFile::Rename(FilePath, new_file_path);
			}
			memcpy_s(&m_temp_screen_data[lRow],sizeof(Control_group_point),&m_screen_data.at(lRow),sizeof(Control_group_point));

			char cTemp1[255];
			memset(cTemp1,0,255);
			WideCharToMultiByte( CP_ACP, 0, FileName.GetBuffer(), -1, cTemp1, 255, NULL, NULL );
			memcpy_s(m_screen_data.at(lRow).picture_file,STR_SCREEN_PIC_FILE_LENGTH,cTemp1,STR_SCREEN_PIC_FILE_LENGTH);

			m_screen_list.SetItemText(lRow,SCREEN_PIC_FILE,FileName);
			New_CString = FileName;
			pic_filename = FileName;

			//if(h_write_pic_thread==NULL)
			//{
			//	if(Device_Basic_Setting.reg.sd_exist)
			//		h_write_pic_thread =CreateThread(NULL,NULL,WritePictureThread,this,NULL, NULL);
			//}

		}
	}
	else
	{
		for (int i=0;i<m_screen_list.GetItemCount();++i)
		{
			if(m_screen_list.GetCellChecked(i,0))
			{
				screen_list_line = i;
				break;
			}
		}

		//if(h_get_pic_thread==NULL)
		//{
		//	if(Device_Basic_Setting.reg.sd_exist)
		//		h_get_pic_thread =CreateThread(NULL,NULL,GetPictureThread,this,NULL, NULL);
		//}

		if(h_read_screenlabel_thread==NULL)
		{
			h_read_screenlabel_thread =CreateThread(NULL,NULL,ReadScreenThreadfun,this,NULL, NULL);
		}
		*pResult = 0;
		return;
	}

	//m_screen_list.Set_Edit(false);

	int cmp_ret = memcmp(&m_temp_screen_data[lRow],&m_screen_data.at(lRow),sizeof(Control_group_point));
	if(cmp_ret!=0)
	{
		m_screen_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Screen List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITESCREEN_T3000,lRow,lRow,sizeof(Control_group_point),m_screen_dlg_hwnd ,temp_task_info,lRow,lCol);

	}


	*pResult = 0;
}
Exemple #23
-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;
}