public Activity(string name, TypeActivity type, DateTime start, DateTime end, List <Member> members, int maxpart, int score) { Name = name; Type = type; StartDate = start; EndDate = end; IsFull = false; Members = members; ActivityMembers = new List <ActivityMember>(); foreach (var m in Members) { ActivityMember am = new ActivityMember(ActivityId, this, m.UserId, m); ActivityMembers.Add(am); } this.MaxParticpants = maxpart; this.Score = score; }
private void Button1_Click(object sender, EventArgs e) { button1.Enabled = false; TypeActivity activity = (TypeActivity)comboBox1.SelectedIndex; int value = Convert.ToInt32(numericUpDown1.Value); if (activity == TypeActivity.ReFuel) { value *= 1000; } carInfo.AddActivity(dateTimePicker1.Value, dateTimePicker2.Value, activity, value); richTextBox1.Text = carInfo.report; label6.Text = "Сейчас топлива " + (carInfo.fuel / 1000.0).ToString() + " л"; dateTimePicker1.Value = dateTimePicker2.Value; dateTimePicker2.Value = dateTimePicker2.Value.AddMinutes(5); dateTimePicker1.Enabled = false; button1.Enabled = true; }
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e) { TypeActivity activity = (TypeActivity)comboBox1.SelectedIndex; if (activity == TypeActivity.Stay) { numericUpDown1.Visible = false; label4.Visible = false; } else if (activity == TypeActivity.Ride) { numericUpDown1.Visible = true; label4.Visible = true; label4.Text = "Со скоростью (км/ч)"; } else if (activity == TypeActivity.ReFuel) { numericUpDown1.Visible = true; label4.Visible = true; label4.Text = "Объем топлива (л)"; } }
public bool AddActivity(DateTime timeStart, DateTime timeFinish, TypeActivity activity, int value) { string localReport = ""; BinaryWriter fileShort = new BinaryWriter(File.Open(puthShortReport, FileMode.Open), System.Text.Encoding.Default); StreamWriter fileFull = new StreamWriter(puthFullReport, true, System.Text.Encoding.Default); int ms = Convert.ToInt32((timeFinish - timeStart).Ticks / TimeSpan.TicksPerMillisecond); uint stepMs = 200; int startFuel = fuel; //Показание счетчика для отчета, с погрешностью int valueFuel = fuel; //id пакета данный int id = 0; // Расход топлива за данный промежуток времени (мл) double fuelConsumption = 0; if (activity == TypeActivity.Ride) { fuelConsumption = FuelConsumption(value, d); fuelConsumption *= 1.0 * ms / 3600000 * 1000; } //Проверка на переполнение топливного бака или досрочное окончание топлива if ((fuelConsumption > fuel && activity == TypeActivity.Ride) || activity == TypeActivity.ReFuel && fuel + value > maxFuel) { return(false); } timeNow = Convert.ToUInt32(((timeStart.Hour * 60 + timeStart.Minute) * 60 + timeStart.Second) * 1000 + timeStart.Millisecond); uint startTime = timeNow; BinaryReport binaryReport; for (uint i = stepMs; i <= ms; i += stepMs) { binaryReport = new BinaryReport(); timeNow = startTime + i; binaryReport.timestamp = timeNow; //Формирование пакета с id = 125: уровень топлива в баке id = 125; localReport = ToHex(id, 4) + "\t"; binaryReport.id = Convert.ToUInt32(id); if (activity == TypeActivity.ReFuel) { fuel = startFuel + Convert.ToInt32(Math.Truncate(1.0 * value / ms * i)); //Показание счетчика для отчета, с погрешностью valueFuel = NoizeFuel(NoizeReFuel); } else if (activity == TypeActivity.Ride) { fuel = startFuel - Convert.ToInt32(Math.Truncate(fuelConsumption / ms * i)); //Показание счетчика для отчета, с погрешностью valueFuel = NoizeFuel(NoizeRide); } else if (activity == TypeActivity.Stay) { //Показание счетчика для отчета, с погрешностью valueFuel = NoizeFuel(NoizeStay); } const byte leng = 8; binaryReport.vallen = leng; binaryReport.val = new byte[leng]; random.NextBytes(binaryReport.val); binaryReport.val[5] = FuelInPercentage(valueFuel); for (int j = 0; j < leng; j++) { localReport += ToHex(binaryReport.val[j], 2); } localReport += "\t" + (timeStart.AddMilliseconds(i)).ToString(); localReport += "\t" + id.ToString() + "\t" + (1.0 * FuelInPercentage(valueFuel) / 2).ToString() + " %"; localReport += "\t\t" + (1.0 * fuel / 1000).ToString() + " л"; localReport += "\t" + (1.0 * FuelInPercentage(fuel) / 2).ToString() + " %"; localReport += "\n"; fileFull.Write(localReport); //ОТКЛЮЧИЛА ВЫВОД НА ЭКРАН //report += localReport; binaryReport.colorspec = 1; binaryReport.colors = new ushort[] { 0xfdfd, 0xfdfd, 0xfdfd, 0xfdfd, 0 }; WriteBinaryReport(fileShort, binaryReport); if (i % 500 == 0) { //рандомные пакеты каждые 30 мс binaryReport = new BinaryReport(); binaryReport.timestamp = timeNow; id = 77; localReport = ToHex(id, 4) + "\t"; binaryReport.id = Convert.ToUInt32(id); const byte len = 8; binaryReport.vallen = len; binaryReport.val = new byte[len]; random.NextBytes(binaryReport.val); for (int j = 0; j < len; j++) { localReport += ToHex(binaryReport.val[j], 2); } localReport += "\t" + (timeStart.AddMilliseconds(i)).ToString() + "\n"; fileFull.Write(localReport); //ОТКЛЮЧИЛА ВЫВОД НА ЭКРАН //report += localReport; binaryReport.colorspec = 1; binaryReport.colors = new ushort[] { 0xfdfd, 0xfdfd, 0xfdfd, 0xfdfd, 0 }; WriteBinaryReport(fileShort, binaryReport); } if (i % 1000 == 0) { //рандомные пакеты каждые 0,5 сек binaryReport = new BinaryReport(); binaryReport.timestamp = timeNow; id = 88; localReport = ToHex(id, 4) + "\t"; binaryReport.id = Convert.ToUInt32(id); const byte len = 6; binaryReport.vallen = len; binaryReport.val = new byte[len]; random.NextBytes(binaryReport.val); for (int j = 0; j < len; j++) { localReport += ToHex(binaryReport.val[j], 2); } localReport += "\t\t" + (timeStart.AddMilliseconds(i)).ToString() + "\n"; fileFull.Write(localReport); //ОТКЛЮЧИЛА ВЫВОД НА ЭКРАН //report += localReport; binaryReport.colorspec = 1; binaryReport.colors = new ushort[] { 0xfdfd, 0xfdfd, 0xfdfd, 0xfdfd, 0 }; WriteBinaryReport(fileShort, binaryReport); } if (i % 3000 == 0) { //рандомные пакеты каждую секунду binaryReport = new BinaryReport(); binaryReport.timestamp = timeNow; id = 99; localReport = ToHex(id, 4) + "\t"; binaryReport.id = Convert.ToUInt32(id); const byte len = 6; binaryReport.vallen = len; binaryReport.val = new byte[len]; random.NextBytes(binaryReport.val); for (int j = 0; j < len; j++) { localReport += ToHex(binaryReport.val[j], 2); } localReport += "\t\t" + (timeStart.AddMilliseconds(i)).ToString() + "\n"; fileFull.Write(localReport); //ОТКЛЮЧИЛА ВЫВОД НА ЭКРАН //report += localReport; binaryReport.colorspec = 1; binaryReport.colors = new ushort[] { 0xfdfd, 0xfdfd, 0xfdfd, 0xfdfd, 0 }; WriteBinaryReport(fileShort, binaryReport); } } fileFull.Close(); fileShort.Close(); return(true); }