public static void LoadDataCate(ComboBox cmb, String sqlx, String id, String name,clsDatabase cls) { cmb.DataSource = cls.QueryDataTable(sqlx); cmb.DisplayMember = name; cmb.ValueMember = id; }
private string GenerateId() { try { string sql = "DECLARE @date DateTime SET @date = '" + Function.GetDate(DateTime.Now) + "' " + "SELECT 'R' + RIGHT(cast(YEAR(@date) AS int)+43,2) + " + "RIGHT('0' + CONVERT(NVARCHAR, MONTH(@date)),2) + Right('00000' + cast((SELECT isnull(max(SUBSTRING(r.RequestId,6,5)),0)+1 " + "FROM dbo.Request r WHERE year(@date) = isnull(year(r.ReqDate),null)" + "and substring(r.RequestId,1,1)='R'" + "and (MONTH(@date)) = isnull(MONTH(r.ReqDate),NULL)) as nvarchar(10)), 5)"; clsDatabase dbconn = new clsDatabase("Request"); return dbconn.QueryExecuteScalarNonAlert(sql).ToString(); } catch { throw new Exception("ไม่สามารถสร้างรหัสใบแจ้งปัญหาได้"); } }
private void frmStockMainAlls_Load(object sender, EventArgs e) { string strConn; clsDatabase clsConn = new clsDatabase(DBConnString.sDb,"192.168.0.3",""); //strConn = DBConnString.strConn; strConn = clsConn.strConnString; Conn = new SqlConnection(); if (Conn.State == ConnectionState.Open) { Conn.Close(); } Conn.ConnectionString = strConn; Conn.Open(); cbodatestop.Value = DateTime.Today; cbofind.Text = "ทั้งหมด"; countdgvAll = dgvAll.Rows.Count; lblCountRec.Text = "ผลการค้นหาพบ " + countdgvAll + " รายการ"; }