示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            chart1.Visible = true;
            var startTicks = dateTimePicker1.Value.Date.Ticks;
            var endTicks   = dateTimePicker2.Value.Date.AddDays(1).Ticks;

            var eventList = MongoRepositoryOrgEvent.GetByDate(startTicks, endTicks, new List <EventType>
            {
                EventType.DISASSEMBLY,
                EventType.INSTALL,
                EventType.REVISION,
                EventType.VERIFICATION
            });

            var implementers = MongoRepositoryImplementers.GetAll();

            chart1.Series.Clear();
            chart1.Series.Add(new Series(""));
            chart1.Series[0].ChartType = SeriesChartType.Pie;

            foreach (var imp in implementers)
            {
                var count = eventList.Count(c => c.ImplementerId == imp.Id);
                var perc  = eventList.Count != 0 ? decimal.Round((decimal)count / (decimal)eventList.Count * 100, 2) : 0;
                chart1.Series[0].Points.AddXY(imp.Name + " (" + perc + "%)", count);
            }
        }
示例#2
0
        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;
        }
示例#3
0
        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();
        }
示例#4
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            var startTicks = dateTimePicker11.Value.Date.Ticks;
            var endTicks   = dateTimePicker12.Value.Date.AddDays(1).Ticks;
            var events     = MongoRepositoryOrgEvent.GetByDate(startTicks, endTicks, new List <EventType> {
                EventType.VERIFICATION, EventType.INSTALL, EventType.REVISION, EventType.DISASSEMBLY
            });

            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_period.xls"), 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            _Worksheet xlWorksheet = (_Worksheet)xlWorkBook.Sheets[1];

            var startRow = 8;

            var counterTypeDic = events.GroupBy(g => g.CounterType).ToDictionary(d => d.Key);
            var eventTypeDic   = events.GroupBy(g => g.EventType).ToDictionary(d => d.Key);

            xlWorksheet.Cells[4, 2] = dateTimePicker11.Value.Date.ToString("D");
            xlWorksheet.Cells[4, 5] = dateTimePicker12.Value.Date.Date.ToString("D");

            foreach (var ect in counterTypeDic)
            {
                var val = ect.Value;
                xlWorksheet.Cells[startRow, 2] = val.Count(w => w.EventType == EventType.VERIFICATION);
                xlWorksheet.Cells[startRow, 3] = val.Count(w => w.EventType == EventType.REVISION);
                xlWorksheet.Cells[startRow, 4] = val.Count(w => w.EventType == EventType.INSTALL);
                xlWorksheet.Cells[startRow, 5] = val.Count(w => w.EventType == EventType.DISASSEMBLY);
                xlWorksheet.Cells[startRow, 6] = val.Count();
                startRow++;
            }

            xlWorksheet.Cells[11, 2] = eventTypeDic[EventType.VERIFICATION].Count();
            xlWorksheet.Cells[11, 3] = eventTypeDic[EventType.REVISION].Count();
            xlWorksheet.Cells[11, 4] = eventTypeDic[EventType.INSTALL].Count();
            xlWorksheet.Cells[11, 5] = eventTypeDic[EventType.DISASSEMBLY].Count();



            xlApp.Visible = true;
        }
示例#5
0
        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();
        }
示例#6
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            var startDate = dateTimePicker_start.Value.Date.Ticks;
            var endDate = dateTimePicker_end.Value.Date.AddDays(1).Ticks;

            var counterTypeList = new List<CounterType>();
            if (comboBox1.SelectedIndex == 0)
            {
                counterTypeList.Add(CounterType.COLD);
                counterTypeList.Add(CounterType.HOT);
            }
            else
            {
                counterTypeList.Add(CounterType.ELECTRO);
            }

            var events = MongoRepositoryOrgEvent.GetByDate(startDate, endDate,
                new List<EventType> {EventType.VERIFICATION}, counterTypeList);


            object fileName = Path.Combine(Application.StartupPath, "Templates\\template_verification_register.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;

            
            if (comboBox1.SelectedIndex == 0)
            {
                var dd = events.GroupBy(g => new {g.AddressId, g.Place}).ToDictionary(d => d.Key.AddressId);

                for (int i = 0; i < 8; i++)
                {
                    aDoc.Tables[1].Columns.Add(ref missing);
                }

                aDoc.Tables[1].Rows[1].Range.Bold = 1;
                aDoc.Tables[1].Rows[1].Cells[1].Range.Text = "№ п/п";
                aDoc.Tables[1].Rows[1].Cells[2].Range.Text = "Адрес";
                aDoc.Tables[1].Rows[1].Cells[3].Range.Text = "Дата поверки";
                aDoc.Tables[1].Rows[1].Cells[4].Range.Text = "ХВС № заводск.";
                aDoc.Tables[1].Rows[1].Cells[5].Range.Text = "показания";
                aDoc.Tables[1].Rows[1].Cells[6].Range.Text = "Дата след.гос.поверки";
                aDoc.Tables[1].Rows[1].Cells[7].Range.Text = "ГВС № заводск.";
                aDoc.Tables[1].Rows[1].Cells[8].Range.Text = "показания";
                aDoc.Tables[1].Rows[1].Cells[9].Range.Text = "Дата след.гос.поверки";




                foreach (var rec in dd)
                {
                    var cold = rec.Value.FirstOrDefault(w => w.CounterType == CounterType.COLD);
                    var hot = rec.Value.FirstOrDefault(w => w.CounterType == CounterType.HOT);

                    var i = 1;
                    aDoc.Tables[1].Rows.Add(ref missing);
                    aDoc.Tables[1].Rows[i + 1].Range.Bold = 0;
                    aDoc.Tables[1].Rows[i + 1].Range.Font.Size = 10;
                    aDoc.Tables[1].Rows[i + 1].Cells[1].Range.Text = i.ToString();
                    aDoc.Tables[1].Rows[i + 1].Cells[2].Range.Text = "LEL";
                    aDoc.Tables[1].Rows[i + 1].Cells[3].Range.Text = new DateTime(cold.DateTime).ToString("D"); 
                    aDoc.Tables[1].Rows[i + 1].Cells[4].Range.Text = cold.Place;
                    aDoc.Tables[1].Rows[i + 1].Cells[5].Range.Text = cold.Count.ToString();
                    aDoc.Tables[1].Rows[i + 1].Cells[6].Range.Text = new DateTime(cold.DateTime).AddYears(4).ToString("D");
                    aDoc.Tables[1].Rows[i + 1].Cells[7].Range.Text = hot?.Place;
                    aDoc.Tables[1].Rows[i + 1].Cells[8].Range.Text = hot?.Count.ToString();
                    aDoc.Tables[1].Rows[i + 1].Cells[9].Range.Text = hot == null ? null : new DateTime(hot.DateTime).AddYears(4).ToString("D");
                }




                //for (int i = 0; i < dissasemblyList.Count; i++)
                //{
                //      aDoc.Tables[1].Rows.Add(ref missing);
                //    aDoc.Tables[1].Rows[i + 2].Range.Bold = 0;
                //    aDoc.Tables[1].Rows[i + 2].Range.Font.Size = 10;
                //    aDoc.Tables[1].Rows[i + 2].Cells[1].Range.Text = (i + 1).ToString();
                //    aDoc.Tables[1].Rows[i + 2].Cells[2].Range.Text = dissasemblyList[i].Date;
                //    aDoc.Tables[1].Rows[i + 2].Cells[3].Range.Text = dissasemblyList[i].Address;
                //    aDoc.Tables[1].Rows[i + 2].Cells[4].Range.Text = dissasemblyList[i].CountDisassembly.ToString();
                //    aDoc.Tables[1].Rows[i + 2].Cells[5].Range.Text = dissasemblyList[i].CountInstall.ToString();
                //}
            }
            else
            {
                
            }


            Close();
        }