Post by Goborijung at 2022-05-24 09:01:27 | ID: 1555
แก้ block resx file Couldn't process file resx due to its being in the Internet Couldn't process file resx due to its being in the Internet or Restricted zone or having the mark of the web on the file วิธีแก้ไข 1. เปิดไฟล์ .rrsx > คลิกขวา เลือก Properties 2. กClick 'Unblock' เป็นอันเสร็จเรียบร้อยจ้า
Post by Goborijung at 2020-09-25 11:57:41 | ID: 825
public CheckBoxInGridView() { InitializeComponent(); // ส่วนประกอบ Object เริ่มต้น in Main this.BindGrid(); // ผูก Grid เข้าไป } private void BindGrid() { SqlConnection con = new dbConn().GSSv2_Prod(); // สร้าง Connection String SqlCommand cmd = new SqlCommand("SELECT TOP 10 OID, FullName, Password FROM [User] Where GCRecord is null", con); // สร้างชุดคำสั่ง sqlCommand cmd.CommandType = CommandType.Text; // กำหนดชนิดเป็น Text SqlDataAdapter da = new SqlDataAdapter(cmd); // สร้างชุดคำสั่ง Sql เพื่อรอ Query (แล้วจะได้ Data มาเป็นก้อน) DataTable dt = new DataTable(); // สร้าง DataTable ขึ้นมาเพื่อเก็บผลลัพธ์หลังจากที่ Query เสร็จ da.Fill(dt); // ยัดหรือโยน Data ที่เป็นก้อนเข้าไปใส่ไว้ใน DataTable เพื่อรอที่จะเอาไปใช้งานต่อไป dataGridView1.DataSource = dt; //เอาข้อมูลใน DataTable ไปใส่ไว้ใน DataGridview เพื่อแสดงผลออกที่หน้าจอโปรแกรม //Add a CheckBox Column to the DataGridView at the first position. เพิ่ม Checkbox ใน Gridview ในตำแหน่งแรก DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn(); checkBoxColumn.HeaderText = "Check/UnCheck"; checkBoxColumn.Width = 30; checkBoxColumn.Name = "checkBoxColumn"; dataGridView1.Columns.Insert(0, checkBoxColumn); //เพิ่ม Checkbox เข้าไปใน Gridview ที่ Index 0 หรือ Columns แรก } private void btnGet_Click(object sender, EventArgs e) { string message = string.Empty; foreach(DataGridViewRow row in dataGridView1.Rows) //Loop แถวทั้งหมดใน Gridview { bool isSelected = Convert.ToBoolean(row.Cells["checkBoxColumn"].Value); //ดึงข้อมูลในแถวที่ row , cell ที่ checkBoxColumn ที่มีการ Selected แล้ว if (isSelected) // ถ้า Selected { message += Environment.NewLine; // ขึ้นบรรทัดใหม่ message += row.Cells["FullName"].Value.ToString(); // เอาข้อมูลใน row i, cell ที่ FullName ไปเพิ่มใน Message } } MessageBox.Show("Selected Values" + message); // show data ที่มีการ Selected เอาไว้ออกมาแสดงผลซะ จบจ้า }
Post by Goborijung at 2020-08-03 08:49:31 | ID: 91
FormBorderStyle: FixedSingle :: Font Text: Form Name(Title Name) :: Font StartPosition: CenterScreen :: Size Icon: ImageIcon :: Icon
Post by Goborijung at 2020-09-10 08:23:48 | ID: 683
>> แบบที่ 1 CellMouseClick private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if(dataGridView1.RowCount > -1) { txtOID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); } }
>> แบบที่ 2 CellContentClick private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { textBox1.Text = dataGridView1.SelectedCells.ToString(); }
Post by Goborijung at 2021-05-27 09:38:06 | ID: 1220
//string curFile = @"c: empsample.txt"; string curFile = "\172.16.0.190GSSv2_UpdateReportBarcodeGSS13CrystalReport_v3.rptx"; if (File.Exists(curFile)) { //Console.WriteLine("File exists..."); MessageBox.Show("File exists..."); } else { //Console.WriteLine("File does not exist in the current directory!"); MessageBox.Show("File does not exist in the current directory!"); }หรือ เขียนแบบย่อๆ
string curFile = @"c: emp est.txt"; Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");
Post by Goborijung at 2020-09-28 11:58:57 | ID: 833
if (myConnection.State == ConnectionState.Open) { myConnection.Dispose(); }
Post by Goborijung at 2020-09-05 14:12:25 | ID: 771
// View ColorName : https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.colors?view=netcore-3.1 private void ShowRowNumber(DataGridView dataGridView) { //dataGridView.RowHeadersWidth = 50; dataGridView.EnableHeadersVisualStyles = false; dataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue; dataGridView.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; dataGridView.ColumnHeadersDefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Bold); for (int i = 0; i < dataGridView.Rows.Count; i++) { dataGridView.Rows[i].HeaderCell.Value = (i + 1).ToString(); if (i%2 == 0) { dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.WhiteSmoke; } } }
Post by Goborijung at 2020-09-10 12:36:53 | ID: 677
string connectionString = "Server=172.16.0.xx;UID=sa;PASSWORD=xxx;Database=xxx;Max Pool Size=400;Connect Timeout=600;"; string sql = "SELECT TOP 1 * FROM TableName"; SqlConnection conn = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); conn.Open(); da.Fill(ds, "WF4"); conn.Close(); dataGridView1.DataSource = ds; dataGridView1.DataMember = "WF4";
Post by Goborijung at 2020-10-17 15:28:10 | ID: 824
>> Current Date
DateTime now = DateTime.Now;
DateTime _sDate = DateTime.Parse(dtpStartDate.Text); string sDate = _sDate.ToString("yyyy-MM-dd"); //MessageBox.Show(sDate);
DateTime _eDate = DateTime.Parse(dtpEndDate.Text); string eDate = _eDate.ToString("yyyy-MM-dd"); //MessageBox.Show(eDate);
// Convert to date Time
Convert.ToDateTime(dtpStartDate.Text).ToString("yyyy-MM-dd");
Post by Goborijung at 2020-09-22 15:12:13 | ID: 778
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace GSS13._1 { class dbConn { public string _server; public string _dbname; public string _user; public string _password; public SqlConnection GSSv2_Prod() { _server = "172.16.0.28"; _dbname = "GSSv2_Prod"; _user = "sa"; _password = "xxxx"; return new SqlConnection("Data Source="+_server+";Initial Catalog="+_dbname+";Persist Security Info=True;User ID="+_user+";Password="+_password+""); } } class dbQuery { SqlConnection conn; SqlDataAdapter da; DataSet ds; SqlCommand cmd; SqlDataReader dr; DataTable dt; // Select public DataSet SqlGet(string sql, string tblName) { conn = new dbConn().GSSv2_Prod(); da = new SqlDataAdapter(sql,conn); ds = new DataSet(); conn.Open(); da.Fill(ds,tblName); conn.Close(); return ds; } // Insert Update Delete public int SqlCmd(string sql) { int i; conn = new dbConn().GSSv2_Prod(); cmd = new SqlCommand(sql, conn); conn.Open(); i = cmd.ExecuteNonQuery(); conn.Close(); return i; } } class objForm { SqlConnection conn; SqlDataAdapter da; DataSet ds; SqlCommand cmd; SqlDataReader dr; DataTable dt; // Load data to GridView public void getDvg(string sql, DataGridView dgvName) { conn = new dbConn().GSSv2_Prod(); da = new SqlDataAdapter(sql, conn); ds = new DataSet(); conn.Open(); da.Fill(ds, "tblName"); conn.Close(); dgvName.DataSource = ds; dgvName.DataMember = "tblName"; } // GetDatatoComboBox public void GetDataToComboBox(string sql, ComboBox cboName) { conn = new dbConn().GSSv2_Prod(); cmd = new SqlCommand(sql,conn); cmd.CommandText = sql; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { cboName.Items.Add(dr[0].ToString()); } conn.Close(); } } }