protected Boolean check_itemExist() { Boolean bl_rtnflag = false; using (ODBCconn = new MyODBCConnection()) { OdbcCommand cmd = new OdbcCommand(strodbccmd); cmd.Parameters.Add("item_code", OdbcType.VarChar).Value = txtItemCode.Text; DataTable dt = ODBCconn.GetData(cmd); if (dt.Rows.Count > 0) //--資料庫裡面找不到資料 { txtItemName.Text = dt.Rows[0].Field <string>("f_desc"); txtItemPrice.Text = dt.Rows[0].Field <decimal>("amt_ex").ToString(); bl_rtnflag = true; } else { PublicLib.showAlert("資料庫無此細項代碼喔"); txtItemCode.Text = ""; txtItemName.Text = ""; txtItemPrice.Text = ""; bl_rtnflag = false; } cmd.Cancel(); ODBCconn.Dispose(); } return(bl_rtnflag); }
private void BindGrid() //新增/編輯 套餐 { DataTable dt = new DataTable(); string strcmd = "SELECT ItemCode FROM HMC_PkgD WHERE 1=0"; if (strPkgCode != null && strPkgCode != "") { strcmd = "SELECT ItemCode FROM HMC_PkgD WHERE PkgCode = @Param"; } SqlCommand cmd = new SqlCommand(strcmd); if (strPkgCode != null && strPkgCode != "") { cmd.Parameters.Add("@Param", SqlDbType.NVarChar).Value = strPkgCode; } conn = new MyConnection(); dt = conn.GetData(cmd); dt.Columns.Add("ItemName", typeof(string)); dt.Columns.Add("ItemPrice", typeof(string)); if (dt.Rows.Count == 0) { dt.Rows.Add(); } else { foreach (DataRow row in dt.Rows) //細項名稱 { string stritemCode = row["ItemCode"].ToString(); using (ODBCconn = new MyODBCConnection()) { OdbcCommand odbccmd = new OdbcCommand(strodbccmd); odbccmd.Parameters.Add("item_code", OdbcType.VarChar).Value = stritemCode; DataTable odbcdt = ODBCconn.GetData(odbccmd); if (odbcdt.Rows.Count > 0) { row["ItemName"] = odbcdt.Rows[0].Field <string>("f_desc");; row["ItemPrice"] = odbcdt.Rows[0].Field <decimal>("amt_ex"); } else { string strmsg = string.Format("代碼{0},資料庫中無此代碼", stritemCode); PublicLib.showAlert(strmsg); } odbccmd.Cancel(); ODBCconn.Dispose(); } } } ViewState["Pkg_Detail"] = dt; GridView1.DataSource = dt; GridView1.DataBind(); }