Exemplo n.º 1
0
void NoteEditScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
       QPointF mousePoint;
       mousePoint = event->scenePos();
       m_clickPoint = mousePoint;

       if(currentMode == MOVE
        ||currentMode == LONGNOTE)
       {
           QGraphicsItem *gItem = itemAt(mousePoint.x(), mousePoint.y(), QTransform());

           if(gItem != nullptr && gItem->type() == Note::Type)
           {
               //もしもオブジェクトをつかんだら
               QGraphicsView *view = this->views().at(0);
               view->setDragMode(QGraphicsView::DragMode::NoDrag);

               _grabItem = gItem;
               return;
           }
       }
       else if(currentMode == ERASE)
       {
           QGraphicsItem *gItem = itemAt(mousePoint.x(), mousePoint.y(), QTransform());
           if(gItem != nullptr && gItem->type() == Note::Type)
           {
               noteList.removeOne(dynamic_cast<Note*>(gItem));
               removeItem(gItem);
           }
       }
       else
       {
           qreal widthRatio  = Note::NOTE_WIDTH;
           qreal heightRatio = Note::NOTE_HEIGHT;
           auto note = new Note(QRect(0,0, widthRatio, heightRatio));
           //QRectF rect = this->sceneRect();
           int px = static_cast<int>(mousePoint.x() / widthRatio) * widthRatio;
           int py = static_cast<int>(mousePoint.y() / heightRatio) * heightRatio;
           note->setPos(px, py);
           addItem(note);

           note->calculateInfo(bpm);
           noteList.append(note);

           qDebug("X: %lf, Y: %lf", mousePoint.x(), mousePoint.y());
       }
      return;
}
Exemplo n.º 2
0
void __fastcall TMyThread::Execute()
{
		//disable home button
		Form3->homeImageButton5->Enabled=false;
		//yes selected, save information in grid to database

		//create empty strings to add to query once populated from grid
		String headings = "";
		String values = "";
		String update = "";
		String updateHeading = "";

		//get day of week
		int Day = DayOfWeek(Form3->pureDate);
		String DayName;
		switch(Day)
		{
		case 1:
			DayName = L"Sunday";
			break;
		case 2:
			DayName = L"Monday";
			break;
		case 3:
			DayName = L"Tuesday";
			break;
		case 4:
			DayName = L"Wednesday";
			break;
		case 5:
			DayName = L"Thursday";
			break;
		case 6:
			DayName = L"Friday";
			break;
		case 7:
			DayName = L"Saturday";
		}

		//populate date and day of week (probably temporary solution)
		headings += ("Date, Day_Of_Week, ");
		values += ("'" + Form3->dateChosen + "', '" + DayName + "', ");

		//construct headings and values for an update query instead of insert query
		if (Form3->alreadyThere)
		{
			//populate strings only from the grid
			for (int i = 0; i < Form3->displayGrid->RowCount; ++i)
			{
				updateHeading = StringReplace(Form3->displayGrid->Cells[0][i], " ", "_", TReplaceFlags() << rfReplaceAll);

				if (i + 1 == Form3->displayGrid->RowCount)
				{
					update += (updateHeading + " = '" + Form3->displayGrid->Cells[1][i] + "'");
				}
				else
				{
					update += (updateHeading + " = '" + Form3->displayGrid->Cells[1][i] + "', ");
				}
			}
		}
		//check if basic input was used, if so populate headings/values from inputObject
		else if (Form1->getInputLevel() == 0)
		{
			//populate rest of strings from grid
			for (int i = 0; i < Form3->inputObject.size; ++i)
			{
				if (i + 1 == Form3->inputObject.size)
				{
					headings += ("" + Form3->inputObject.valueMap[i][0] + "");
					values += ("'" + Form3->displayGrid->Cells[1][i] + "'");
				}
				else
				{
					headings += ("" + Form3->inputObject.valueMap[i][0] + ", ");
					values += ("'" + Form3->displayGrid->Cells[1][i] + "', ");
				}
			}
		}
		//if inputLevel is not basic, get both headings and values from the grid
		else
		{
			//populate strings only from the grid (might not be "minus 1")
			for (int i = 0; i < Form3->displayGrid->RowCount; ++i)
			{
				if (i + 1 == Form3->displayGrid->RowCount)
				{
					headings += ("" + StringReplace(Form3->displayGrid->Cells[0][i], " ", "_", TReplaceFlags() << rfReplaceAll) + "");
					values += ("'" + Form3->displayGrid->Cells[1][i] + "'");
				}
				else
				{
					headings += ("" + StringReplace(Form3->displayGrid->Cells[0][i], " ", "_", TReplaceFlags() << rfReplaceAll) + ", ");
					values += ("'" + Form3->displayGrid->Cells[1][i] + "', ");
				}
			}
		}

		//run update query if item already in database
		if (Form3->alreadyThere)
		{
			//update the raw_input table
			Form3->SQLQuery2->SQL->Text = "UPDATE baldwins_hotel_data."+Form3->inputTable+" SET "+update+" WHERE "+Form3->inputTable+".Date = '"+Form3->dateChosen+"';";
			Form3->SQLQuery2->ExecSQL();

			//update the read_data table
			Form3->SQLQuery2->SQL->Text = "UPDATE baldwins_hotel_data."+Form3->readTable+" SET "+update+" WHERE "+Form3->readTable+".Date = '"+Form3->dateChosen+"';";
			Form3->SQLQuery2->ExecSQL();
		}
		//if item not there, then run the normal insert query
		else
		{
			//query input_table db and insert new row
			Form3->SQLQuery2->SQL->Text = "INSERT INTO baldwins_hotel_data."+Form3->inputTable+" ("+headings+") VALUES ("+values+");";
			Form3->SQLQuery2->ExecSQL();

			//query read_table db and insert new row
			Form3->SQLQuery2->SQL->Text = "INSERT INTO baldwins_hotel_data."+Form3->readTable+" ("+headings+") VALUES ("+values+");";
			Form3->SQLQuery2->ExecSQL();
		}

		//Calculate and update values for Standard_Hours and Percent_Performance
		//first, query role_table to get all the Role_Name, Bare_Role_Name and Standard_Hours_Reference
		String currentHotelID = Form1->getHotelID();
		vector<calculateInfo> infoVector;
		String roleName = "";
		String roleStandardHoursName = "";
		String bareRoleName = "";
		String standardHoursReference = "";
		int context = 0;
		double actual = 0;
		double labor = 0;
		double roleWages = 0;
		double totalLaborHoursHoursPaid = 0;
		double totalLaborHoursStandardHours = 0;
		double totalLaborHoursPercentPerformance = 0;
		double totalLaborCostHoursPaid = 0;
		double totalLaborCostStandardHours = 0;
		double totalLaborCostPercentPerformance = 0;
		Form3->SQLQuery2->SQL->Text = "SELECT Role_Name, Bare_Role_Name, Standard_Hours_Reference, Role_Wages FROM baldwins_hotel_data.role_table WHERE hotelID = '"+currentHotelID+"';";
		Form3->SQLQuery2->Open();
		Form3->SQLQuery2->First();
		while (!Form3->SQLQuery2->Eof)
		{
			//fill strings
			roleName = Form3->SQLQuery2->Fields->Fields[0]->AsString;
			roleStandardHoursName = StringReplace(roleName, "Hours_Paid", "Standard_Hours", TReplaceFlags() << rfReplaceAll);
			bareRoleName = Form3->SQLQuery2->Fields->Fields[1]->AsString;
			standardHoursReference = Form3->SQLQuery2->Fields->Fields[2]->AsString;
			roleWages = Form3->SQLQuery2->Fields->Fields[3]->AsFloat;

			//get the integer value based on above strings
			Form3->SQLQuery3->SQL->Text = "SELECT "+roleName+", "+standardHoursReference+" FROM baldwins_hotel_data."+Form3->readTable+" WHERE Date = '"+Form3->dateChosen+"';";
			Form3->SQLQuery3->Open();
			Form3->SQLQuery3->First();
			if (!Form3->SQLQuery3->Eof)
			{
				//get values for normal use in this while loop
				actual = Form3->SQLQuery3->Fields->Fields[0]->AsFloat;
				context = Form3->SQLQuery3->Fields->Fields[1]->AsInteger;
			}

			//get the labor value for standard hours
			Form3->SQLQuery3->SQL->Text = "SELECT "+bareRoleName+" FROM baldwins_hotel_data."+Form3->laborTable+" WHERE "+context+" >= Rooms_Occupied_Low AND "+context+" <= Rooms_Occupied_High;";
			Form3->SQLQuery3->Open();
			Form3->SQLQuery3->First();
			if (!Form3->SQLQuery3->Eof)
			{
				labor = Form3->SQLQuery3->Fields->Fields[0]->AsFloat;
			}

			//push_back calculateInfo object
			infoVector.push_back(calculateInfo(roleName, roleStandardHoursName, bareRoleName, standardHoursReference, context, actual, labor));

			//compute values used below this while loop in actual update query
			totalLaborHoursHoursPaid += actual;
			totalLaborHoursStandardHours += labor;
			totalLaborCostHoursPaid = totalLaborCostHoursPaid + (actual * roleWages);
			totalLaborCostStandardHours = totalLaborCostStandardHours + (labor * roleWages);

			//reset strings and doubles to empty for next iteration
			roleName = "";
			roleStandardHoursName = "";
			bareRoleName = "";
			standardHoursReference = "";
			actual = 0;
			context = 0;
			labor = 0;
			roleWages = 0;
			/*totalLaborHoursHoursPaid = 0;
			totalLaborHoursStandardHours = 0;
			totalLaborHoursPercentPerformance = 0;
			totalLaborCostHoursPaid = 0;
			totalLaborCostStandardHours = 0;
			totalLaborCostPercentPerformance = 0;*/

			//move cursor to next item
			Form3->SQLQuery2->Next();
		}

		//run update query that updates standard hours and percent performance
		updateHeading = "";
		String updateHeading2 = "";
		update = "";
		labor = 0;
		double percent = 0;
		for (int i = 0; i < infoVector.size(); ++i)
		{
			updateHeading = infoVector[i].roleStandardHours;
			updateHeading2 = StringReplace(updateHeading, "Standard_Hours", "Percent_Performance", TReplaceFlags() << rfReplaceAll);
			labor = infoVector[i].laborValue;
			percent = infoVector[i].percentPerformance;

			/*if (i + 1 == infoVector.size())
			{
				update += (updateHeading + " = '" + labor + "', " + updateHeading2 + " = '" + percent + "'");
			}*/
			//else
			//{
				update += (updateHeading + " = '" + labor + "', " + updateHeading2 + " = '" + percent + "', ");
			//}
		}

		//calculate/store overtime, total_labor_hours, total_labor_cost in read_data
		double overtimeHoursPaid = 0;
		double overtimeStandardHours = 0;
		double overtimePercentPerformance = 0;
		Form3->SQLQuery3->SQL->Text = "SELECT Overtime_Hours_Paid FROM baldwins_hotel_data."+Form3->inputTable+" WHERE "+Form3->inputTable+".Date = '"+Form3->dateChosen+"';";
		Form3->SQLQuery3->Open();
		Form3->SQLQuery3->First();
		if (!Form3->SQLQuery3->Eof)
			overtimeHoursPaid = Form3->SQLQuery3->Fields->Fields[0]->AsFloat;
		overtimeStandardHours = Form3->overtimePerHour * overtimeHoursPaid;
		overtimePercentPerformance = overtimeStandardHours / 3;
		if (totalLaborHoursHoursPaid != 0)
			totalLaborHoursPercentPerformance = totalLaborHoursStandardHours / totalLaborHoursHoursPaid;
		else
			totalLaborHoursPercentPerformance = 0;
		if (totalLaborCostHoursPaid != 0)
			totalLaborCostPercentPerformance = totalLaborCostStandardHours / totalLaborCostHoursPaid;
		else
			totalLaborCostPercentPerformance = 0;
		totalLaborCostHoursPaid += overtimePercentPerformance;
		String spaceTaker = "";
		update += (spaceTaker + "Overtime_Hours_Paid = '" + overtimeHoursPaid + "', " + "Overtime_Standard_Hours = '" + overtimeStandardHours + "', " + "Overtime_Percent_Performance = '" + overtimePercentPerformance + "', ");
		update += (spaceTaker + "Total_Labor_Hours_Hours_Paid = '" + totalLaborHoursHoursPaid + "', " + "Total_Labor_Hours_Standard_Hours = '" + totalLaborHoursStandardHours + "', " + "Total_Labor_Hours_Percent_Performance = '" + totalLaborHoursPercentPerformance + "', ");
		update += (spaceTaker + "Total_Labor_Cost_Hours_Paid = '" + totalLaborCostHoursPaid + "', " + "Total_Labor_Cost_Standard_Hours = '" + totalLaborCostStandardHours + "', " + "Total_Labor_Cost_Percent_Performance = '" + totalLaborCostPercentPerformance + "'");
		Form3->SQLQuery2->SQL->Text = "UPDATE baldwins_hotel_data."+Form3->readTable+" SET "+update+" WHERE "+Form3->readTable+".Date = '"+Form3->dateChosen+"';";
		Form3->SQLQuery2->ExecSQL();
	}