//To get Image Areas Coordinates from database and send them to Front End to Display on Image protected void GetImageAreas(int currentImage) { int ImgId = int.Parse(mainDt.Rows[currentImage].ItemArray[0].ToString()); currentImageId = ImgId; InnitialAreas.Clear(); string conString = ConfigurationManager.ConnectionStrings["Images"].ConnectionString; SqlConnection con = new SqlConnection(conString); string query = "SELECT [Id],[AreaId],[X],[Y],[Width],[Height],[Label] FROM [dbo].[Coordinates] WHERE ImgId = @Id"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.Add("@Id", System.Data.SqlDbType.Int); cmd.Parameters["@Id"].Value = ImgId; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { AnnotationArea Area = new AnnotationArea(); Area.id = int.Parse(dt.Rows[i]["AreaId"].ToString()); Area.x = int.Parse(dt.Rows[i]["X"].ToString()); Area.y = int.Parse(dt.Rows[i]["Y"].ToString()); Area.width = int.Parse(dt.Rows[i]["Width"].ToString()); Area.height = int.Parse(dt.Rows[i]["Height"].ToString()); Area.tag = dt.Rows[i]["Label"].ToString(); Area.dataId = int.Parse(dt.Rows[i]["Id"].ToString()); InnitialAreas.Add(Area); } string dataString = ""; for (int i = 0; i < dt.Rows.Count; i++) { dataString += '~'; dataString += InnitialAreas[i].id.ToString() + ',' + InnitialAreas[i].x.ToString() + ',' + InnitialAreas[i].y.ToString() + ',' + InnitialAreas[i].width.ToString() + ',' + InnitialAreas[i].height.ToString() + ',' + InnitialAreas[i].tag.ToString(); } if (dataString.Length > 0) { dataString = dataString.Substring(1); } ImageAreas.Value = dataString; }
private void AddNewData(AnnotationArea Area, SqlConnection con) { string query = "INSERT INTO [dbo].[Coordinates] VALUES (@ImageId, @AreaId, @X, @Y, @Height, @Width, @Label )"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.Add("@ImageId", SqlDbType.Int); cmd.Parameters.Add("@AreaId", SqlDbType.Int); cmd.Parameters.Add("@X", SqlDbType.Int); cmd.Parameters.Add("@y", SqlDbType.Int); cmd.Parameters.Add("@Height", SqlDbType.Int); cmd.Parameters.Add("@Width", SqlDbType.Int); cmd.Parameters["@ImageId"].Value = currentImageId; cmd.Parameters["@AreaId"].Value = Area.id; cmd.Parameters["@X"].Value = (int)(Area.x / Double.Parse(RatioOfX.Value)); cmd.Parameters["@Y"].Value = (int)(Area.y / Double.Parse(RatioOfY.Value)); cmd.Parameters["@Width"].Value = (int)(Area.width / Double.Parse(RatioOfX.Value)); cmd.Parameters["@Height"].Value = (int)(Area.height / Double.Parse(RatioOfY.Value)); cmd.Parameters.AddWithValue("@Label", (Area.tag.Split(' '))[0]); cmd.ExecuteNonQuery(); }
private void UpdateData(AnnotationArea Area, SqlConnection con) { int DataId = Area.dataId; string query = "UPDATE [dbo].[Coordinates] SET X = @X, Y = @Y, Height = @Height, Width = @Width, Label = @Label WHERE Id = @ID"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.Add("@ID", SqlDbType.Int); cmd.Parameters.Add("@X", SqlDbType.Int); cmd.Parameters.Add("@Y", SqlDbType.Int); cmd.Parameters.Add("@Height", SqlDbType.Int); cmd.Parameters.Add("@Width", SqlDbType.Int); cmd.Parameters.AddWithValue("@Label", (Area.tag.Split(' ')[0])); cmd.Parameters["@ID"].Value = DataId; cmd.Parameters["@X"].Value = (int)(Area.x / Double.Parse(RatioOfX.Value)); cmd.Parameters["@Y"].Value = (int)(Area.y / Double.Parse(RatioOfY.Value)); cmd.Parameters["@Width"].Value = (int)(Area.width / Double.Parse(RatioOfX.Value)); cmd.Parameters["@Height"].Value = (int)(Area.height / Double.Parse(RatioOfY.Value)); cmd.ExecuteNonQuery(); }