private void button_ok_Click(object sender, EventArgs e) { var address = MongoRepositoryAddresses.Get(textBox_street.Text, textBox_house.Text, textBox_building.Text, textBox_apartment.Text); if (address == null) { MessageBox.Show("Адрес не занесен в базу!"); return; } var orgEvent = new OrgEvent { Id = OrgEvent?.Id ?? Guid.NewGuid(), EventType = GetEventType(), CounterType = GetCounterType(), AddressId = address.Id, DateTime = dateTimePicker_date.Value.Ticks, ImplementerId = ((ComboBoxItem)comboBox_implementer.SelectedItem).HiddenValue, Place = string.IsNullOrEmpty(textBox_place.Text) ? null : textBox_place.Text, Count = Convert.ToDecimal(textBox_count.Text) }; MongoRepositoryOrgEvent.Upsert(orgEvent); Close(); }
private void button_search_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text)) { dataGridView1.Rows.Clear(); var addressList = MongoRepositoryAddresses.GetAll(); var userList = MongoRepositoryUsers.GetAll(); foreach (var address in addressList) { var user = userList.First(f => f.Id == address.UserId); dataGridView1.Rows.Add(address.Id, address.Street, address.House, address.Building, address.Apartment, user.Name); } } else { dataGridView1.Rows.Clear(); var addressList = MongoRepositoryAddresses.Search(textBox1.Text); var userList = MongoRepositoryUsers.GetAll(); foreach (var address in addressList) { var user = userList.First(f => f.Id == address.UserId); dataGridView1.Rows.Add(address.Id, address.Street, address.House, address.Building, address.Apartment, user.Name); } } }
private void button2_Click(object sender, EventArgs e) { var startTicks = dateTimePicker21.Value.Date.Ticks; var endTicks = dateTimePicker22.Value.Date.AddDays(1).Ticks; var eventList = MongoRepositoryOrgEvent.GetByDate(startTicks, endTicks, new List <EventType> { EventType.DISASSEMBLY, EventType.INSTALL, EventType.REVISION, EventType.VERIFICATION }); var userList = MongoRepositoryUsers.GetAll(); var addressIdList = eventList.Select(s => s.AddressId).Distinct().ToList(); var addressList = MongoRepositoryAddresses.GetMany(addressIdList); foreach (var orgEvent in eventList) { orgEvent.AddressId = addressList.First(f => f.Id == orgEvent.AddressId).UserId; } Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Workbook xlWorkBook = xlApp.Workbooks.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates\\template_report_events_controller.xls"), 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); _Worksheet xlWorksheet = (_Worksheet)xlWorkBook.Sheets[1]; xlWorksheet.Cells[4, 2] = dateTimePicker21.Value.Date.ToString("D"); xlWorksheet.Cells[4, 5] = dateTimePicker22.Value.Date.ToString("D"); var startRow = 7; var grouped = eventList.GroupBy(g => g.AddressId).ToDictionary(d => d.Key); foreach (var keyValue in grouped) { var val = keyValue.Value; var userName = userList.First(f => f.Id == keyValue.Key).Name; xlWorksheet.Cells[startRow, 1] = userName; xlWorksheet.Cells[startRow, 2] = val.Count(w => w.EventType == EventType.INSTALL); xlWorksheet.Cells[startRow, 3] = val.Count(w => w.EventType == EventType.VERIFICATION); xlWorksheet.Cells[startRow, 4] = val.Count(w => w.EventType == EventType.REVISION); xlWorksheet.Cells[startRow, 5] = val.Count(w => w.EventType == EventType.DISASSEMBLY); var startCell = xlWorksheet.Cells[startRow, 1]; var endCell = xlWorksheet.Cells[startRow, 5]; var range = xlWorksheet.Range[startCell, endCell]; range.Style.HorizontalAlignment = XlHAlign.xlHAlignCenter; range.Style.VerticalAlignment = XlVAlign.xlVAlignCenter; range.Borders.LineStyle = XlLineStyle.xlContinuous; var start = xlWorksheet.Cells[startRow, 1]; var end = xlWorksheet.Cells[startRow, 1]; xlWorksheet.Range[start, end].Font.Bold = true; xlWorksheet.Range[start, end].Borders.Weight = XlBorderWeight.xlMedium; startRow++; } xlApp.Visible = true; }
private void button_ok_Click(object sender, EventArgs e) { //var startDate = dateTimePicker1.Value.DateTime; //var endDate = dateTimePicker2.Value.DateTime; var startTicks = dateTimePicker1.Value.Date.Ticks; var endTicks = dateTimePicker2.Value.Date.AddDays(1).Ticks; var events = MongoRepositoryOrgEvent.GetByDate(startTicks, endTicks, new List <EventType> { EventType.DISASSEMBLY, EventType.INSTALL }); var addressIdList = events.Select(s => s.AddressId).Distinct().ToList(); var addressList = MongoRepositoryAddresses.Get(addressIdList); var disassemblyEventList = events.Where(w => w.EventType == EventType.DISASSEMBLY).ToList(); var installEventList = events.Where(w => w.EventType == EventType.INSTALL).ToList(); var result = new List <Disassembly>(); foreach (var dis in disassemblyEventList) { var address = addressList.First(f => f.Id == dis.AddressId); var install = installEventList.First(w => w.AddressId == dis.AddressId && w.CounterType == dis.CounterType); var disassembly = new Disassembly { Date = dis.DateTime.ToString("dd.MM.yyyy"), Address = address.Street + " " + address.House + " " + address.Building + " " + address.Apartment, CountDisassembly = dis.Count, CountInstall = install.Count }; result.Add(disassembly); } /* var disList = new List<Disassembly>(); * disList.Add(new Disassembly * { * Date = "10.12.2017", * Address = "ул. Репина", * CountDisassembly = 202103, * CountInstall = 123 * }); * disList.Add(new Disassembly * { * Date = "10.12.2018", * Address = "ул. Филатова", * CountDisassembly = 25553, * CountInstall = 1 * }); */ Export(result); Close(); }
private void button_remove_Click(object sender, EventArgs e) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; var id = Guid.Parse(selectedRow.Cells["Id"].Value.ToString()); MongoRepositoryPeople.RemoveByAddressId(id); MongoRepositoryAddresses.Remove(id); dataGridView1.Rows.Remove(selectedRow); }
private void button_update_Click(object sender, EventArgs e) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; string a = selectedRow.Cells["Id"].Value.ToString(); var address = MongoRepositoryAddresses.Get(Guid.Parse(a)); var peopleList = MongoRepositoryPeople.GetByAddressId(Guid.Parse(a)); new AddressForm(address, peopleList).ShowDialog(); }
//private void MainForm_Load(object sender, EventArgs e) //{ // //DGVBind(); // //var bindingList = new BindingList<Implementer>(implementers); // //var source = new BindingSource(bindingList, null); // //dataGridView1.DataSource = source; //} private void MainForm_Activated(object sender, EventArgs e) { dataGridView1.Rows.Clear(); var eventList = MongoRepositoryOrgEvent.GetAll(); var addressList = MongoRepositoryAddresses.GetAll(); var implementers = MongoRepositoryImplementers.GetAll(); foreach (var orgEvent in eventList) { var address = addressList.First(w => w.Id == orgEvent.AddressId); var addressString = string.Join(", ", new List <string> { address.Street, address.House, address.Building, address.Apartment }); var implementer = implementers.First(a => a.Id == orgEvent.ImplementerId).Name; var counterType = String.Empty; switch (orgEvent.CounterType) { case Models.CounterType.COLD: counterType = "Холодная вода"; break; case Models.CounterType.HOT: counterType = "Горячая вода"; break; case Models.CounterType.ELECTRO: counterType = "Электрический"; break; } var eventType = string.Empty; switch (orgEvent.EventType) { case Models.EventType.INSTALL: eventType = "Установка"; break; case Models.EventType.REVISION: eventType = "Переустановка"; break; case Models.EventType.VERIFICATION: eventType = "Поверка"; break; case Models.EventType.DISASSEMBLY: eventType = "Демонтаж"; break; } dataGridView1.Rows.Add(orgEvent.Id, orgEvent.AddressId, addressString, counterType, orgEvent.Place, new DateTime(orgEvent.DateTime).ToString("D"), implementer, eventType); } }
private void AddressesForm_Activated(object sender, EventArgs e) { dataGridView1.Rows.Clear(); var addressList = MongoRepositoryAddresses.GetAll(); var userList = MongoRepositoryUsers.GetAll(); foreach (var address in addressList) { var user = userList.First(f => f.Id == address.UserId); dataGridView1.Rows.Add(address.Id, address.Street, address.House, address.Building, address.Apartment, user.Name); } }
private void button_update_Click(object sender, EventArgs e) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; string a = selectedRow.Cells["Id"].Value.ToString(); var orgEvent = MongoRepositoryOrgEvent.Get(Guid.Parse(a)); Address address = null; if (orgEvent != null) { address = MongoRepositoryAddresses.Get(orgEvent.AddressId); } new OrgEventForm(orgEvent, address).ShowDialog(); }
private void ControllersForm_Load(object sender, EventArgs e) { //var controllers = MongoRepositoryController.GetAll(); //foreach (var imp in controllers) //{ // dataGridView2.Rows.Add(imp.Id, imp.FIO); //} AddressList = MongoRepositoryAddresses.GetAll(); var streetList = AddressList.Select(s => s.Street).Distinct().ToList(); foreach (var street in streetList) { comboBox_street.Items.Add(street); } }
private void button_ok_Click(object sender, EventArgs e) { var address = new Address { Id = Address?.Id ?? Guid.NewGuid(), Street = textBox_street.Text, Building = textBox_biulding.Text, House = textBox_house.Text, Apartment = textBox_apartment.Text, UserId = ((ComboBoxItem)comboBox_users.SelectedItem).HiddenValue }; MongoRepositoryAddresses.Upsert(address); foreach (DataGridViewRow row in dataGridView1.Rows) { var id = row.Cells[0].Value?.ToString(); var lastName = row.Cells[1].Value?.ToString(); var firstName = row.Cells[2].Value?.ToString(); var surName = row.Cells[3].Value?.ToString(); var phone = row.Cells[4].Value?.ToString(); if (!string.IsNullOrEmpty(id) && string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName) && string.IsNullOrEmpty(surName) && string.IsNullOrEmpty(phone)) { MongoRepositoryPeople.Remove(Guid.Parse(id)); } if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName) || !string.IsNullOrEmpty(surName) || !string.IsNullOrEmpty(phone)) { var people = new People { Id = id == null?Guid.NewGuid() : Guid.Parse(id), FirstName = firstName, LastName = lastName, SurName = surName, Phone = phone, AddressId = address.Id }; MongoRepositoryPeople.Upsert(people); } } Close(); }
private void button_load_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox_path.Text)) { MessageBox.Show("Укажите путь к файлу!"); } var exist = File.Exists(textBox_path.Text); if (!exist) { MessageBox.Show("Файл не найден!"); } var addressList = MongoRepositoryAddresses.GetByUserId(((ComboBoxItem)comboBox1.SelectedItem).HiddenValue); verificList = MongoRepositoryOrgEvent.GetByAddressandType(addressList, EventType.VERIFICATION); progressBar1.Minimum = 0; var verificationList = Parse(addressList); Export_revision(verificationList, verificList); }
private void button_ok_Click(object sender, EventArgs e) { var startTicks = dateTimePicker_start.Value.Date.Ticks; var endTicks = dateTimePicker_end.Value.Date.AddDays(1).Ticks; var eventTypes = new List <EventType> { EventType.INSTALL }; var eventList = MongoRepositoryOrgEvent.GetByDate(startTicks, endTicks, eventTypes); var addressIdList = eventList.Select(s => s.AddressId).Distinct().ToList(); var addressList = MongoRepositoryAddresses.Get(addressIdList); object fileName = Path.Combine(Application.StartupPath, "Templates\\template_acceptance_acts.doc"); Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true }; Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(fileName, ReadOnly: false, Visible: true); aDoc.Activate(); FindAndReplace(wordApp, "{date}", DateTime.Today.ToString("D")); object missing = System.Reflection.Missing.Value; for (int i = 0; i < eventList.Count; i++) { var address = addressList.First(w => w.Id == eventList[i].AddressId); var counterType = string.Empty; switch (eventList[i].CounterType) { case CounterType.COLD: counterType = "ХВС"; break; case CounterType.HOT: counterType = "ГВС"; break; case CounterType.ELECTRO: counterType = "Электр."; break; } aDoc.Tables[1].Rows.Add(ref missing); aDoc.Tables[1].Rows[i + 4].Range.Bold = 0; aDoc.Tables[1].Rows[i + 4].Range.Font.Size = 10; aDoc.Tables[1].Rows[i + 4].Cells[1].Range.Text = address.Street; aDoc.Tables[1].Rows[i + 4].Cells[2].Range.Text = address.House; aDoc.Tables[1].Rows[i + 4].Cells[3].Range.Text = address.Apartment; aDoc.Tables[1].Rows[i + 4].Cells[4].Range.Text = new DateTime(eventList[i].DateTime).ToString("D"); aDoc.Tables[1].Rows[i + 4].Cells[5].Range.Text = counterType; aDoc.Tables[1].Rows[i + 4].Cells[6].Range.Text = eventList[i].Place; } Close(); }
private void Export_revision(List <Verification> verificationList, List <OrgEvent> verificList) { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Workbook xlWorkBook = xlApp.Workbooks.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates\\template_verification_list.xls"), 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); _Worksheet xlWorksheet = (_Worksheet)xlWorkBook.Sheets[1]; int startRow = 5; progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Maximum = verificationList.Count + verificList.Count; label_wait.Text = "Запись данных в файл..."; foreach (var verification in verificationList) { var start = startRow; var end = startRow + verification.Counters.Count - 1; var startCell = xlWorksheet.Cells[start, 1]; var endCell = xlWorksheet.Cells[end, 1]; var range = xlWorksheet.Range[startCell, endCell]; range.Merge(Type.Missing); range.Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; range.Style.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; range.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; range.BorderAround(); xlWorksheet.Cells[startRow, 1] = verification.Address; foreach (var counter in verification.Counters) { xlWorksheet.Cells[startRow, 2] = counter.Name; // xlWorksheet.Cells[startRow, 3] = counter.StartCount.Insert(counter.StartCount.Length - 3, ","); xlWorksheet.Cells[startRow, 3] = counter.StartCount.ToString(); xlWorksheet.Cells[startRow, 4] = counter.EndCount.ToString(); xlWorksheet.Cells[startRow, 5] = counter.StartDate; xlWorksheet.Cells[startRow, 6] = counter.EndDate; var rng = xlWorksheet.Range[xlWorksheet.Cells[startRow, 2], xlWorksheet.Cells[startRow, 6]]; rng.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; startRow++; } progressBar1.PerformStep(); } xlWorksheet = (_Worksheet)xlWorkBook.Sheets[2]; startRow = 5; foreach (var ver in verificList) { var start = startRow; var end = startRow + ver.Count; var startCell = xlWorksheet.Cells[start, 1]; var endCell = xlWorksheet.Cells[end, 1]; var range = xlWorksheet.Range[startCell, endCell]; range.Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; range.Style.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; //range.Borders.LineStyle = XlLineStyle.xlContinuous; (range.Cells as Microsoft.Office.Interop.Excel.Range).ColumnWidth = 50; //range.BorderAround(); var counterType = String.Empty; switch (ver.CounterType) { case Models.CounterType.COLD: counterType = "Холодная вода"; break; case Models.CounterType.HOT: counterType = "Горячая вода"; break; case Models.CounterType.ELECTRO: counterType = "Электрический"; break; } xlWorksheet.Cells[startRow, 1] = "ул. " + MongoRepositoryAddresses.Get(ver.AddressId).Street + ", дом " + MongoRepositoryAddresses.Get(ver.AddressId).House + ", кв. " + MongoRepositoryAddresses.Get(ver.AddressId).Apartment; xlWorksheet.Cells[startRow, 2] = counterType; xlWorksheet.Cells[startRow, 3] = new DateTime(ver.DateTime).ToShortDateString(); var rng = xlWorksheet.Range[xlWorksheet.Cells[startRow, 2], xlWorksheet.Cells[startRow, 3]]; rng.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; startRow++; progressBar1.PerformStep(); } label_wait.Text = "Документ построен."; xlApp.Visible = true; }