private void button2_Click(object sender, EventArgs e) { DataServiceXmlImpl objj = new DataServiceXmlImpl(); var plcss = objj.Read(); { for (int i = 0; i < plcss.plcList.Count; i++) { //string data = plcs.plcList[i].ipAddress.ToString(); if (plcss.plcList[i].ipAddress.ToString() == cb1.Text) { plcss.plcList[i].ownerName = txtnewowner.Text; XmlSerializer serializer = new XmlSerializer(typeof(plcs)); using (TextWriter writer = new StreamWriter(@"D:\InformationPlc.xml")) { serializer.Serialize(writer, plcss); writer.Close(); } } } MessageBox.Show("Owner details is edited"); txtCurrentOwner.Text = ""; txtnewowner.Text = ""; groupBox1.Visible = false; } }
public void createpanel() { DataServiceXmlImpl objj = new DataServiceXmlImpl(); var plcss = objj.Read(); for (int j = 0; j < plcss.plcList.Count; j++) { cb1.Items.Add(plcss.plcList[j].ipAddress); } cb1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown; cb1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; cb1.AutoCompleteSource = AutoCompleteSource.ListItems; }
private void cb1_SelectedIndexChanged(object sender, EventArgs e) { groupBox1.Enabled = true; groupBox1.Visible = true; string ed1 = cb1.Text; DataServiceXmlImpl obj = new DataServiceXmlImpl(); var plcs = obj.Read(); for (int i = 0; i < plcs.plcList.Count; i++) { //string data = plcs.plcList[i].ipAddress.ToString(); if (plcs.plcList[i].ipAddress.ToString() == cb1.Text) { txtCurrentOwner.Text = String.Format(plcs.plcList[i].ownerName.ToString()); } } }
private void Save_Click(object sender, EventArgs e) { DataServiceXmlImpl objj = new DataServiceXmlImpl(); var addip = objj.Read(); plcDevice obj2 = new plcDevice(); obj2.ipAddress = addtxtip.Text; obj2.status = " "; obj2.userName = "******"; obj2.ownerName = addtxtname.Text; addip.plcList.Add(obj2); XmlSerializer serializer = new XmlSerializer(typeof(plcs)); using (TextWriter writer = new StreamWriter(@"D:\InformationPlc.xml")) { serializer.Serialize(writer, addip); writer.Close(); } MessageBox.Show("Data has been added"); }
public void createpanel() { DataServiceXmlImpl obj = new DataServiceXmlImpl(); var plcs = obj.Read(); this.AutoSize = true; tableLayoutPanel1.Controls.Clear(); //Clear out the existing row and column styles tableLayoutPanel1.ColumnStyles.Clear(); tableLayoutPanel1.RowStyles.Clear(); tableLayoutPanel1.AutoSize = true; //Now we will generate the table, setting up the row and column counts first tableLayoutPanel1.ColumnCount = 6; tableLayoutPanel1.RowCount = plcs.plcList.Count; Label lbIpaddress = new Label(); lbIpaddress.Text = string.Format("IP Address"); tableLayoutPanel1.Controls.Add(lbIpaddress); Label lbOwnername = new Label(); lbOwnername.Text = string.Format("Owner"); tableLayoutPanel1.Controls.Add(lbOwnername); Label lbStatus = new Label(); lbStatus.Text = string.Format("Status"); tableLayoutPanel1.Controls.Add(lbStatus); Label lbUsername = new Label(); lbUsername.Text = string.Format("User"); tableLayoutPanel1.Controls.Add(lbUsername); Label lbAccess = new Label(); lbAccess.Text = string.Format("Access"); tableLayoutPanel1.Controls.Add(lbAccess); Label lbRelease = new Label(); lbRelease.Text = string.Format("PLC"); tableLayoutPanel1.Controls.Add(lbRelease); for (int x = 0; x < tableLayoutPanel1.RowCount; x++) { //First add a column tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); //Next, add a row. Only do this when once, when creating the first column // tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize)); TextBox txtIpaddress = new TextBox(); //txtIpaddress.Name = x.ToString(); txtIpaddress.Text = string.Format(plcs.plcList[x].ipAddress.ToString()); //Finally, add the control to the correct location in the table tableLayoutPanel1.Controls.Add(txtIpaddress); //txtIpaddress.Enabled = false; txtIpaddress.ReadOnly = true; TextBox txtOwnername = new TextBox(); txtOwnername.Text = string.Format(plcs.plcList[x].ownerName); //Finally, add the control to the correct location in the table tableLayoutPanel1.Controls.Add(txtOwnername); txtOwnername.ReadOnly = true; CheckBox cbStatus = new CheckBox(); cbStatus.Text = string.Format(plcs.plcList[x].status); if (plcs.plcList[x].status == "Active") { cbStatus.Checked = true; } else { cbStatus.Checked = false; } tableLayoutPanel1.Controls.Add(cbStatus); cbStatus.Enabled = false; TextBox txtUsername = new TextBox(); if (cbStatus.Checked) { txtUsername.Text = string.Format(plcs.plcList[x].userName); //Finally, add the control to the correct location in the table } else { txtUsername.Text = ""; } tableLayoutPanel1.Controls.Add(txtUsername); txtUsername.ReadOnly = true; Button btnRequest = new Button(); //btnRequest.Name = x.ToString(); if (cbStatus.Checked == false) { btnRequest.Enabled = true; } else { btnRequest.Enabled = false; } tableLayoutPanel1.Controls.Add(btnRequest); btnRequest.Text = string.Format("Request PLC"); btnRequest.Click += (s, d) => { Form2 newform = new Form2(txtIpaddress.Text); newform.ShowDialog(); tableLayoutPanel1.Controls.Clear(); //Clear out the existing row and column styles tableLayoutPanel1.ColumnStyles.Clear(); tableLayoutPanel1.RowStyles.Clear(); createpanel(); //Button btn = s as Button; //MessageBox.Show(txtIpaddress.Text); }; Button btmRelease = new Button(); if (plcs.plcList[x].status == "Active") { btmRelease.Enabled = true; } else { btmRelease.Enabled = false; } tableLayoutPanel1.Controls.Add(btmRelease); btmRelease.Text = string.Format("Release PLC"); btmRelease.Click += (s, d) => { DataServiceXmlImpl _obj = new DataServiceXmlImpl(); var _plcs = _obj.Read(); for (int i = 0; i < _plcs.plcList.Count; i++) { //string data = plcs.plcList[i].ipAddress.ToString(); if (_plcs.plcList[i].ipAddress.ToString() == txtIpaddress.Text) { _plcs.plcList[i].status = "InActive"; } } XmlSerializer serializer = new XmlSerializer(typeof(plcs)); TextWriter writer = new StreamWriter(@"E:\InformationPlc.xml"); serializer.Serialize(writer, _plcs); writer.Close(); tableLayoutPanel1.Controls.Clear(); //Clear out the existing row and column styles tableLayoutPanel1.ColumnStyles.Clear(); tableLayoutPanel1.RowStyles.Clear(); createpanel(); }; textBox1.TextChanged += (s, k) => { reloadPanel(plcs.plcList); }; } }
private void button1_Click(object sender, EventArgs e) { TcpClient tcpclnt = new TcpClient(); try { tcpclnt.Connect("172.17.90.28", 8001); // use the ipaddress as in the server program string str = Environment.UserName + ":" + _ipAddress; Stream stm = tcpclnt.GetStream(); ASCIIEncoding asen = new ASCIIEncoding(); byte[] ba = asen.GetBytes(str); //Console.WriteLine("Transmitting....."); stm.Write(ba, 0, ba.Length); byte[] bb = new byte[100]; int k = stm.Read(bb, 0, 100); string result = System.Text.Encoding.UTF8.GetString(bb); //textBox2.Text = result; if (result.Contains("Yes")) { DataServiceXmlImpl obj = new DataServiceXmlImpl(); var plcs = obj.Read(); for (int i = 0; i < plcs.plcList.Count; i++) { //string data = plcs.plcList[i].ipAddress.ToString(); if (plcs.plcList[i].ipAddress.ToString() == _ipAddress) { plcs.plcList[i].userName = Environment.UserName; plcs.plcList[i].status = "Active"; } } XmlSerializer serializer = new XmlSerializer(typeof(plcs)); using (TextWriter writer = new StreamWriter(@"D:\InformationPlc.xml")) { serializer.Serialize(writer, plcs); writer.Close(); } this.Close(); } else { this.lblMessage.Text = "Your request has been declined!"; this.lblMessage.ForeColor = Color.Red; } } catch (Exception k) { //Console.WriteLine("Error..... " + e.StackTrace); } finally { tcpclnt.Close(); } }
private void tabControl1_Click(object sender, EventArgs e) { DataServiceXmlImpl objj = new DataServiceXmlImpl(); var plcss = objj.Read(); }