using inputbox;
using Microsoft.VisualBasic;
{
string msg, title, df;
object myvalue;
msg = "input";
title = "test";
df = "bb";
myvalue = Interaction.InputBox(msg, title, df);
if ((string)myvalue=="")
{
myvalue = df;
Interaction.MsgBox("MyValue=" + myvalue.ToString(), MsgBoxStyle.OkOnly | MsgBoxStyle.Information, "C# Msgbox Demo");
}
else {
Interaction.MsgBox("Hello, " + myvalue.ToString() + "!"+Environment.NewLine+"Nice to meet you",MsgBoxStyle.OkOnly|MsgBoxStyle.Information,"C# Demo");
}
}
https://www.youtube.com/watch?v=LEsl_psykrQ&t=4s
วันพฤหัสบดีที่ 30 เมษายน พ.ศ. 2563
วันพุธที่ 29 เมษายน พ.ศ. 2563
ส่งค่าข้าม Form
ฟอร้มหลัก
if (Application.OpenForms["formnutri05"] != null)
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
// ต้องเรียงลำดับตามนี้ ก่อนฟอร์ม โชว์
ฟอร์มที่รับค่า
public string hcode { get; set; }
public string hname { get; set; }
public int yearprocess { get; set; }
public MySqlConnection ConJ { get; set; }
public MySqlConnection ConServer { get; set; }
if (Application.OpenForms["formnutri05"] != null)
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
// ต้องเรียงลำดับตามนี้ ก่อนฟอร์ม โชว์
ฟอร์มที่รับค่า
public string hcode { get; set; }
public string hname { get; set; }
public int yearprocess { get; set; }
public MySqlConnection ConJ { get; set; }
public MySqlConnection ConServer { get; set; }
ตรวจสอบเปิด form ซ้ำ
if (Application.OpenForms["formnutri05"] != null)
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
วันอังคารที่ 28 เมษายน พ.ศ. 2563
เพิ่มปีใน Combobox +- 10 ปี
1.สร้าง class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testmenu
{
public class yearP
{
public string tyear { get; set; }
public int pyear { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testmenu
{
public class yearP
{
public string tyear { get; set; }
public int pyear { get; set; }
}
}
2.สร้าง procedure ใน Form
void AddValue()
{
comboBox1.Items.Clear();
int year = DateTime.Now.Year;
string a = year.ToString();
//comboBox1.Items.Add(a);
List<yearP> list = new List<yearP>();
for (int i = 1; i <= 10; i++)
{
int my = year + i;
string tmy = (my + 543).ToString();
list.Add(new yearP() { tyear = tmy, pyear = my });
}
for (int i = 0; i <= 10; i++)
{
int my = year - i;
string tmy = (my + 543).ToString();
list.Add(new yearP() { tyear = tmy, pyear = my });
}
comboBox1.DataSource = list;
comboBox1.ValueMember = "pyear";
comboBox1.DisplayMember = "tyear";
}
3.เรียกใช้
private void FormMain_Load(object sender, EventArgs e)
{
AddValue();
comboBox1.SelectedIndex = 10;
}
How to: Make the entire focused row highlighted เลือกทั้งแถว
This example shows how to paint the focused cell using the same appearance as the entire focused row:
// Make the grid read-only. gridView1.OptionsBehavior.Editable = false; // Prevent the focused cell from being highlighted. gridView1.OptionsSelection.EnableAppearanceFocusedCell = false; // Draw a dotted focus rectangle around the entire row. gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
วันอาทิตย์ที่ 26 เมษายน พ.ศ. 2563
C# - Logical Operators
Operator | Description | Example |
---|---|---|
&& | Called Logical AND operator. If both the operands are non zero then condition becomes true. | (A && B) is false. |
|| | Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. | (A || B) is true. |
! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A && B) is true. |
Example
using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { bool a = true; bool b = true; if (a && b) { Console.WriteLine("Line 1 - Condition is true"); } if (a || b) { Console.WriteLine("Line 2 - Condition is true"); } /* lets change the value of a and b */ a = false; b = true; if (a && b) { Console.WriteLine("Line 3 - Condition is true"); } else { Console.WriteLine("Line 3 - Condition is not true"); } if (!(a && b)) { Console.WriteLine("Line 4 - Condition is true"); } Console.ReadLine(); } } }
วันเสาร์ที่ 25 เมษายน พ.ศ. 2563
Get connection string from App.config
using System.Configuration;
//--------------------------------------------
InitializeComponent();
var j = Properties.Settings.Default;
string jserver = j.jserver;
string jport = j.jport.ToString();
string jdbname = j.jdbname;
string jusername = j.juser;
string jpassword = j.jpassword;
StringBuilder jsb = new StringBuilder();
jsb.Append("server=" + jserver + ";");
jsb.Append("port=" + jport + ";");
jsb.Append("Database=" + jdbname + ";");
jsb.Append("Uid=" + jusername + ";");
jsb.Append("Pwd=" + jpassword + ";");
jsb.Append("CharSet=utf8;");
jsb.Append("Convert Zero Datetime=True;Use Affected Rows=true;AllowUserVariables=True;CheckParameters=False;");
string jconString = jsb.ToString();
jcon = new MySqlConnection(jconString);
//--------------------------------------------
InitializeComponent();
var j = Properties.Settings.Default;
string jserver = j.jserver;
string jport = j.jport.ToString();
string jdbname = j.jdbname;
string jusername = j.juser;
string jpassword = j.jpassword;
StringBuilder jsb = new StringBuilder();
jsb.Append("server=" + jserver + ";");
jsb.Append("port=" + jport + ";");
jsb.Append("Database=" + jdbname + ";");
jsb.Append("Uid=" + jusername + ";");
jsb.Append("Pwd=" + jpassword + ";");
jsb.Append("CharSet=utf8;");
jsb.Append("Convert Zero Datetime=True;Use Affected Rows=true;AllowUserVariables=True;CheckParameters=False;");
string jconString = jsb.ToString();
jcon = new MySqlConnection(jconString);
pie chart
using DevExpress.Charts.Model;
using DevExpress.XtraCharts;
using MySql.Data.MySqlClient;
using MySqlX.XDevAPI.Relational;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.Charts.Native;
namespace WindowsFormsApp1
{
public partial class FormSendReport : Form
{
public FormSendReport()
{
InitializeComponent();
}
string ConString = "Server=127.0.0.1;Database=r506;Uid=root;ConvertZeroDateTime=True;";
private void FormSendReport_Load(object sender, EventArgs e)
{
MySqlConnection cnn = new MySqlConnection(ConString);
DataSet ds = new DataSet();
string sql = "SELECT e.HSERV,COUNT(*) as c " +
"FROM epe0 e " +
"GROUP BY e.HSERV";
MySqlDataAdapter da ;
try
{
cnn.Open();
da = new MySqlDataAdapter(sql, cnn);
da.Fill(ds);
// Create a pie series.
DataTable dt = new DataTable() { TableName = "Table" };
ds.Tables.Add(dt);
gridControl1.DataSource = ds.Tables[0].DefaultView;
chart1.DataSource = ds;
chart1.SeriesDataMember = "Table";
chart1.Series.Add(ISeries);
chart1.Series 1 = "HSERV";
s1.ValueDataMembers[0] = "c";
this.Controls.Add(chart);
chart.DataBind();
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! " + ex.Message);
}
}
}
}
using DevExpress.XtraCharts;
using MySql.Data.MySqlClient;
using MySqlX.XDevAPI.Relational;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.Charts.Native;
namespace WindowsFormsApp1
{
public partial class FormSendReport : Form
{
public FormSendReport()
{
InitializeComponent();
}
string ConString = "Server=127.0.0.1;Database=r506;Uid=root;ConvertZeroDateTime=True;";
private void FormSendReport_Load(object sender, EventArgs e)
{
MySqlConnection cnn = new MySqlConnection(ConString);
DataSet ds = new DataSet();
string sql = "SELECT e.HSERV,COUNT(*) as c " +
"FROM epe0 e " +
"GROUP BY e.HSERV";
MySqlDataAdapter da ;
try
{
cnn.Open();
da = new MySqlDataAdapter(sql, cnn);
da.Fill(ds);
// Create a pie series.
DataTable dt = new DataTable() { TableName = "Table" };
ds.Tables.Add(dt);
gridControl1.DataSource = ds.Tables[0].DefaultView;
chart1.DataSource = ds;
chart1.SeriesDataMember = "Table";
chart1.Series.Add(ISeries);
chart1.Series 1 = "HSERV";
s1.ValueDataMembers[0] = "c";
this.Controls.Add(chart);
chart.DataBind();
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! " + ex.Message);
}
}
}
}
วันพุธที่ 22 เมษายน พ.ศ. 2563
chart
using DevExpress.XtraCharts;
-----------------------------------------------------------------
private void Form1_Load(object sender, EventArgs e)
{
MySqlConnection cnn = new MySqlConnection(ConString);
string sql = "SELECT hserv,COUNT(*) c " +
"FROM epe0 " +
"GROUP BY HSERV " +
"ORDER BY count(*) DESC";
try
{
cnn.Open();
StatusLabel1.Text = "Connected !!";
StatusLabel1.ForeColor = Color.Green;
cnn.Close();
}
catch (Exception ex)
{
// MessageBox.Show("Can not open connection ! " + ex.Message);
StatusLabel1.Text = "UnConnected !!";
StatusLabel1.ForeColor = Color.Red;
}
finally
{
}
try
{
cnn.Open();
DataTable dt = new DataTable() ;
DataSet ds = new DataSet();
MySqlCommand cmd = new MySqlCommand(sql, cnn);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
//MySqlDataReader rdr = cmd.ExecuteReader();
da.Fill(dt);
da.Fill(ds, "Table");
gridControl1.DataSource = ds.Tables[0].DefaultView;
DevExpress.XtraCharts.Series series1 = new DevExpress.XtraCharts.Series("A Pie Series", ViewType.Bar);
chartControl1.DataSource = ds.Tables[0].DefaultView;
// chartControl1.SeriesDataMember = "Table";
chartControl1.Series.Add(series1);
series1.ArgumentDataMember = "hserv";
series1.ValueDataMembers[0] = "c";
// this.Controls.Add(chartControl1);
//chartControl1.da
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error ! " + ex.Message);
}
วันอังคารที่ 21 เมษายน พ.ศ. 2563
check form open
bool IsOpen = false;
foreach (Form f in Application.OpenForms)
{
if (f.Text == "Send506Form")
{
IsOpen = true;
f.Focus();
f.Dock = DockStyle.Fill;
f.WindowState = FormWindowState.Normal;
f.MaximizeBox = false;
f.MinimizeBox = false;
f.Show();
// break;
}
}
if (IsOpen == false)
{
Send506Form f2 = new Send506Form();
f2.MdiParent = this;
f2.Dock = DockStyle.Fill;
f2.MaximizeBox = false;
f2.MinimizeBox = false;
f2.Show();
}
foreach (Form f in Application.OpenForms)
{
if (f.Text == "Send506Form")
{
IsOpen = true;
f.Focus();
f.Dock = DockStyle.Fill;
f.WindowState = FormWindowState.Normal;
f.MaximizeBox = false;
f.MinimizeBox = false;
f.Show();
// break;
}
}
if (IsOpen == false)
{
Send506Form f2 = new Send506Form();
f2.MdiParent = this;
f2.Dock = DockStyle.Fill;
f2.MaximizeBox = false;
f2.MinimizeBox = false;
f2.Show();
}
c# การเชื่อมต่อ Mysql
using MySql.Data;
using MySql.Data.MySqlClient;
-----------------------------------
public Form1()
{
InitializeComponent();
}
string ConString = "Server=127.0.0.1;Database=r506;Uid=root;ConvertZeroDateTime=True;";
private void Form1_Load(object sender, EventArgs e)
{
MySqlConnection cnn = new MySqlConnection(ConString);
try
{
cnn.Open();
//MessageBox.Show("Connection Open ! ");
StatusLabel1.Text = "Connected !!";
StatusLabel1.ForeColor = Color.Green;
}
catch (Exception ex)
{
// MessageBox.Show("Can not open connection ! " + ex.Message);
StatusLabel1.Text = "UnConnected !!";
StatusLabel1.ForeColor = Color.Red;
}
finally
{
cnn.Close();
}
}
using MySql.Data.MySqlClient;
-----------------------------------
public Form1()
{
InitializeComponent();
}
string ConString = "Server=127.0.0.1;Database=r506;Uid=root;ConvertZeroDateTime=True;";
private void Form1_Load(object sender, EventArgs e)
{
MySqlConnection cnn = new MySqlConnection(ConString);
try
{
cnn.Open();
//MessageBox.Show("Connection Open ! ");
StatusLabel1.Text = "Connected !!";
StatusLabel1.ForeColor = Color.Green;
}
catch (Exception ex)
{
// MessageBox.Show("Can not open connection ! " + ex.Message);
StatusLabel1.Text = "UnConnected !!";
StatusLabel1.ForeColor = Color.Red;
}
finally
{
cnn.Close();
}
}
c# เปลี่ยนสีตัวอักษรใน statusBar
using System.Drawing;
-------------------------------
StatusLabel1.Text = "Connected !!";
StatusLabel1.ForeColor = Color.Green;
-------------------------------
StatusLabel1.Text = "Connected !!";
StatusLabel1.ForeColor = Color.Green;
สมัครสมาชิก:
บทความ (Atom)