private void btnDelete_Click(object sender, EventArgs e) { try { using (IDbConnection cnn = new SqlConnection(HelperStatic.LoadConnectionString())) { string sql = $@"DELETE FROM Unit WHERE UnitID = {_mainFormUnit.UnitID}"; cnn.Execute(sql); } string DeletePath = Application.StartupPath + @"\Data\Units\image\" + "\\" + _mainFormUnit.UnitID + ".jpg"; File.Delete(DeletePath); DeletePath = Application.StartupPath + @"\Data\Units\pid\" + "\\" + _mainFormUnit.UnitID + ".pdf"; File.Delete(DeletePath); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Close(); }
public void frmTagFinder_Load(object sender, EventArgs e) { loadIsFinished = false; if (firstLoad) { #region reposition btnExit.Top = 0; btnExit.Left = this.Width - btnExit.Width; btnMinimize.Top = 0; btnMinimize.Left = btnExit.Left - btnExit.Width - 2; pnlTop.Height = btnExit.Height = btnMinimize.Height = this.Height * 5 / 100; pnlUnit.Width = btnEdit.Left + btnEdit.Width; pnlEquipment.Width = btnEditEquipmentType.Left + btnEditEquipmentType.Width; unitImagePictureBox.Dock = DockStyle.Fill; #endregion #region Binding /*unitBindingSource.DataSource = _CurrentUnit; * unitBindingSource.ResetBindings(true); * * equipmentTypeBindingSource.DataSource = _CurrentEquipmentType; * equipmentTypeBindingSource.ResetBindings(true); * * equipmentBindingSource.DataSource = _CurrentEquipment; * equipmentBindingSource.ResetBindings(true);*/ #endregion #region loadAllUnits using (IDbConnection cnn = new SqlConnection(HelperStatic.LoadConnectionString())) { var p = new DynamicParameters(); p.Add("@tblName", "Unit"); string sql = "[dbo].[SelectTable]"; _AllUnins = cnn.Query <Unit>(sql, p, commandType: CommandType.StoredProcedure).ToList(); } #endregion #region loadAllEquipmentType using (IDbConnection cnn = new SqlConnection(HelperStatic.LoadConnectionString())) { var p = new DynamicParameters(); p.Add("@tblName", "EquipmentType"); string sql = "[dbo].[SelectTable]"; _AllEquipmentTypes = cnn.Query <EquipmentType>(sql, p, commandType: CommandType.StoredProcedure).ToList(); } #endregion #region loadAllEquipment using (IDbConnection cnn = new SqlConnection(HelperStatic.LoadConnectionString())) { var p = new DynamicParameters(); p.Add("@tblName", "Equipment"); string sql = "[dbo].[SelectTable]"; _AllEquipments = cnn.Query <Equipment>(sql, p, commandType: CommandType.StoredProcedure).ToList(); tagComboBox.DataSource = _AllEquipments.Select(x => x.Tag).ToList(); } #endregion this.equipmentNameComboBox.SelectedIndexChanged += new System.EventHandler(this.equipmentNameComboBox_SelectedIndexChanged); this.unitNameComboBox.SelectedIndexChanged += new System.EventHandler(this.unitNameComboBox_SelectedIndexChanged); equipmentNameComboBox_SelectedIndexChanged(sender, null); unitNameComboBox_SelectedIndexChanged(sender, null); unitNameComboBox.DataSource = _AllUnins.OrderBy(x => x.UnitName).Select(x => x.UnitName).ToList(); equipmentNameComboBox.DataSource = _AllEquipmentTypes.OrderBy(x => x.EquipmentName).Select(x => x.EquipmentName).ToList(); //test_Timer.Start(); firstLoad = false; } List <Equipment> _AllSelectedEquipments = new List <Equipment>();// = _AllEquipments; switch (my_SelectEquipments) { case SelectEquipments.UnitSelected: _AllSelectedEquipments = _AllEquipments.Where(x => x.UnitID == _CurrentUnit.UnitID).ToList(); break; case SelectEquipments.UnitAndType: _AllSelectedEquipments = _AllEquipments.Where(x => x.UnitID == _CurrentUnit.UnitID && x.EquipmentTypeID == _CurrentEquipmentType.EquipmentTypeID).ToList(); break; case SelectEquipments.onlyOneTag: _AllSelectedEquipments = _AllEquipments.Where(x => x.Tag == _CurrentEquipment.Tag).ToList(); break; /*case SelectEquipments.TypeSelected: * break; * case SelectEquipments.nulll: * break;*/ default: break; } unitImagePictureBox.Controls.Clear(); _AllSelectedEquipments = currectPositionEquipments(_AllSelectedEquipments); foreach (Equipment equipment in _AllSelectedEquipments) { int x = 0; Int32.TryParse(equipment.XOffset.ToString(), out x); int y = 0; Int32.TryParse(equipment.YOffset.ToString(), out y); MouseEventArgs e1 = new MouseEventArgs(MouseButtons.Left, 1, x, y, 1); my_clickedTask = ClickedTask.AddEquipment; unitImagePictureBox_MouseDown(sender, e1); } loadIsFinished = true; }
private List <Equipment> currectPositionEquipments(List <Equipment> allSelectedEquipments) { List <Equipment> TTTallSelectedEquipments = new List <Equipment>();// allSelectedEquipments; foreach (Equipment equipment in allSelectedEquipments) { TTTallSelectedEquipments.Add(equipment); } if (allSelectedEquipments.Where(x => x.IsDatum != true).Count() == 0) { return(TTTallSelectedEquipments);// = allSelectedEquipments; } List <Equipment> allDatums = _AllEquipments.Where(x => x.IsDatum == true && x.UnitID == allSelectedEquipments[0].UnitID).ToList(); frmEquipment.isValidUintArea isValidUintArea1 = new frmEquipment.isValidUintArea(); isValidUintArea1.left = allDatums.Min(x => x.XOffset).Value; isValidUintArea1.right = allDatums.Max(x => x.XOffset).Value; isValidUintArea1.top = allDatums.Min(x => x.YOffset).Value; isValidUintArea1.bottom = allDatums.Max(x => x.YOffset).Value; if (isValidUintArea1.isValid) { TTTallSelectedEquipments.Clear();// = allDatums;//.Clear(); foreach (Equipment equipment in allSelectedEquipments) { if (equipment.IsDatum == true) { TTTallSelectedEquipments.Add(equipment); } else { double t1 = Convert.ToDouble(100 / equipment.XPercent); var p1 = (isValidUintArea1.right - isValidUintArea1.left); double a = isValidUintArea1.left + p1 / t1; double t2 = Convert.ToDouble(100 / equipment.YPercent); var p2 = (isValidUintArea1.bottom - isValidUintArea1.top); double b = isValidUintArea1.top + p2 / t2; if (equipment.XOffset - a > 5 && equipment.YOffset - b > 5) { try { using (IDbConnection cnn = new SqlConnection(HelperStatic.LoadConnectionString())) { string sql = $@"DELETE FROM Equipment WHERE EquipmentID = {equipment.EquipmentID}"; int deleted = cnn.Execute(sql); //INSERT INTO [dbo].[Equipment] (EquipmentID ,EquipmentTypeID,UnitID,Latitude,Longitude,XOffset,YOffset,IsDatum,Tag) VALUES (@EquipmentID ,@EquipmentTypeID2,@UnitID2,@Latitude,@Longitude,@XOffset,@YOffset,@IsDatum,@Tag) sql = $@"INSERT INTO [dbo].[Equipment] (EquipmentTypeID,UnitID,Latitude,Longitude,XOffset,YOffset,IsDatum,Tag) " + $@"VALUES (@EquipmentTypeID,@UnitID,@Latitude,@Longitude,@XOffset,@YOffset,@IsDatum,@Tag)"; if (deleted > 0) { cnn.Execute(sql, equipment); } } } catch (Exception ex) { throw ex; } } TTTallSelectedEquipments.Add(equipment); } } } return(TTTallSelectedEquipments); }