public void UpdateRemove(int ID, double quantity, double sell) { cmd = new SqlCommand(); cmd.CommandText = "UPDATE Products SET Quantity = @quantity, Sell = @sell WHERE ID = @id"; connection = new ConnectionController(); cmd.Parameters.AddWithValue("@quantity", quantity); cmd.Parameters.AddWithValue("@sell", sell); cmd.Parameters.AddWithValue("@id", ID); try { //Object connection = new ConnectionController(); //Connect to the DB cmd.Connection = connection.Connect(); //Execute command cmd.ExecuteNonQuery(); //Disconnect cmd.Connection = connection.Disconnect(); } catch (SqlException) { Console.WriteLine("Erro ao alterar dados no Banco."); } finally { //Disconnect the DB cmd.Connection = connection.Disconnect(); } }
void ConnectionView_Loaded(object sender, RoutedEventArgs e) { //initialise connection view from appropriate controller //TODO: get view based on connection type var displaySize = (Size)PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice.Transform(new Vector(this.ActualWidth, this.ActualHeight)); connectionController = new RDPConnectionController { DesktopResolution = new Size(displaySize.Width, displaySize.Height), Model = ViewModel }; ViewModel.DisconnectRequested += (s, se) => { connectionController.Disconnect(); }; connectionController.Disconnected += (s, se) => { ViewModel.OnDisconnected(se); }; System.Windows.Forms.Panel container = new System.Windows.Forms.Panel(); container.Dock = System.Windows.Forms.DockStyle.Fill; formHost.Child = container; var rdpConnection = connectionController.ConnectionView; rdpConnection.Dock = System.Windows.Forms.DockStyle.Fill; rdpConnection.Parent = container; rdpConnection.CreateControl(); this.GotFocus += new RoutedEventHandler(ConnectionView_GotFocus); connectionController.CreateControl(); connectionController.Connect(); //make sure all events fire System.Windows.Forms.Application.DoEvents(); }
//Insert in DB public void InsertDB(Product p) { connection = new ConnectionController(); SqlConnection sc = new SqlConnection(); sc = connection.Cn; //SQL Command cmd = new SqlCommand("INSERT INTO Products (Name, Quantity, PurchasePrice, SalePrice, Buy, Sell)" + "values (@Name, @Quantity, @PurchasePrice, @SalePrice, @Buy, @Sell)", sc); //Parameters cmd.Parameters.AddWithValue("@Name", p.Name); cmd.Parameters.AddWithValue("@Quantity", p.Quantity); cmd.Parameters.AddWithValue("@PurchasePrice", p.PurchasePrice); cmd.Parameters.AddWithValue("@SalePrice", p.SalePrice); cmd.Parameters.AddWithValue("@Buy", p.Buy); cmd.Parameters.AddWithValue("@Sell", p.Sell); try { //Object connection = new ConnectionController(); //Connect to the DB cmd.Connection = connection.Connect(); //Execute command cmd.ExecuteNonQuery(); //Disconnect the DB cmd.Connection = connection.Disconnect(); } catch (SqlException) { Console.WriteLine("Nome do produto excede o limite para registro, tente novamente."); } finally { connection.Disconnect(); } }
public void Connect(string address, int port, string login, InterfaceType interfaceType) { _connectionController = null; switch (interfaceType) { case InterfaceType.WebSocket: _connectionController = new WsNetworkController(); break; case InterfaceType.Tcp: _connectionController = new TcpNetworkController(); break; default: throw new ArgumentOutOfRangeException(nameof(Type), interfaceType, null); } _connectionController.Connect(address, port, login); _connectionController.ConnectionStateChanged += HandleConnectionStateChanged; _connectionController.Login += HandleLogin; _connectionController.MessageReceived += HandleMessageReceived; _connectionController.UpdateChannel += HandleUpdateChannel; _connectionController.LogEvent += HandleLog; }
public void SelectDB(List <Product> list) { cmd = new SqlCommand(); //SQL Command cmd.CommandText = "SELECT * FROM Products"; try { //Object connection = new ConnectionController(); Product p; SqlDataReader reader; //Connect to the DB cmd.Connection = connection.Connect(); //Execute command reader = cmd.ExecuteReader(); if (reader.HasRows) { //Loop to read the rows and set in the object while (reader.Read()) { p = new Product(); p.ID = Convert.ToInt32(reader["ID"].ToString()); //Repeated data test by ID if (!(p.ID <= list.Count)) { p.Name = reader["Name"].ToString(); p.Quantity = Convert.ToInt32(reader["Quantity"].ToString()); p.PurchasePrice = double.Parse(reader["PurchasePrice"].ToString()); p.SalePrice = double.Parse(reader["SalePrice"].ToString()); p.Buy = double.Parse(reader["Buy"].ToString()); p.Sell = double.Parse(reader["Sell"].ToString()); list.Add(p); } else { list[p.ID - 1].Name = reader["Name"].ToString(); list[p.ID - 1].Quantity = Convert.ToInt32(reader["Quantity"].ToString()); list[p.ID - 1].PurchasePrice = double.Parse(reader["PurchasePrice"].ToString()); list[p.ID - 1].SalePrice = double.Parse(reader["SalePrice"].ToString()); list[p.ID - 1].Buy = double.Parse(reader["Buy"].ToString()); list[p.ID - 1].Sell = double.Parse(reader["Sell"].ToString()); } } //end while } //end if reader.Close(); } //Disconnect the DB catch (SqlException) { Console.WriteLine("Erro ao conectar ao banco de dados, tente novamente"); } finally { connection.Disconnect(); } }//end selectDB