C50108
  • 2019/0801/轉職成功路途開始
  • 自學心得與此網站使用方式
  • 行事曆&課程大綱
  • 2019/0224/自我檢視
  • 雜記
    • 2019/0103/雜記
    • 2019/0410/作品集建構
    • 2019/0429/職訓局書單
    • 2019/0317/自我檢視
    • 2019/0316/陪玄松去高車討論&環境圖流程圖大神們line討論
    • 2019/0305/Gitbook使用方法
  • 2018/10XX/轉職心路歷程
  • 職訓局里程碑
    • 201901
      • 2019/0103/行動商務系統設計與開發,職訓局報到
      • 2019/0104/正式開課日&行動商務課程簡介
      • 2019/0108/資料庫理論/Access&WEB開發簡介
      • 2019/0109/資料庫資料型態屬性&HTMLtag
      • 2019/0110/計概基礎概念
      • 2019/0111/HTML表格table&form表單_post/get&iframe
      • 2019/0114/計&網概概念&網路層概念
      • 2019/0115/資料庫Access運算值&CSS簡介&在職班補充
      • 2019/0116/Access比較/邏輯運算&CSS_在職班補充+選擇器+Box model
      • 2019/0117/資訊系統架構&網路層
      • 2019/0118/資料庫正規化
      • 2019/0121/計概IT分工&資料庫正規化
      • 2019/0122/網路層&CSS父子容器切版
      • 2019/0123/Access資料庫關聯&CSS position&偵錯
      • 2019/0124/C#宣告、指定運算子
      • 2019/0125/VM虛擬機_基礎介紹
      • 2019/0128/VM虛擬機架設_虛擬網卡設定&伺服器權限設置
      • 2019/0129/Wireshark查詢網路層&資料庫物件導向
      • 2019/0130/ERmod雞爪圖&C#if、for時間複雜度
      • 2019/0131/C#流程控制&變數型別
    • 201902
      • 2019/0201/系統分析與設計_資料庫ERmod&c#Homework
      • 2019/0211/ASP.NET_Webforms&物件命名空間
      • 2019/0212/定址&網路遮罩
      • 2019/0213/SQLSeverM.S.介紹&AspWebforms表單控制項
      • 2019/0214/網概乙太網路&網路安全
      • 2019/0215/Pre Javascript 基礎 & 在職班補充
      • 2019/0218/TSQL基本指令&ASP.net左右置換表格/驗證傳值
      • 2019/0219/Javascript終極密碼&musicplay&asp.net驗證器
      • 2019/0220/SS基本語法&網概line機器人
      • 2019/0221/前端Javascript musicplay、內聚力耦合率
      • 2019/0222/前端Javascript musicplay、內聚力耦合率&伺服器權限
      • 2019/0223/SqlServerHomework&第一次專案報告
      • 2019/0225/SS合併查詢&ASP.NET驗證器
      • 2019/0226/伺服器ntfs安全性權限/共用權限
      • 2019/0227/Javascript_music_play_end&ASP.net串聯SQL(datasource就是拿來串SQLServer的)
    • 201903
      • 2019/0304/SS集合運算/子查詢/exists&asp.net GridView 事件 OnRowDataBound
      • 2019/0305/SS查詢式end&ASP.NET_Gridview_自訂樣式分頁
      • 2019/0306/Javascript musicplay_really_end
      • 2019/0307/前端HTML5鑲嵌字型&伺服器網域概念
      • 2019/0308/Android Studio_基礎概念&開發環境建置
      • 2019/0311/胡中興 工業4.0講習
      • 2019/0312/安卓系統_開發基礎介紹
      • 2019/0313/安卓工作室_基礎/布局內元件
      • 2019/0314/Asp.net鏈結資料庫-查詢
      • 2019/0315/SQS DML&第二次專案報告
      • 2019/0318/SQL DDL & 伺服器 自學基礎
      • 2019/0319/Android Studio_布局內元件&佈局規劃元件
      • 2019/0320/SQL檢視表&tsql基礎&Asp.net_Gridview
      • 2019/0321/TSQL&TDM&ASP.NET_Datalist
      • 2019/0322/DOM&JQ基礎&系統分析設計PPT&在職班補充
      • 2019/0325/TMD&Asp.net上傳圖片/產生QRCode
      • 2019/0326/SQLServer_預存程序+函數&Asp.net_Webforms半自動鏈結資料庫與自動化更新
      • 2019/0327/安卓工作室_佈局規劃元件
      • 2019/0328/jQuery選擇器應用&Ajax導讀+應用&asp.net串sserver_註冊帳號功能
      • 2019/0329/ADDS伺服器架設&第三次專題報告
    • 201904
      • 2019/0401/SQL觸發程序&Asp.net自動寄信&認證信
      • 2019/0402/前端作業四-jQ應用轉換樣式&ASP.NET_FormView控制項-會員資料維護實例
      • 2019/0403/JQ事件動畫&股市&Usecase
      • 2019/0408/安卓工作室_元件/布局基本end
      • 2019/0409/安卓工作室-物件導向事件驅動實作+Homework1&2
      • 2019/0410/上午小組討論-作品集自習&Visual studio webform+MVC範本
      • 2019/0411/安卓工作室-UI觸發委派函式與控制物件
      • 2019/0412/JQ動畫實做(寶可夢遊戲開場)&第四次專題報告
      • 2019/0415/前端JQ-Ajax+JSON&後端ADO建置、主板頁面概念控制項、Bootstrap演示
      • 2019/0416/安卓工作室UI控件案例結束、IDE Eclipse_Java物件導向基礎
      • 2019/0417/伺服器網域ADDNS&416LINE討論
      • 2019/0418/SQL指標、索引&Use cace
      • 2019/0419/主頁、Webform ADO.NET Entity Fromwork 增刪修實作&第五次專題報告
      • 2019/0423/Java基礎(型別/溢位/自動強制型別轉換/鑄造物件/串流/)&I/O物件用法(底層/較不底層)
      • 2019/0424/Bootstrap_RWD基礎/應用&Asp.Net_MVC實作增刪修(修待補)
      • 2019/0425/伺服器IIS安裝&資料匯入與管理
      • 2019/0426/Asp.Net_MVC增刪修實作(補修)&bootstrap – gridsystem– 網格系統&第六次專題報告&全國技能競賽網頁設計
      • 2019/0429/物件導向技術原理方法實作
      • 2019/0430/資料庫設計應用效能調教_SQL all end&ASP.NET_MVC_Controller單元_純C無V無M操作/簡單複雜繫結
    • 201905
      • 2019/0501/內部網站辨識&外部DNS域名/IP+自架DNS伺服器理解
      • 2019/0502/Java語言基礎、物件導向基礎
      • 2019/0503/Asp.net泛型處理常式驗證圖片應用&第七次專題報告Usecase
      • 2017/0506/Bs_FlexBox&Asp.Net_MVC_View+Razor@+Viewbag+helper
      • 2019/0507/Java 物件導向_類別+函式觀念&階段性作業三
      • 2019/0508/Asp.Net_MVC_Model_ADO.NET+Entityframework+LoginMember實作+MVC觀念
      • 2019/0509/Java物件導向(函式)_儲存型態+回傳值+多載+自制+例外處理+this參照+存取+複合
      • 20919/0510/第八次專題報告=功能DEMO
      • 2019/0514/Java_靜態類別+繼承特性
      • 2019/0515/RWD Utility+Card&MVC ViewModel+CRUD(RD)
      • 2019/0516/BS form&驗證+JQ驗證 & MVC_CRUD(CU)
      • 2019/0517/ASP.NET Webform介紹Master page 主頁 & Session 簡介 & 登入login驗證 & 隱碼攻擊injection & 工具箱程式碼片段使用
      • 2019/0520/繼承&存取權特性+java作業四+字符串格式化+多形+抽象類別
      • 2019/0521/抽象類別+介面
      • 2019/0522/Bootstrap Components 元件介紹 + MVC API 概念&實作
      • 2019/0523/IIS IP限制&ASP.NET部屬
      • 2019/0524/WebApi異質程式連線方式&第九次專題報告_循序圖
      • 2019/0528/Bootstrap Components 元件介紹 + MVC 登入驗證 + 商品加入購物車 實作
      • 2019/0529/ASP.NET_MVC購物車訂單功能完成+BootstrapComponents元件介紹
      • 2019/0530/原本是伺服器的課,但拿來做專題。
      • 2019/0531/ASP.NET_WebformAllView物件功能清單&ListView實作&第十次專案報告(完整循序圖)
    • 201906
      • 2019/0603/Bootstrap Components RWD End + ASP.NET_MVC Part2 PhotoSharing CodeFirst & Model 驗證
      • 2019/0604/ASP.NET_MVC Part2 PhotoSharing Controller & Filter & ADO.NET & View@RAZOR Helper
      • 2019/0605/Java介面實作&結束+安卓工作室(整合Layout與Java)Intent意圖&Bundle包裹
      • 2019/0606/第十一次專案報告功能demo+SingnaIR+伺服器作業+端午歌唱比賽
      • 2019/0609/黃大神傳授Visual_Studio&除錯技巧
      • 2019/0610/番外篇 Web Socket 即時連線& 就業前準備與技巧
      • 2019/0611/安卓工作室_(意圖+隱含意圖)資料傳遞+Android生命週期+硬體裝置與應用
      • 2019/0612/WebSockets Notification + MVC Part2 PhotoSharing PartialView & ADO.NET & EntitySQL & VMd
      • 2019/0613/MVC Part2 PhotoSharing ViewModel & ErrorHandle
      • 2019/0614/第十二次專案報告 功能Demo
      • 2019/0618/MVC Part2 PhotoSharing Route & Sitemap & _LayOut & AJAX
      • 2019/0618/RWD在職班_(Javascript_object-oriented programming)
      • 2019/0619/安卓工作室_(硬體裝置與應用)相機操作&GPS+階段性作業6+延伸 ( APP End )
      • 2019/0620/MVC補充C#MS SQL匯入CSV+上傳CSV存入MS SQL
      • 2019/0621/第十三次專案報告 功能Demo
    • 2019/0701/最終專案報告
    • 2019/0702/結訓與家人遊台東預計0708開始找工作自學筆記應該會等工作穩定後繼續開始
  • 自學里程碑
    • 201901
      • 2019/0107/DR
      • 2019/0108/UW
      • 2019/0103/Git
      • 2019/0103/CS
      • 2019/0115/Vscode
      • 2019/0116/JSON&AJAX
      • 2019/0122/卡內基
      • 2019/0126/MBTI
      • 2019/0131/PDP 外在 內在
    • 201902
      • 2019/0217/huli_half Developer
      • 2019/0219/SEO
      • 2019/0219/雪球速讀法
    • 201903
      • 2019/0304/asp、php、jsp、asp.net、net. Framework、asp.net core
      • 2019/0329/網站架站初嘗試
    • 201904
      • 2019/0415/Datatype-Explanation
      • 2019/0416/ASP.NET_Webform&Core&MVC(MVVM/MVP)
    • 201905
      • 2019/0613/開發職訓局共同專案時遇到的問題與解法
      • 2019/0514/ASP.NET SignalR
      • 2019/0514/JS擴展-JQ、React、Vue、Angular...
      • 2019/0514/Sass&Scss
      • 2019/0514/MVC結合Webform
      • 2019/0515/ASP.NET MVC_TempData/ViewData/ViewBag
      • 2019/0522/[自學筆記]海綿體啟蒙??
Powered by GitBook
On this page
  • TMD案例
  • 視覺化的關聯圖
  • sql ddl scrip
  • SQL Server資料庫圖表
  • SQL 物件 預存程序 Stored Procedure
  • 建立
  • 使用
  • 傳遞參數
  • asp.net gridview 串 預存程序
  • datalist
  • 更新圖片
  • 1.必須秀原圖在畫面上
  • 2.上傳圖片功能 ( 接收資料具有高度危險性 ( 判斷限制假設有驗證器 ( 上傳沒成功
  • 3.按下更新按鈕後,回寫資料庫複寫 ( 複寫失敗
  • 4. 取消案扭 ( 編輯狀態轉為唯讀狀態
  • 5. chrome 執行只會抓到伺服器端檔名 不會抓到伺服器端路徑
  • 6.網頁上catch
  • QRcode
  • 產生
  • 相同名字不同物件就會有模玲兩可產生必須寫完整類別名稱
  • gridview 加上 qrcode 檔案第21個
  • ado.net明日 正規用法 不是 datasorse

Was this helpful?

  1. 職訓局里程碑
  2. 201903

2019/0325/TMD&Asp.net上傳圖片/產生QRCode

Previous2019/0322/DOM&JQ基礎&系統分析設計PPT&在職班補充Next2019/0326/SQLServer_預存程序+函數&Asp.net_Webforms半自動鏈結資料庫與自動化更新

Last updated 6 years ago

Was this helpful?

TMD案例

視覺化的關聯圖

關係實體 一個課程 有 多個測驗 ,有的課程沒有考試 但有考試一定有課程

編碼規則系統設計師會標註

nvarchar 變動長度

測驗種類 遞移相依問題 但這裡依照圖施工不考慮

實體本身就有pk就不用pfk所以使用fk 不可被識別的多對1

學生 多對多於 測驗 具有 明細

多質屬性 轉資料表原則 要獨立一張資料表 自為一實體

要有一個自己的pk 但通常不太據原生意義 ( 流水號

但這個pk是因為學生跟地址為1對多 但不曉得學生會填幾筆資料

組合鍵

弱實體 與 強實體差別 在於 弱實體依附強實體 ( 弱實體本身沒有pk 強消失弱也消失

TMD轉為圖檔

sql ddl scrip

create database hw5

go

use hw5

go

/*
Created		2019/3/21
Modified		2019/3/25
Project		
Model			
Company		
Author		
Version		
Database		MS SQL 2005 
*/


Create table [Students]
(
	[學號] Char(4) NOT NULL,
	[姓名] Nvarchar(20) NOT NULL,
	[性別] Bit NOT NULL,
	[電話] Varchar(16) NULL,
	[生日] Datetime NULL,
Primary Key ([學號])
) 
go

Create table [課程]
(
	[課程編號] Char(1) NOT NULL,
	[名稱] Nvarchar(20) NULL,
	[學分] Integer NOT NULL,
Primary Key ([課程編號])
) 
go

Create table [班級]
(
	[學號] Char(4) NOT NULL,
	[教授編號] Char(4) NOT NULL,
	[課程編號] Char(1) NOT NULL,
	[上課時間] Datetime NOT NULL,
	[教室] Varchar(8) NOT NULL,
Primary Key ([學號],[教授編號],[課程編號])
) 
go

Create table [教授]
(
	[教授編號] Char(4) NOT NULL,
	[科系] Varchar(5) NOT NULL,
	[職稱] Nvarchar(4) NOT NULL,
	[身份證字號] Char(10) NULL,
Primary Key ([教授編號])
) 
go

Create table [員工]
(
	[身份證字號] Char(10) NOT NULL,
	[姓名] Nvarchar(20) NOT NULL,
	[電話] Varchar(16) NULL,
	[城市] Nvarchar(4) NOT NULL,
	[街道] Nvarchar(10) NOT NULL,
	[薪水] Money NOT NULL,
	[保險] Money NOT NULL,
	[扣稅] Money NOT NULL,
Primary Key ([身份證字號])
) 
go

Create table [測驗]
(
	[測驗編號] Char(4) NOT NULL,
	[名稱] Nvarchar(20) NOT NULL,
	[種類] Char(1) NULL,
	[課程編號] Char(1) NULL,
Primary Key ([測驗編號])
) 
go

Create table [結果]
(
	[測驗編號] Char(4) NOT NULL,
	[學號] Char(4) NOT NULL,
	[成績] Integer NOT NULL,
	[日期] Datetime NOT NULL,
Primary Key ([測驗編號],[學號])
) 
go

Create table [地址]
(
	[地址流水號] Bigint Identity NOT NULL,
	[地址] Nvarchar(30) NOT NULL,
	[學號] Char(4) NOT NULL,
Primary Key ([地址流水號],[學號])
) 
go

Create table [家長]
(
	[姓名] Nvarchar(20) NOT NULL,
	[關係] Nvarchar(4) NULL,
	[學號] Char(4) NOT NULL,
Primary Key ([姓名],[學號])
) 
go


Alter table [班級] add  foreign key([學號]) references [Students] ([學號])  on update no action on delete no action 
go
Alter table [結果] add  foreign key([學號]) references [Students] ([學號])  on update no action on delete no action 
go
Alter table [地址] add  foreign key([學號]) references [Students] ([學號])  on update no action on delete no action 
go
Alter table [家長] add  foreign key([學號]) references [Students] ([學號])  on update no action on delete no action 
go
Alter table [班級] add  foreign key([課程編號]) references [課程] ([課程編號])  on update no action on delete no action 
go
Alter table [測驗] add  foreign key([課程編號]) references [課程] ([課程編號])  on update no action on delete no action 
go
Alter table [班級] add  foreign key([教授編號]) references [教授] ([教授編號])  on update no action on delete no action 
go
Alter table [教授] add  foreign key([身份證字號]) references [員工] ([身份證字號])  on update no action on delete no action 
go
Alter table [結果] add  foreign key([測驗編號]) references [測驗] ([測驗編號])  on update no action on delete no action 
go


Set quoted_identifier on
go


Set quoted_identifier off
go


SQL Server資料庫圖表

SQL 物件 預存程序 Stored Procedure

TSQL 涉及資料操作等等的 將程式寫好 等需要時再執行

資料庫資料操作與定譯 ,

select 的程序能存成view 就類似預存程序

但不是所有程序都可以存成view

建立

create Procedure 程序名稱

可簡寫 Proc

as begin 程序內容 end

--預存程序Stored Procedure
--建立
create Proc 學生選課總筆數
as
begin
	select 班級.教授編號,員工.姓名,教授.科系,教授.職稱,班級.學號,學生.姓名,學生.性別, 
	班級.課程編號,課程.名稱,課程.學分,班級.上課時間,班級.教室
	from 班級 
	inner join 學生 on 班級.學號=學生.學號 
	inner join 課程 on 班級.課程編號=課程.課程編號
	inner join 教授 on 班級.教授編號=教授.教授編號
	inner join 員工 on 教授.身份證字號=員工.身份證字號
	order by 學生.學號

	print '共有'+cast(@@rowcount as varchar)+'筆選課資料!!'
end

使用

--執行預存程序
execute 學生選課總筆數
--簡寫
exec 學生選課總筆數

exec 如果後面是一整串字串後面可以當作命令執行

--再談execute
declare @tablename varchar(30)
set @tablename='學生'
exec('select * from '+@tablename)
--------------------------------------
declare @procname varchar(30)
set @procname='學生選課明細'

exec @procname

功能會有括弧可傳遞參數 那預存程序要如何傳遞參數呢?

傳遞參數

創建

as 前定義名稱 資料型態

--有參數的預存程序
create proc 學生查詢
	@name varchar(12)
as
begin

	select * from 學生
	where 姓名 like '%'+  @name+ '%'
end

使用

exec 學生查詢 @name='張'
exec 學生查詢 '張'

asp.net gridview 串 預存程序

具有隱藏資訊的特點

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:教務系統ConnectionString %>" 
SelectCommand="學生選課明細" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"></asp:GridView>

傳參數 1.設置輸入框 2.確認參數資料型態

 輸入姓名關鍵字:<asp:TextBox ID="txtName" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="查詢" />

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
ConnectionString="<%$ ConnectionStrings:教務系統ConnectionString %>" 
SelectCommand="學生查詢" SelectCommandType="StoredProcedure">

<SelectParameters>
<asp:ControlParameter Name="name" ControlID="txtName" Type="String" />
</SelectParameters>


</asp:SqlDataSource>

<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource2"></asp:GridView>

datalist

唯讀畫面->編輯畫面

按下發送->回寫資料庫

更新圖片

1.必須秀原圖在畫面上

    Product_Img:
                    <img src='ProductsImg/s<%# Eval("Product_Img") %>' />

2.上傳圖片功能 ( 接收資料具有高度危險性 ( 判斷限制假設有驗證器 ( 上傳沒成功

控制項 fileupload

後端鑄造物件用於抓更新值

先在後端判斷前端控制器是否有抓到東西 判斷是否有上傳檔案

監看式可以看檔名等等 也可用於除錯

做限制判斷圖檔 ( 判斷副檔名是不準的 (對方可以把病毒附檔為jpg

contentlength 檔案大小

contenttype 檔案類型

| | 或

呼叫方法 saveas 路徑+img.filename原主檔名+副檔名 ( 寫邏輯判斷副檔名 )

但今天不是要用原檔名而是利用pk當作檔名這樣才能夠讓資料庫後續可以回傳

mapping邏輯路徑對應相對路徑 呼叫物件來用

server.mappath 去找伺服器絕對路徑


        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if(e.CommandName=="Edit")
            {
                DataList1.EditItemIndex = e.Item.ItemIndex;
                DataBind();

                int index = e.Item.ItemIndex;
                string status = ((Label)DataList1.Items[index].FindControl("lblProduct_Status")).Text;
                RadioButtonList rbl = (RadioButtonList)DataList1.Items[index].FindControl("rblProduct_Status");
             
                if (status == "True")
                {
                    rbl.Items[0].Selected = true;
                }
                else
                    rbl.Items[1].Selected = true;

            }
            else if (e.CommandName == "Cancel")
            {
                DataList1.EditItemIndex = -1;
                DataBind();

            }

*問題是照片大小版面呢? (實務上通常是修改到完整大小才可更新

分別using 可以少寫一些

將一張圖鑄造成image物件

抓客戶端檔案路徑轉到參數中

讓客戶端檔案能夠轉到物件中

抓客戶端檔案格式轉至物件中

重新畫一張大圖 360*360

圖形驗證 QRcod都是用bitmap

  //上傳新的產品圖檔
            FileUpload img=(FileUpload)e.Item.FindControl("fulProductsImg");
            Label proID = (Label)e.Item.FindControl("Product_IDLabel");

            if (img.FileName!="")
            {
                System.Drawing.Image g = System.Drawing.Image.FromFile(img.PostedFile.FileName);
                ImageFormat imgformat = g.RawFormat;
                Bitmap newImg = new Bitmap(g,360,360);
                Bitmap newSImg = new Bitmap(g, 120, 120);


                if (img.PostedFile.ContentType == "image/jpeg")
                {
                    newImg.Save(Server.MapPath("/ProductsImg/" + proID.Text + ".jpg"));
                    newSImg.Save(Server.MapPath("/ProductsImg/s" + proID.Text + ".jpg"));
                    //img.SaveAs(Server.MapPath("/ProductsImg/" + proID.Text + ".jpg"));
                }
                else if (img.PostedFile.ContentType == "image/png")
                {
                    newImg.Save(Server.MapPath("/ProductsImg/" + proID.Text + ".png"));
                    newSImg.Save(Server.MapPath("/ProductsImg/s" + proID.Text + ".png"));
                    //img.SaveAs(Server.MapPath("/ProductsImg/" + proID.Text + ".png"));
                }

            }

3.按下更新按鈕後,回寫資料庫複寫 ( 複寫失敗

commandname重要=update

確認有無重新整理 ( post back

屬性 OnUpdateCommand 功能名稱

後端 將所有需要回寫的資料 鑄造物件 ( 包含索引直 pk ) 用於抓更新\值

前端 UpdateCommand 設置

讀取後端參數設置 ( 包含索引直 pk

將參數餵給後端變數 並寫入資料庫 ( 包含索引直 pk

並轉為唯讀程式

前端

<div>
            <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" 
                RepeatColumns="3" CellSpacing="20" RepeatDirection="Horizontal"
                 OnItemCommand="DataList1_ItemCommand"
                  OnUpdateCommand="DataList1_UpdateCommand"
                >
     
                  
                  <ItemTemplate>
                    <div style="text-align:center">
                        <asp:Button ID="Button1" runat="server" Text="編輯資料" CommandName="Edit" />
                        <%--<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Select"> <%# Eval("Product_id") %></asp:LinkButton>--%>
                        <br />

                        <img src='ProductsImg/s<%# Eval("Product_Img") %>' />
                        <br />
                        <asp:Label ID="Label2" runat="server" Font-Names="微軟正黑體" Font-Bold="true" Font-Size="14pt" Text='<%# Eval("Product_Name") %>' />
                        <br />
                        原價:
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Product_Price","{0:C0}") %>' ForeColor="#999999" CssClass="line_through" />
                        <br />
                        特價:
                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("Product_Price2","{0:C0}") %>' ForeColor="#ff0066" Font-Names="Arial Black" Font-Size="18pt" />
                    </div>
                </ItemTemplate>

            <EditItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update">更新</asp:LinkButton>
                <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel">取消</asp:LinkButton>
                <br />
                <asp:Label ID="lblProduct_Status" runat="server" Text='<%# Eval("Product_Status") %>'></asp:Label>
           
                    Product_ID:
                    <asp:Label ID="Product_IDLabel" runat="server" Text='<%# Eval("Product_ID") %>' />
                    <br />
                    Product_Name:
                  
                <asp:TextBox ID="txtProduct_Name" runat="server" Text='<%# Eval("Product_Name") %>' Width="200"></asp:TextBox>
                    <br />
                    Product_Img:
                    <img src='ProductsImg/s<%# Eval("Product_Img") %>' /><br />
                    <asp:FileUpload ID="fulProductsImg" runat="server" />
                    <br />
                    Product_Price:
                 
                <asp:TextBox ID="txtProduct_Price" runat="server" Text='<%# Eval("Product_Price","{0:0}") %>' Width="100"></asp:TextBox>
                    <br />
                    Product_price2:
          
                <asp:TextBox ID="txtProduct_Price2" runat="server" Text='<%# Eval("Product_Price2","{0:0}") %>' Width="100"></asp:TextBox>
                    <br />
                    Product_Intro:
              
                <asp:TextBox ID="txtProduct_Intro" runat="server" TextMode="MultiLine" Text='<%# Eval("Product_Intro") %>' Width="200" Height="100"></asp:TextBox>
                    <br />
                    Product_Status:
              
                <asp:RadioButtonList ID="rblProduct_Status" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Text="上架" Value="1"></asp:ListItem>
                    <asp:ListItem Text="下架" Value="0"></asp:ListItem>
                </asp:RadioButtonList>
                    <br />

            </EditItemTemplate>
                  
            </asp:DataList>
             <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:MySystemConnectionString1 %>" 
                SelectCommand="SELECT * FROM [Products]"
                  UpdateCommand="update Products set Product_Name=@Product_Name, Product_Price=@Product_Price, 
                 Product_Price2=@Product_Price2, Product_Intro=@Product_Intro, Product_Status=@Product_Status where Product_ID=@Product_ID"
                 >
                    <UpdateParameters>
                        <asp:Parameter Name="Product_Name" Type="String" />
                        <asp:Parameter Name="Product_Price" Type="Int32" />
                        <asp:Parameter Name="Product_Price2" Type="Int32" />
                        <asp:Parameter Name="Product_Intro" Type="String" />
                        <asp:Parameter Name="Product_Status" Type="Int16" />
                        <asp:Parameter Name="Product_ID" Type="String" />
                    </UpdateParameters>



             </asp:SqlDataSource>
        </div>

後端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPnet
{
    public partial class _27DataList_Edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if(e.CommandName=="Edit")
            {
                DataList1.EditItemIndex = e.Item.ItemIndex;
                DataBind();

                int index = e.Item.ItemIndex;
                string status = ((Label)DataList1.Items[index].FindControl("lblProduct_Status")).Text;
                RadioButtonList rbl = (RadioButtonList)DataList1.Items[index].FindControl("rblProduct_Status");
             
                if (status == "True")
                {
                    rbl.Items[0].Selected = true;
                }
                else
                    rbl.Items[1].Selected = true;

            }
            else if (e.CommandName == "Cancel")
            {
                DataList1.EditItemIndex = -1;
                DataBind();

            }
          
        }

        protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
        {
            //上傳新的產品圖檔

            //資料回寫資料庫
            TextBox name =(TextBox)e.Item.FindControl("txtProduct_Name");
            TextBox price = (TextBox)e.Item.FindControl("txtProduct_Price");
            TextBox price2 = (TextBox)e.Item.FindControl("txtProduct_Price2");
            TextBox intro = (TextBox)e.Item.FindControl("txtProduct_Intro");
            RadioButtonList status = (RadioButtonList)e.Item.FindControl("rblProduct_Status");

            Label proID=(Label)e.Item.FindControl("Product_IDLabel");

            SqlDataSource1.UpdateParameters["Product_Name"].DefaultValue = name.Text;
            SqlDataSource1.UpdateParameters["Product_Price"].DefaultValue = price.Text;
            SqlDataSource1.UpdateParameters["Product_Price2"].DefaultValue = price2.Text;
            SqlDataSource1.UpdateParameters["Product_Intro"].DefaultValue = intro.Text;
            SqlDataSource1.UpdateParameters["Product_Status"].DefaultValue = status.SelectedValue;
            SqlDataSource1.UpdateParameters["Product_ID"].DefaultValue = proID.Text;

            SqlDataSource1.Update();

            DataList1.EditItemIndex = -1;
            DataBind();

        }
    }
}

4. 取消案扭 ( 編輯狀態轉為唯讀狀態

commandname重要=Cancel

確認有無重新整理 ( post back

if(e.CommandName=="Edit")
            {
                DataList1.EditItemIndex = e.Item.ItemIndex;
                DataBind();

                int index = e.Item.ItemIndex;
                string status = ((Label)DataList1.Items[index].FindControl("lblProduct_Status")).Text;
                RadioButtonList rbl = (RadioButtonList)DataList1.Items[index].FindControl("rblProduct_Status");
             
                if (status == "True")
                {
                    rbl.Items[0].Selected = true;
                }
                else
                    rbl.Items[1].Selected = true;

            }
            else if (e.CommandName == "Cancel")
            {
                DataList1.EditItemIndex = -1;
                DataBind();

            }

5. chrome 執行只會抓到伺服器端檔名 不會抓到伺服器端路徑

直接存這個上傳檔案存到某個暫存資料夾 (保持原檔名與副檔名

這樣後端就能用server上的路徑做判斷

//上傳新的產品圖檔
            FileUpload img=(FileUpload)e.Item.FindControl("fulProductsImg");
            Label proID = (Label)e.Item.FindControl("Product_IDLabel");

            if (img.FileName!="")
            {
                img.SaveAs(Server.MapPath("/tmpImage/temp.jpg"));
                img.Dispose();

                //System.Drawing.Image g = System.Drawing.Image.FromFile(img.PostedFile.FileName);
                System.Drawing.Image g = System.Drawing.Image.FromFile(Server.MapPath("/tmpImage/temp.jpg"));
                ImageFormat imgformat = g.RawFormat;
                Bitmap newImg = new Bitmap(g,360,360);
                Bitmap newSImg = new Bitmap(g, 120, 120);


                if (img.PostedFile.ContentType == "image/jpeg")
                {
                    newImg.Save(Server.MapPath("/ProductsImg/" + proID.Text + ".jpg"));
                    newSImg.Save(Server.MapPath("/ProductsImg/s" + proID.Text + ".jpg"));
                    //img.SaveAs(Server.MapPath("/ProductsImg/" + proID.Text + ".jpg"));
                }
                else if (img.PostedFile.ContentType == "image/png")
                {
                    newImg.Save(Server.MapPath("/ProductsImg/" + proID.Text + ".png"));
                    newSImg.Save(Server.MapPath("/ProductsImg/s" + proID.Text + ".png"));
                    //img.SaveAs(Server.MapPath("/ProductsImg/" + proID.Text + ".png"));
                }

            }

怕同時一堆人處理 可以將暫存檔案名稱亂數處理 ( 上面沒用

6.網頁上catch

必須將catch釋放出來 不然圖跟上傳都會報錯

 img.Dispose();

釋放物件使用

實務上會有兩頁 一頁為更新頁 一頁為預覽頁

( 最後有點聽不清楚 如果不懂這邊可以重聽

f5?

QRcode

產生

messagingtoolkit.qrcode

id 為自己打的亂碼

打物件名稱選擇正確位置自動using

graphics 也是圖形介面

 public partial class _29QR_Code : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            QRCodeEncoder encoder = new QRCodeEncoder();
            encoder.QRCodeVersion = 3;
            encoder.QRCodeScale = 20;

            string ProductID = "ufkjud8979302ikld";

            Bitmap img = encoder.Encode(ProductID);

            img.Save(Server.MapPath("/QR_Code/MyCdoe.jpg"), ImageFormat.Jpeg);

            Image1.ImageUrl = "/QR_Code/MyCdoe.jpg";
        }
    }

qrcode有芬版本

 encoder.QRCodeVersion = 3;

延展性

   encoder.QRCodeScale = 20;

相同名字不同物件就會有模玲兩可產生必須寫完整類別名稱

gridview 加上 qrcode 檔案第21個

前端

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="21GridView_BoundField.aspx.cs" Inherits="ASPnet._21GridView_BoundField" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" />
</head>
<body>
    <form id="form1" runat="server">
        <div class="container">
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MySystemConnectionString1 %>" SelectCommand="SELECT * FROM [Products]"></asp:SqlDataSource>
            <div class="table-responsive">
            <asp:GridView GridLines="None" CssClass="table table-hover" ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="Product_ID" HeaderText="Product_ID" SortExpression="Product_ID" />
                    <asp:BoundField DataField="Product_Name" HeaderText="Product_Name" SortExpression="Product_Name" />
                  <%--  <asp:BoundField DataField="Product_Img" HeaderText="Product_Img" SortExpression="Product_Img" />--%>
                    <asp:ImageField DataImageUrlField="Product_Img" DataImageUrlFormatString="~\ProductsImg\s{0}"></asp:ImageField>
                    <asp:BoundField DataField="Product_Price" DataFormatString="{0:C0}" HeaderText="Product_Price" SortExpression="Product_Price" />
                    <asp:BoundField DataField="Product_price2" DataFormatString="{0:C0}" HeaderText="Product_price2" SortExpression="Product_price2" />
                    <%--<asp:BoundField DataField="Product_Intro" HeaderText="Product_Intro" SortExpression="Product_Intro" />--%>
                    <asp:TemplateField HeaderText="Product_Intro" SortExpression="Product_Intro">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Product_Intro") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Product_Intro").ToString().Replace("\n","<br>") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CheckBoxField DataField="Product_Status" HeaderText="Product_Status" SortExpression="Product_Status" />

                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Image runat="server" ID="Image1"></asp:Image>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            </div>
        </div>
    </form>
</body>
</html>

後端

using MessagingToolkit.QRCode.Codec;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPnet
{
    public partial class _21GridView_BoundField : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowIndex != -1)
            {
                QRCodeEncoder encoder = new QRCodeEncoder();


                string ProductID = e.Row.Cells[0].Text;

                Bitmap img = encoder.Encode(ProductID);

                img.Save(Server.MapPath("/QR_Code/"+ ProductID+".jpg"), ImageFormat.Jpeg);

                ((System.Web.UI.WebControls.Image)e.Row.Cells[7].FindControl("Image1")).ImageUrl = "/QR_Code/" + ProductID + ".jpg";
            }
        }
    }
}

ado.net明日 正規用法 不是 datasorse

Bitmap 類別 (System.Drawing)docsmsft
Logo