void Deleteitem::deleteItem()
{
	Win::HourGlassCursor hgc(true);
	const int selectedIndex= lvItems.GetSelectedIndex();
	if(selectedIndex<0) return; //_____________________________Nothing is selected
	//_________________________________________________________Ask the user
	if(this->MessageBox(L"Are you sure you want to delete the selected item?", L"Delete item",
		MB_YESNO|MB_ICONQUESTION)!=IDYES) return;
	//________________________________________________________Delete;
	Sql::SqlConnection conn;
	wstring cmd;
	const int item_id= lvItems.Items[selectedIndex].Data; //Get the Primary Key; 
	int rows = 0;
	try
	{
		//conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase
		conn.OpenSession(hWnd, CONNECTION_STRING);
		Sys::Format(cmd, L"DELETE FROM item WHERE item_id= %d", item_id);
		rows = conn.ExecuteNonQuery(cmd);
		if (rows!=1)
		{
			this->MessageBox(Sys::Convert::ToString(rows), L"Error: number of deleted rows", MB_OK | MB_ICONERROR);
		}
	}
	catch (Sql::SqlException e)
	{
		this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR);
	}
	fillListView();
}
Exemplo n.º 2
0
void CoordDlg::btOK_Click(Win::Event& e)
{
    //_____________________________________________________________ Validate
    tr1::wregex regextbxUsername(L"[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]+");
    if (tr1::regex_match(tbxUsername.Text, regextbxUsername) == false)
    {
        tbxUsername.ShowBalloonTip(L"Invalid Username", L"Please provide four or more alphanumeric characters (A-Z, a-z or 0-9)", TTI_ERROR);
        return;
    }
    tr1::wregex regextbxPass(L"[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]+");
    if (tr1::regex_match(tbxPass.Text, regextbxPass) == false)
    {
        tbxPass.ShowBalloonTip(L"Invalid Pass", L"Please provide three or more alphanumeric characters (A-Z, a-z or 0-9)", TTI_ERROR);
        return;
    }
    Sql::StringBuilder sb(L"coordinator", L"coordinator_id", coordinator_id);
    sb.Bind(L"professor_id", ddProfessor);
    sb.Bind(L"program_id", ddProgram);
    sb.Bind(L"username", tbxUsername);
    sb.Bind(L"pass", tbxPass);
    sb.Bind(L"isAdmin", ckIsadmin);
    Sql::SqlConnection conn;
    int rows = 0;
    try
    {
        conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase
        //conn.OpenSession(hWnd, CONNECTION_STRING);
        rows = conn.ExecuteNonQuery(sb.GetString());
        if (rows!=1)
        {
            this->MessageBox(Sys::Convert::ToString(rows), L"Error: number of affected rows", MB_OK | MB_ICONERROR);
            return;
        }
    }
    catch (Sql::SqlException e)
    {
        this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR);
        return;
    }
    this->EndDialog(TRUE);
}
void TeethX::deleteItem()
{
	toolbMain.EnableButton(IDM_DELETE,false);
	Win::HourGlassCursor hgc(true);
	const int selectedIndex= lvMain.GetSelectedIndex();
	if(selectedIndex<0) return; //_____________________________Nothing is selected
	//_________________________________________________________Ask the user
	if(this->MessageBox(L"Are you sure you want to delete the selected item?", L"Delete item",
		MB_YESNO|MB_ICONQUESTION)!=IDYES) return;
	//________________________________________________________Delete;
	Sql::SqlConnection conn;
	wstring cmd;
	const int item_id= lvMain.Items[selectedIndex].Data; //Get the Primary Key; 
	int rows = 0;
	try
	{
		//conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase
		conn.OpenSession(hWnd, CONNECTION_STRING);
		if(tabSelection.SelectedData==0)
			{Sys::Format(cmd, L"DELETE FROM patient WHERE patient_id= %d", item_id);}
		else if(tabSelection.SelectedData==1)
			{Sys::Format(cmd, L"DELETE FROM transactionz WHERE transactionz_id= %d", item_id);}
		else if(tabSelection.SelectedData==2)
			Sys::Format(cmd, L"DELETE FROM transactionz WHERE transactionz_id= %d", item_id);
		else if(tabSelection.SelectedData==3)
			{Sys::Format(cmd, L"DELETE FROM dental_procedure WHERE dental_procedure_id= %d", item_id);}
		else if(tabSelection.SelectedData==4)
			{Sys::Format(cmd, L"DELETE FROM userz WHERE userz_id= %d", item_id);}
		rows = conn.ExecuteNonQuery(cmd);
		if (rows!=1)
		{
			this->MessageBox(Sys::Convert::ToString(rows), L"ERROR: number of deleted rows", MB_OK | MB_ICONERROR);
		}
	}
	catch (Sql::SqlException ex)
	{
		this->MessageBox(ex.GetDescription(), L"ERROR", MB_OK | MB_ICONERROR);
	}
	fillListView();
}
void CategoryPage::btOk_Click(Web::HttpConnector& h)
{
	Sql::StringBuilder sb(L"category", L"category_id", category_id);
	sb.Bind(L"descr", tbxDescr);

	Sql::SqlConnection conn;
	int rows = 0;
	try
	{
		//conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase
		conn.OpenSession(NULL, CONNECTION_STRING);
		rows = conn.ExecuteNonQuery(sb.GetString());
		if (rows!=1)
		{
			this->MessageBox(Sys::Convert::ToString(rows), L"Error -number of rows", MB_OK | MB_ICONERROR);
		}
	}
	catch (Sql::SqlException e)
	{
		this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR);
	}
	h.NavigateTo(L"Index");
}
Exemplo n.º 5
0
void AddCourseUD::btAccept_Click(Win::Event& e)
{
	if(isEditing!=1)
	{
		int course_id=ddCourse.GetSelectedData();
		int professor_id=ddProfessor.GetSelectedData();
		int classroom_id=ddClassroom.GetSelectedData();
		int week_id=ddClassdays.GetSelectedIndex()+1;
		int classtime_id=ddClasstime.GetSelectedData();
		if(course_id>1 || professor_id>1 || classroom_id>1 || week_id >1 || classtime_id >1)
		{
			this->MessageBox(L"You haven't selected all the required data", L"Error", MB_OK | MB_ICONERROR);
			return;
		}
		wstring cmd;
		char group='A';
		Sql::SqlConnection conn;
		int no_groups;
		try
		{
			conn.OpenSession(DSN, USERNAME, PASSWORD);
			Sys::Format(cmd,L"SELECT COUNT(*) FROM schedule WHERE course_id=%d AND period_id=%d AND week_day_id BETWEEN 1 AND 2",course_id, current_period);
			no_groups=conn.GetInt(cmd);
			group+=no_groups;

			if(week_id==1)
			{
				Sys::Format(cmd, L"INSERT INTO schedule(period_id,professor_id,course_id,grupo,classroom_id,classtime_id,week_day_id)VALUES(%d,%d,%d,'%c',%d,%d,1)",current_period,professor_id,course_id,group, classroom_id,classtime_id);
				conn.ExecuteNonQuery(cmd);
				Sys::Format(cmd, L"INSERT INTO schedule(period_id,professor_id,course_id,grupo,classroom_id,classtime_id,week_day_id)VALUES(%d,%d,%d,'%c',%d,%d,3)",current_period,professor_id,course_id,group, classroom_id,classtime_id);
				conn.ExecuteNonQuery(cmd);
				Sys::Format(cmd, L"INSERT INTO schedule(period_id,professor_id,course_id,grupo,classroom_id,classtime_id,week_day_id)VALUES(%d,%d,%d,'%c',%d,%d,5)",current_period,professor_id,course_id,group, classroom_id,classtime_id);
				conn.ExecuteNonQuery(cmd);
			}
			else
			{
				Sys::Format(cmd, L"INSERT INTO schedule(period_id,professor_id,course_id,grupo,classroom_id,classtime_id,week_day_id)VALUES(%d,%d,%d,'%c',%d,%d,2)",current_period,professor_id,course_id,group, classroom_id,classtime_id);
				conn.ExecuteNonQuery(cmd);
				Sys::Format(cmd, L"INSERT INTO schedule(period_id,professor_id,course_id,grupo,classroom_id,classtime_id,week_day_id)VALUES(%d,%d,%d,'%c',%d,%d,4)",current_period,professor_id,course_id,group, classroom_id,classtime_id);
				conn.ExecuteNonQuery(cmd);
			}
			conn.CloseSession();
		}
		catch (Sql::SqlException e)
		{
			this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR);
		}
	}
	else
	{
		classroom_id=ddClassroom.GetSelectedData();
		classtime_id=ddClasstime.GetSelectedData();
		wstring cmd;
		int rows=0;
		Sql::SqlConnection conn;
		try
		{
			conn.OpenSession(DSN, USERNAME, PASSWORD);
			Sys::Format(cmd, L"SELECT COUNT(*) FROM schedule WHERE professor_id=%d AND classtime_id=%d",professor_id,classtime_id);
			rows=conn.GetInt(cmd);
			if(rows>0)
			{
				this->MessageBoxW(L"This Professor is already teaching at this hour", L"Error", MB_OK | MB_ICONERROR);
				return;
			}

			Sys::Format(cmd, L"SELECT COUNT(*) FROM schedule WHERE classroom_id=%d AND classtime_id=%d",classroom_id,classtime_id);
			rows=conn.GetInt(cmd);
			if(rows>0)
			{
				this->MessageBoxW(L"This CLassroom is already occupied", L"Error", MB_OK | MB_ICONERROR);
				return;
			}


			Sys::Format(cmd, L"SELECT isbase FROM professor WHERE professor_id=%d",professor_id);
			rows=conn.GetInt(cmd);
			if(rows==1 && classtime_id>=5)
			{
				this->MessageBoxW(L"This Professor is fulltime", L"Error", MB_OK | MB_ICONERROR);
				return;
			}

			Sys::Format(cmd, L"UPDATE schedule SET classroom_id=%d WHERE course_id=%d AND grupo='%c'",classroom_id,course_id,grupo);
			conn.ExecuteNonQuery(cmd);

			Sys::Format(cmd, L"UPDATE schedule SET classtime_id=%d WHERE course_id=%d AND grupo='%c'",classtime_id,course_id,grupo);
			conn.ExecuteNonQuery(cmd);

			conn.CloseSession();
		}
		catch (Sql::SqlException e)
		{
			this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR);
		}

	}
	this->EndDialog(TRUE);
}
void UserDlg::btOK_Click(Win::Event& e)
{
	//_____________________________________________________________ Validate
	tr1::wregex regextbxUsername(L"[A-Za-z0-9]+");
	if (tr1::regex_match(tbxUsername.Text, regextbxUsername) == false)
	{
		tbxUsername.ShowBalloonTip(L"Invalid Username", L"Please provide one or more characters", TTI_ERROR);
		return;
	}
	tr1::wregex regextbxFirst_name(L"[A-Za-z0-9]+");
	if (tr1::regex_match(tbxFirst_name.Text, regextbxFirst_name) == false)
	{
		tbxFirst_name.ShowBalloonTip(L"Invalid First name", L"Please provide one or more characters", TTI_ERROR);
		return;
	}
	tr1::wregex regextbxLast_name(L"[A-Za-z0-9]+");
	if (tr1::regex_match(tbxLast_name.Text, regextbxLast_name) == false)
	{
		tbxLast_name.ShowBalloonTip(L"Invalid Last name", L"Please provide one or more characters", TTI_ERROR);
		return;
	}
	tr1::wregex regextbxPasswordz(L"[A-Za-z0-9]+");
	if (tr1::regex_match(tbxPasswordz.Text, regextbxPasswordz) == false)
	{
		tbxPasswordz.ShowBalloonTip(L"Invalid Passwordz", L"Please provide one or more characters", TTI_ERROR);
		return;
	}
	tr1::wregex regextbxEmail(L".+@.+");
	if (tr1::regex_match(tbxEmail.Text, regextbxEmail) == false)
	{
		tbxEmail.ShowBalloonTip(L"Invalid Email", L"Please provide one or more characters", TTI_ERROR);
		return;
	}
	Sql::StringBuilder sb(L"userz", L"userz_id", userz_id);
	sb.Bind(L"username", tbxUsername);
	sb.Bind(L"first_name", tbxFirst_name);
	sb.Bind(L"last_name", tbxLast_name);
	sb.Bind(L"passwordz", tbxPasswordz);
	sb.Bind(L"email", tbxEmail);
	sb.Bind(L"is_active", ckIs_active);
	sb.Bind(L"has_access_patient_info", ckHas_access_patient_info);
	sb.Bind(L"has_access_users", ckHas_access_users);
	sb.Bind(L"has_access_payments", ckHas_access_payments);
	sb.Bind(L"has_access_patient_chart", ckHas_access_patient_chart);
	sb.Bind(L"has_access_dental_procedure_setup", ckHas_access_dental_procedure_setup);
	Sql::SqlConnection conn;
	int rows = 0;
	try
	{
		//conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase
		conn.OpenSession(hWnd, CONNECTION_STRING);
		rows = conn.ExecuteNonQuery(sb.GetString());
		if (rows!=1)
		{
			this->MessageBox(Sys::Convert::ToString(rows), L"Error: number of affected rows", MB_OK | MB_ICONERROR);
			return;
		}
	}
	catch (Sql::SqlException e)
	{
		this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR);
		return;
	}
	this->EndDialog(TRUE);
}