EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่างเพิ่มเติม)Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
namespace Auto_Connection_WD_MycloudPR4100
{
public partial class Auto_Connecttion_WD_MycloudPR4100 : Form
{
int count = 0;
System.Timers.Timer t;
int h, m, s;
private async void btn_connext_Click(object sender, EventArgs e)
{
serialPort1.PortName = portComboBox.SelectedItem + "";
serialPort1.BaudRate = 115200;
serialPort1.Open();
btn_connext.Enabled = false;
listStatu.Items.Add("Connected....");
await Task.Delay(1000);
listStatu.Items.Add("Please Click ''TEST''");
}
private void btn_TestAuto_Click(object sender, EventArgs e)
{
// webBrowser1.Url = new Uri(txtAddress.Text);
timer1.Start();
groupBox3.Enabled = false;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// MessageBox.Show(webBrowser1.Url.ToString());
}
private void btn_close_Click(object sender, EventArgs e)
{
serialPort1.Write("5");
serialPort1.Write("6");
serialPort1.Write("7");
serialPort1.Write("8");
Application.Exit();
}
private async void timer1_Tick(object sender, EventArgs e)
{
if (count <= 7)
{
timer1.Stop();
// webBrowser1.Url = new Uri("http://mycloudpr4100/");
webBrowser1.Url = new Uri(txtAddress.Text);
await Task.Delay(2000);
webBrowser1.Document.GetElementById("login_login_button").InvokeMember("Click");
await Task.Delay(2000);
webBrowser1.Document.GetElementById("id_logout").InvokeMember("Click");
await Task.Delay(1500);
webBrowser1.Document.GetElementById("home_reboot_link").InvokeMember("Click");
await Task.Delay(1500);
//webBrowser1.Document.GetElementById("popup_apply_button").InvokeMember("Click");
count = count + 1;
label44.Text = count.ToString();
listStatu.Items.Add("Please Waiting");
serialPort1.Write("1");
await Task.Delay(20000);
pictureON1.Visible = true;
pictureOFF1.Visible = false;
lbOn1.Text = "ON";
lbOn1.BackColor = Color.GreenYellow;
listStatu.Items.Add("Test Drive 2.0 [1]ON...");
}
Application.DoEvents();
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Write("1");
pictureON1.Visible = true;
pictureOFF1.Visible = false;
lbOn1.Text = "ON";
lbOn1.BackColor = Color.GreenYellow;
button2.Enabled = false;
listStatu.Items.Add("Test Drive 2.0 [1]ON...");
}
private void button3_Click(object sender, EventArgs e)
{
serialPort1.Write("2");
pictureON2.Visible = true;
pictureOFF2.Visible = false;
lbOn2.Text = "ON";
lbOn2.BackColor = Color.GreenYellow;
button3.Enabled = false;
listStatu.Items.Add("Test Drive 2.0 [2]ON...");
}
private void button4_Click(object sender, EventArgs e)
{
serialPort1.Write("3");
pictureON3.Visible = true;
pictureOFF3.Visible = false;
lbOn3.Text = "ON";
lbOn3.BackColor = Color.GreenYellow;
button4.Enabled = false;
listStatu.Items.Add("Test Drive 3.0 [1]ON...");
}
private void button5_Click(object sender, EventArgs e)
{
serialPort1.Write("4");
pictureON4.Visible = true;
pictureOFF4.Visible = false;
lbOn4.Text = "ON";
lbOn4.BackColor = Color.GreenYellow;
button5.Enabled = false;
listStatu.Items.Add("Test Drive 3.0 [2]ON...");
}
private void button6_Click(object sender, EventArgs e)
{
serialPort1.Write("5");
serialPort1.Write("6");
serialPort1.Write("7");
serialPort1.Write("8");
//
pictureON1.Visible = false;
pictureOFF1.Visible = true;
lbOn1.Text = "OFF";
lbOn1.BackColor = Color.Red;
//
pictureON2.Visible = false;
pictureOFF2.Visible = true;
lbOn2.Text = "OFF";
lbOn2.BackColor = Color.Red;
//
pictureON3.Visible = false;
pictureOFF3.Visible = true;
lbOn3.Text = "OFF";
lbOn3.BackColor = Color.Red;
//
pictureON4.Visible = false;
pictureOFF4.Visible = true;
lbOn4.Text = "OFF";
lbOn4.BackColor = Color.Red;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
btn_TestAuto.Enabled = true;
listStatu.Items.Add("Clear Test Button [AUTO] open.\n");
}
private void portComboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
listStatu.Items.Add("Please Click Connect...");
btn_connext.Visible = true;
}
private async void btn_Shutdown_Click(object sender, EventArgs e)
{
webBrowser1.Url = new Uri(txtAddress.Text);
await Task.Delay(2000);
webBrowser1.Document.GetElementById("login_login_button").InvokeMember("Click");
await Task.Delay(2000);
webBrowser1.Document.GetElementById("id_logout").InvokeMember("Click");
await Task.Delay(1500);
webBrowser1.Document.GetElementById("home_shutdown_link").InvokeMember("Click");
await Task.Delay(1500);
//webBrowser1.Document.GetElementById("popup_apply_button").InvokeMember("Click");
count = count + 1;
label44.Text = count.ToString();
listStatu.Items.Add("Please Waiting");
serialPort1.Write("1");
await Task.Delay(20000);
pictureON1.Visible = true;
pictureOFF1.Visible = false;
lbOn1.Text = "ON";
lbOn1.BackColor = Color.GreenYellow;
listStatu.Items.Add("Test Drive 2.0 [1]ON...");
}
//-----------------------------------------MANUAL----------------------------------------------------
private async void btn_WakeMeOn_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
MessageBox.Show(lbUser.Text);
Process.Start("cmd.exe");
await Task.Delay(500);
SendKeys.Send("cd " + lbUser.Text + "{ENTER}");
await Task.Delay(500);
SendKeys.Send("Wolcmd.exe" + "{ENTER}");
await Task.Delay(500);
//wolcmd [mac address] [ip address] [subnet mask] [port number]
SendKeys.Send("wolcmd " + lbMac.Text + " " + lbIP.Text + " " + lbSubnet.Text + "{ENTER}");
await Task.Delay(500);
// SendKeys.Send("exit" + "{ENTER}");
}
//------------------------------Void Timer ----------------------------------------------------------
//------------------------------Void Timer ----------------------------------------------------------
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
t.Stop();
Application.DoEvents();
}
private void OntimeEvent(object sender, ElapsedEventArgs e)
{
Invoke(new Action(() =>
{
s += 1;
if (s == 60)
{
s = 0;
m += 1;
}
if (m == 60)
{
m = 0;
h += 1;
}
txtResult.Text = string.Format("{0}:{1}:{2}", h.ToString().PadLeft(2, '0'), m.ToString().PadLeft(2, '0'), s.ToString().PadLeft(2, '0'));
}));
}
//------------------------------Void Timer ----------------------------------------------------------
public Auto_Connecttion_WD_MycloudPR4100()
{
InitializeComponent();
serialPort1.Close();
}
private void Auto_Connecttion_WD_MycloudPR4100_Load(object sender, EventArgs e)
{
//-------------------SerialPort---------------------
string[] strPortNames = SerialPort.GetPortNames();
foreach (string n in strPortNames)
{
portComboBox.Items.Add(n);
}
//-------------------SerialPort----------------------
t = new System.Timers.Timer();
t.Interval = 1000;
t.Elapsed += OntimeEvent;
t.Start();
btn_connext.Visible = false;
btn_TestAuto.Enabled = false;
}
}
}