private void grvStation_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 0)
     {
         FrmDetailStation frm = new FrmDetailStation(sourceData[e.RowIndex], this);
         frm.Show();
     }
     else if (e.ColumnIndex == 1)
     {
         if (MessageBox.Show("Delete record?", "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
         {
             DeleteStationDevice(sourceData[e.RowIndex].StationID);
             DeleteStationChannelDevice(sourceData[e.RowIndex].StationID);
             DeleteStation(sourceData[e.RowIndex].StationID);
             MessageBox.Show("Record Deleted Successfully!");
         }
     }
 }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmDetailStation frm = new FrmDetailStation(new StationViewModel(), this);

            frm.Show();
        }
        private void gmap_OnMarkerClick(GMapMarker item, MouseEventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Xem chi tiết thông tin trạm !! ", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                DataTable     dataTable = new DataTable();
                SqlConnection con       = new SqlConnection(cs);
                SqlCommand    com       = new SqlCommand(" Select TOP 1 * from Station where ID = @stationID ", con);

                SqlParameter name = new SqlParameter("@stationID", SqlDbType.Int);
                name.Value = int.Parse(item.Tag.ToString());
                com.Parameters.Add(name);
                SqlDataAdapter dataAdapter = new SqlDataAdapter(com);
                try
                {
                    con.Open();
                    dataAdapter.Fill(dataTable);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                }

                if (dataTable.Rows.Count > 0)
                {
                    //totalRecords = dtSource.Rows.Count;
                    foreach (DataRow item1 in dataTable.Rows)
                    {
                        StationViewModel model = new StationViewModel
                        {
                            //Group = item1["Group"].ToString(),
                            GroupID           = int.Parse(item1["StationGroupID"].ToString()),
                            StationCode       = item1["Code"].ToString(),
                            StationName       = item1["Name"].ToString(),
                            StationLocation   = item1["Location"].ToString(),
                            StationLatitude   = float.Parse(item1["Lat"].ToString()),
                            StationLongtitude = float.Parse(item1["Lng"].ToString()),
                            StationID         = int.Parse(item1["ID"].ToString()),
                            kvID = item1["KV_ID"].ToString()
                        };
                        FrmDetailStation frm = new FrmDetailStation(model, null);
                        frm.ShowDialog();
                        break;
                    }
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                //do something else
            }


            //if (currentMarker != null)
            //{
            //    currentMarker.ToolTip.Fill = Brushes.Gray;
            //}

            //if (currentMarkerMap != null) {
            //    currentMarkerMap.ToolTip.Fill = Brushes.Gray;
            //}

            //currentMarkerMap = item;
            //item.ToolTip.Fill = Brushes.Brown;
            //this.gmap.Position = new PointLatLng(item.Position.Lat, item.Position.Lng);
            ////Usage
            //TreeNode itemNode = null;
            //foreach (TreeNode node in tvListTram.Nodes)
            //{
            //    itemNode = FromID(item.Tag.ToString(), node);
            //    tvListTram.Focus();
            //    if (itemNode != null) {
            //        tvListTram.SelectedNode = itemNode;
            //    }
            //}

            //var result = tvListTram.Nodes.OfType<TreeNode>()
            //                .FirstOrDefault(node => node.Tag.Equals(item.Tag));
            //MessageBox.Show(result.Text);
            //DialogResult dialogResult = MessageBox.Show("Ap Suat : 11223 \r\n Luu luong: 1700 \r\n Battery : 12 VDC", "Station Info", MessageBoxButtons.YesNo);
            //if (dialogResult == DialogResult.Yes)
            //{
            //    //do something
            //}
            //else if (dialogResult == DialogResult.No)
            //{
            //    //do something else
            //}
        }