Ejemplo n.º 1
0
        //hàm này mở file cell

        static TRAM OPenCELL(string a)
        {
            TRAM   tram = new TRAM();
            string file = a;
            string ext  = Path.GetExtension(file).ToString();

            if (ext == ".xlsx")
            {
                var excel    = new ExcelQueryFactory(file);
                var cellfile = from truongCellFile in excel.Worksheet <CELL>("Sheet1")
                               select truongCellFile;


                foreach (var item in cellfile)
                {
                    // string nameTram = item.tramName;


                    CELL cell1 = new CELL(item.tramName, item.tencell, item.lonCell, item.latCell, item.Azimut, item.uarfcn, item.psc);
                    tram.CellList.Add(cell1);
                    // Console.WriteLine("các trường cần in là: "+ item.tencell.ToString());
                }
            }
            else
            {
                MessageBox.Show("đang bị lỗi không mở được file  cell");
            }
            return(tram);
        }
Ejemplo n.º 2
0
        private void timCheoCell_Click(object sender, EventArgs e)
        {
            List <TRAM> tramList = new List <TRAM>();
            TRAM        tram     = new TRAM();
            CELL        cell     = new CELL();

            //  tram = OPenCELL(linkScan.Text.ToString());
            //   cell = OPenDIEM(linkCell.Text.ToString());
            tram = OPenCELL(linkCell.Text.ToString());
            cell = OPenDIEM(linkScan.Text.ToString());
            //  double d = double.Parse(KhoangCach.Text);


            double d = double.Parse(KhoangCach.Text);
            // double d;
            //if( !double.TryParse(KhoangCach.Text, out d))
            // { MessageBox.Show("nhập lại khoảng cách"); }



            double bw = double.Parse(bW.Text);

            //    double bw;

            //if (!double.TryParse(KhoangCach.Text, out bw))
            //{ MessageBox.Show("nhập lại búp  sóng"); }

            double diempv = double.Parse(diemPhucVu.Text);

            //double diempv;
            //if (!double.TryParse(KhoangCach.Text, out diempv))
            //{ MessageBox.Show("nhập lại điểm phục vụ"); }


            foreach (CELL itemCell in tram.CellList)     //đây là xét đến các cell trong danh sách cell
            {
                foreach (DIEM itemDiem in cell.DiemList) // xét đến các điểm trong danh sách điểm
                {
                    // câu này là tìm xem điểm nào có cùng psc và cùng uarfcn và cách trạm không quá 5km thì cho điểm đó vào danh sách các điểm cell đang phục vụ.
                    if ((itemCell.psc == itemDiem.psc) && (itemCell.uarfcn == itemDiem.uarfcn) && (distance(itemCell.latCell, itemDiem.lat, itemCell.lonCell, itemDiem.lon) < d))
                    {
                        itemCell.DiemList.Add(itemDiem);//dòng add điểm vào trong danh sách điểm của cell
                    }
                    else
                    {
                        continue;
                    }
                }
            }


            TRAM tram2 = new TRAM();


            //     tìm những trạm nào có điểm phục vụ thì thêm vào trạm 2, đồng thời tính góc của điểm đó với trạm xem là bao nhiêu độ luôn.
            foreach (CELL itemCell in tram.CellList)
            {
                if (itemCell.DiemList.Count > diempv)
                {
                    foreach (DIEM itemDiem in itemCell.DiemList)
                    {
                        itemDiem.anlge = angle(itemCell.latCell, itemDiem.lat, itemCell.lonCell, itemDiem.lon); //tính góc hướng của điểm với cell phục vụ
                    }
                    tram2.CellList.Add(itemCell);                                                               // nếu cell đó có trên 1 điểm phục vụ thì add cell đó vào tập trạm2
                }
                else
                {
                    continue;
                }
            }



            //phần này xác định cell nào bị chéo nếu cell chéo thì swap = true


            //xác định bằng cách nếu số điểm phục vụ của cell trên lớn hơn 60% tổng số điểm có góc hướng không thuộc góc hướng của cell ( góc hướng của cell +- 30 độ) thì là chéo rồi



            foreach (CELL itemcell in tram2.CellList)
            {
                double anlgeTBtem = 0;// tính góc hướng trung bình  của các điểm thuộc cell đó

                foreach (DIEM itemDiem in itemcell.DiemList)
                {
                    if (!doTim(itemcell.Azimut, itemDiem.anlge, bw))//hàm này để dò xem điểm có thuộc góc hướng của cell ko

                    {
                        itemcell.demdiem++;
                    }                      // biến đếm  đếm xem có bao nhiêu điểm không thuộc góc hướng của cell

                    anlgeTBtem = anlgeTBtem + itemDiem.anlge;
                }

                if (((double)itemcell.demdiem / (double)itemcell.DiemList.Count) > 0.6)//lớp hơn 60% thì tức là cell này phải swap lại
                {
                    itemcell.swap = true;
                }

                itemcell.angleTB = (anlgeTBtem / itemcell.DiemList.Count); //tính góc hướng trung bình của cell

                //  if (itemcell.swap == true)
                //  ketqua.Rows.Add(itemcell.tramName, itemcell.tencell, itemcell.latCell, itemcell.lonCell, itemcell.uarfcn, itemcell.psc, itemcell.Azimut, itemcell.angleTB);
                //  Console.WriteLine(itemcell.tramName + ";" + itemcell.tencell + ";" + itemcell.latCell + ";" + itemcell.lonCell + ";" + itemcell.uarfcn + ";" + itemcell.psc + ";" + itemcell.Azimut + ";" + itemcell.angleTB);
            }


            DataTable ketqua = new DataTable();

            ketqua.Columns.Add("TramName");
            ketqua.Columns.Add("tencell");
            ketqua.Columns.Add("latCell");
            ketqua.Columns.Add("lonCell");
            ketqua.Columns.Add("uarfcn ");
            ketqua.Columns.Add("psc");
            ketqua.Columns.Add("Azimut");
            ketqua.Columns.Add("AngleTB");
            ketqua.Columns.Add("so_mau");


            foreach (CELL item in tram2.CellList)
            {
                if (item.swap == true)
                {
                    ketqua.Rows.Add(item.tramName, item.tencell, item.latCell, item.lonCell, item.uarfcn, item.psc, item.Azimut, item.angleTB, item.DiemList.Count);
                }
            }
            ketqua.AcceptChanges();
            dataGridView1.DataSource = ketqua;



            String filepath = linkResult.Text + "\\test.txt";

            //    FileStream fs = new FileStream(filepath, FileMode.Create);
            try
            {
                using (StreamWriter sw = new StreamWriter(filepath))
                {
                    sw.WriteLine("tên trạm;" + "tên cell;" + "lat cell;" + "lonCell;" + "uarfcn;" + "psc;" + "Azimut;" + "angleTB;" + "số mẫu;" + "swap");

                    foreach (CELL itemcell in tram2.CellList)
                    {
                        // if (itemcell.swap == true)
                        sw.WriteLine(itemcell.tramName + ";" + itemcell.tencell + ";" + itemcell.latCell + ";" + itemcell.lonCell + ";" + itemcell.uarfcn + ";" + itemcell.psc + ";" + itemcell.Azimut + ";" + itemcell.angleTB + ";" + itemcell.DiemList.Count + ";" + itemcell.swap);
                    }
                    MessageBox.Show("file chéo cheo đã được tạo ra ở thư mục " + filepath);
                }
            }
            catch (Exception g)

            {
                MessageBox.Show("Error:  đường dẫm của bạn ko đúng hoặc đường dẫn vào thư mục windows ko cho phép chương trình tạo file" + g);
            }
        }