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
  • #Bootstrap
  • ##bs form class
  • ##接著form實例??
  • 重點
  • bootstrap 驗證狀態 ? 加上 jq 驗證寫法
  • keyword class 驗證產生文字位樣式
  • Keyword class 驗證欄位樣式
  • 題外話:右鍵檢查可以直接展開那個位置的程式碼
  • ##接著調整架構 (內聚力高耦合力低)
  • ##JQ 內DOM選擇器
  • #接著處理submit postback問題
  • ##最後 改成 keyboard 事件 只要有打字就觸發格式驗證
  • MVC_ CRUD 接續昨天
  • 新增
  • #接著換修改
  • #六月份會從頭做到尾一次給我們看

Was this helpful?

  1. 職訓局里程碑
  2. 201905

2019/0516/BS form&驗證+JQ驗證 & MVC_CRUD(CU)

Previous2019/0515/RWD Utility+Card&MVC ViewModel+CRUD(RD)Next2019/0517/ASP.NET Webform介紹Master page 主頁 & Session 簡介 & 登入login驗證 & 隱碼攻擊injection & 工具箱程式碼片段使用

Last updated 6 years ago

Was this helpful?

#Bootstrap

接續昨天card

可以套其他組件

學框架要懂舉一反三

積木在那裏了堆成怎樣就看各人

接著

##bs form class

Webform一頁只能有一個form標籤就是最外層那層form且屬性server就是在伺服器執行

但其實pre html 一頁可以有很多 form

友善介面 input 善用 label for id & placeholder

##Class keyword

Form-group

Form-control

Form-text

Text-muted

btn

btn-secondary

form-check

form-check-input

###/RWD/17Form.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title></title>

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <link href="MyStyle.css" rel="stylesheet" />
</head>
<body>
    <form>
        <div class="container">
            <div class="form-group">
                <label for="email">Email:</label>
                <input id="email" type="email" class="form-control" placeholder="Enter email..." required />
                <small class="form-text text-muted">忘記帳號</small>
            </div>
            <div class="form-group">
                <label for="pwd">Password:</label>
                <input id="pwd" type="password" class="form-control" placeholder="Password" required />
            </div>
            <div class="form-group form-check">
                <input id="remember" type="checkbox" class="form-check-input" />
                <label for="remember">記住我</label>
            </div>
            <input id="Submit1" type="submit" value="submit" class="btn btn-secondary" />

        </div>
    </form>
</body>
</html>

以上為上下排較制式

接著嘗試左右排

要配合gridsystem

在container內做就會遷就container的大小

##keyword

form-row

以前還要多一個div做col現在可以在 form-group那層直接col

col-md-6

以前還要每個都下 form-row

現在只要讓div在同一階層他就會自動判斷為 form-row ?

只要是form 裡面的物件 就用 form-group 然後 form-control

然後用 form-row橫排或不寫 直接直排

##接著將欄位名稱與欄位並排

###Form-group 直接當 row 底下的就都變 col 但input要用div包住下col ?? ((( legend 也是一個 div 的感覺

Col-form-label

Form-label-lg ( 字就會變大 ?

##題外話 控制項 ?

##題外話 Html tag fieldset legend

###/RWD/17Form.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title></title>

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <link href="MyStyle.css" rel="stylesheet" />
</head>
<body>


    <form>
        <div class="container">
            <div class="form-group">
                <label for="email">Email:</label>
                <input id="email" type="email" class="form-control" placeholder="Enter email..." required />
                <small class="form-text text-muted">忘記帳號</small>
            </div>
            <div class="form-group">
                <label for="pwd">Password:</label>
                <input id="pwd" type="password" class="form-control" placeholder="Password" required />
            </div>
            <div class="form-group form-check">
                <input id="remember" type="checkbox" class="form-check-input" />
                <label for="remember">記住我</label>
            </div>
            <input id="Submit1" type="submit" value="submit" class="btn btn-secondary" />

        </div>
    </form>

    <hr />

    <form>
        <div class="container">
            <div class="form-row">
                <div class="form-group col-md-6">
                    <label for="email">Email:</label>
                    <input id="email" type="email" class="form-control" placeholder="Enter email..." required />
                    <small class="form-text text-muted">忘記帳號</small>
                </div>
                <div class="form-group col-md-6">
                    <label for="pwd">Password:</label>
                    <input id="pwd" type="password" class="form-control" placeholder="Password" required />
                </div>

            </div>
            <div class="form-group">
                <label for="Address">Address:</label>
                <input id="Address" type="text" class="form-control" placeholder="Address" required />
            </div>


            <div class="form-row">
                <div class="form-group col-md-6">
                    <label for="City">City:</label>
                    <input id="City" type="text" class="form-control" placeholder="City" />
                </div>
                <div class="form-group col-md-4">
                    <label for="State">State:</label>
                    <select id="State" class="form-control">
                        <option>Choose...</option>
                        <option>111</option>
                        <option>222</option>
                    </select>
                </div>
                <div class="form-group  col-md-2">
                    <label for="abc">abc:</label>
                    <input id="abc" type="text" class="form-control" placeholder="abc" />
                </div>
            </div>
            <div class="form-group form-check">
                <input id="Agree" type="checkbox" class="form-check-input" />
                <label for="Agree">Agree</label>
            </div>

            <input id="Submit1" type="submit" value="submit" class="btn btn-secondary" />

        </div>
    </form>

    <hr />

    <form>
        <div class="container">
            <div class="form-group row">
                <label for="email" class="col-sm-3">Email:</label>
                <div class="col-sm-9">
                    <input id="email" type="email" class="form-control" placeholder="Enter email..." required />
                </div>
            </div>
            <div class="form-group row">
                <label for="pwd" class="col-sm-3 col-form-label col-form-label-lg">Password:</label>
                <div class="col-sm-9">
                    <input id="pwd" type="password" class="form-control form-control-lg" placeholder="Password" required />
                </div>
            </div>

            <fieldset class="form-group">
                <div class="row">
                    <legend class="col-form-label col-sm-3">性別</legend>
                    <div class="col-sm-9">
                        <div class="form-check">
                            <input id="male" type="radio" name="gender" />
                            <label for="male">男</label>
                        </div>
                        <div class="form-check">
                            <input id="female" type="radio" name="gender" />
                            <label for="female">女</label>
                        </div>
                    </div>
                </div>
            </fieldset>

            <div class="form-group form-check">
                <input id="remember" type="checkbox" class="form-check-input" />
                <label for="remember">記住我</label>
            </div>
            <input id="Submit1" type="submit" value="submit" class="btn btn-secondary" />

        </div>
    </form>

</body>
</html>

##接著form實例??

form-inline

sr-only ( lable會不見 ?? ( 視障者專用 ?

https://segmentfault.com/q/1010000003007829

原則 form-control 一定會有 其他都是扛拜 ??

Form-check

Form-check-input

Form-check-lable

### /RWD/18Form-2.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title></title>

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <link href="MyStyle.css" rel="stylesheet" />
</head>
<body>


    <div class="card bg-light">
        <div class="container">

            <form class="form-inline">
                <label for="email" class="sr-only">Email:</label>
                <input id="email" type="email" class="form-control mb-2 mr-sm-2" placeholder="Enter email..." required />



                <label for="pwd" class="sr-only">Password:</label>
                <input id="pwd" type="password" class="form-control mb-2 mr-sm-2" placeholder="Password" required />

                <div class="form-check mb-2 mr-sm-2">
                    <input id="remember" type="checkbox" class="form-check-input" />
                    <label for="remember" class="form-check-label">記住我</label>
                </div>
                <input id="Submit1" type="submit" value="submit" class="btn btn-secondary mb-2" />
            </form>
        </div>
    </div>

    <hr />
    <div class="container">

        <div class="textcenter">
            <h1 class="text-center">My Website</h1>
        </div>


        <div class="row">
            <div class="col-2 col-md-4 col-sm-6">
                台灣高等法院審理「W飯店女子命案」,今天做出更一審判決,認為朱家龍等人轉讓藥品與女子死亡無相當因果關係,依藥事法轉讓偽藥或禁藥罪,改判朱2年10月徒刑。


                土豪哥朱家龍(前左)被控「W飯店女模案件」。(中央社/資料照)
                更多
                「土豪哥」朱家龍被控於民國105年12月2日訂房入住W Hotel,邀約友人洪聖晏、蔡逸學舉辦毒品派對,另邀郭姓被害女子等人參加,並提供大批毒軟糖、毒梅片同歡,導致郭女於12月7日因用毒過量身亡。

                朱家龍4月初在高院更一審就W飯店命案庭做無罪答辯,強調對死者死亡結果感到抱歉,他遭押2年多,請求法官讓他交保回家向父母懺悔。他在庭上指出,對自己之前吸毒玩樂感到後悔,也對死者死亡結果感到遺憾及抱歉,已和死者家屬達成和解,法律上他應負的責任不會逃避,但他已遭押2年多,也2年多沒看到父母,希望法官能讓他交保,讓他回家向父母認錯及懺悔,他會記取這次教訓,不會再發生憾事。

                朱家龍律師表示,朱家龍已和郭女家屬達成和解,和解金也已全數匯款賠償完畢,但並未透露金額。

                蔡逸學及洪聖晏也做無罪答辯;洪聖晏表示,已與死者家屬和解,他會盡力去彌補及贖罪,過兩天就是清明節,之前奶奶過世,他都沒去上香,希望法官讓他具保停押。

                一、二審依藥事法轉讓偽藥致人於死罪判朱家龍10年徒刑;蔡逸學、洪聖晏各被判刑10年、10年6月。最高法院將朱家龍、蔡逸學、洪聖晏所涉部分發回高院更審,高院更一審今天宣判。
                台灣高等法院審理「W飯店女子命案」,今天做出更一審判決,認為朱家龍等人轉讓藥品與女子死亡無相當因果關係,依藥事法轉讓偽藥或禁藥罪,改判朱2年10月徒刑。


                土豪哥朱家龍(前左)被控「W飯店女模案件」。(中央社/資料照)
                更多
                「土豪哥」朱家龍被控於民國105年12月2日訂房入住W Hotel,邀約友人洪聖晏、蔡逸學舉辦毒品派對,另邀郭姓被害女子等人參加,並提供大批毒軟糖、毒梅片同歡,導致郭女於12月7日因用毒過量身亡。

                朱家龍4月初在高院更一審就W飯店命案庭做無罪答辯,強調對死者死亡結果感到抱歉,他遭押2年多,請求法官讓他交保回家向父母懺悔。他在庭上指出,對自己之前吸毒玩樂感到後悔,也對死者死亡結果感到遺憾及抱歉,已和死者家屬達成和解,法律上他應負的責任不會逃避,但他已遭押2年多,也2年多沒看到父母,希望法官能讓他交保,讓他回家向父母認錯及懺悔,他會記取這次教訓,不會再發生憾事。

                朱家龍律師表示,朱家龍已和郭女家屬達成和解,和解金也已全數匯款賠償完畢,但並未透露金額。

                蔡逸學及洪聖晏也做無罪答辯;洪聖晏表示,已與死者家屬和解,他會盡力去彌補及贖罪,過兩天就是清明節,之前奶奶過世,他都沒去上香,希望法官讓他具保停押。

                一、二審依藥事法轉讓偽藥致人於死罪判朱家龍10年徒刑;蔡逸學、洪聖晏各被判刑10年、10年6月。最高法院將朱家龍、蔡逸學、洪聖晏所涉部分發回高院更審,高院更一審今天宣判。
            </div>
            <div class="col-7 col-md-4 col-sm-6">
                台灣高等法院審理「W飯店女子命案」,今天做出更一審判決,認為朱家龍等人轉讓藥品與女子死亡無相當因果關係,依藥事法轉讓偽藥或禁藥罪,改判朱2年10月徒刑。


                土豪哥朱家龍(前左)被控「W飯店女模案件」。(中央社/資料照)
                更多
                「土豪哥」朱家龍被控於民國105年12月2日訂房入住W Hotel,邀約友人洪聖晏、蔡逸學舉辦毒品派對,另邀郭姓被害女子等人參加,並提供大批毒軟糖、毒梅片同歡,導致郭女於12月7日因用毒過量身亡。

                朱家龍4月初在高院更一審就W飯店命案庭做無罪答辯,強調對死者死亡結果感到抱歉,他遭押2年多,請求法官讓他交保回家向父母懺悔。他在庭上指出,對自己之前吸毒玩樂感到後悔,也對死者死亡結果感到遺憾及抱歉,已和死者家屬達成和解,法律上他應負的責任不會逃避,但他已遭押2年多,也2年多沒看到父母,希望法官能讓他交保,讓他回家向父母認錯及懺悔,他會記取這次教訓,不會再發生憾事。

                朱家龍律師表示,朱家龍已和郭女家屬達成和解,和解金也已全數匯款賠償完畢,但並未透露金額。

                蔡逸學及洪聖晏也做無罪答辯;洪聖晏表示,已與死者家屬和解,他會盡力去彌補及贖罪,過兩天就是清明節,之前奶奶過世,他都沒去上香,希望法官讓他具保停押。

                一、二審依藥事法轉讓偽藥致人於死罪判朱家龍10年徒刑;蔡逸學、洪聖晏各被判刑10年、10年6月。最高法院將朱家龍、蔡逸學、洪聖晏所涉部分發回高院更審,高院更一審今天宣判。
                台灣高等法院審理「W飯店女子命案」,今天做出更一審判決,認為朱家龍等人轉讓藥品與女子死亡無相當因果關係,依藥事法轉讓偽藥或禁藥罪,改判朱2年10月徒刑。


                土豪哥朱家龍(前左)被控「W飯店女模案件」。(中央社/資料照)
                更多
                「土豪哥」朱家龍被控於民國105年12月2日訂房入住W Hotel,邀約友人洪聖晏、蔡逸學舉辦毒品派對,另邀郭姓被害女子等人參加,並提供大批毒軟糖、毒梅片同歡,導致郭女於12月7日因用毒過量身亡。

                朱家龍4月初在高院更一審就W飯店命案庭做無罪答辯,強調對死者死亡結果感到抱歉,他遭押2年多,請求法官讓他交保回家向父母懺悔。他在庭上指出,對自己之前吸毒玩樂感到後悔,也對死者死亡結果感到遺憾及抱歉,已和死者家屬達成和解,法律上他應負的責任不會逃避,但他已遭押2年多,也2年多沒看到父母,希望法官能讓他交保,讓他回家向父母認錯及懺悔,他會記取這次教訓,不會再發生憾事。

                朱家龍律師表示,朱家龍已和郭女家屬達成和解,和解金也已全數匯款賠償完畢,但並未透露金額。

                蔡逸學及洪聖晏也做無罪答辯;洪聖晏表示,已與死者家屬和解,他會盡力去彌補及贖罪,過兩天就是清明節,之前奶奶過世,他都沒去上香,希望法官讓他具保停押。

                一、二審依藥事法轉讓偽藥致人於死罪判朱家龍10年徒刑;蔡逸學、洪聖晏各被判刑10年、10年6月。最高法院將朱家龍、蔡逸學、洪聖晏所涉部分發回高院更審,高院更一審今天宣判。
            </div>
            <div class="col-3 col-md-4">
                台灣高等法院審理「W飯店女子命案」,今天做出更一審判決,認為朱家龍等人轉讓藥品與女子死亡無相當因果關係,依藥事法轉讓偽藥或禁藥罪,改判朱2年10月徒刑。


                土豪哥朱家龍(前左)被控「W飯店女模案件」。(中央社/資料照)
                更多
                「土豪哥」朱家龍被控於民國105年12月2日訂房入住W Hotel,邀約友人洪聖晏、蔡逸學舉辦毒品派對,另邀郭姓被害女子等人參加,並提供大批毒軟糖、毒梅片同歡,導致郭女於12月7日因用毒過量身亡。

                朱家龍4月初在高院更一審就W飯店命案庭做無罪答辯,強調對死者死亡結果感到抱歉,他遭押2年多,請求法官讓他交保回家向父母懺悔。他在庭上指出,對自己之前吸毒玩樂感到後悔,也對死者死亡結果感到遺憾及抱歉,已和死者家屬達成和解,法律上他應負的責任不會逃避,但他已遭押2年多,也2年多沒看到父母,希望法官能讓他交保,讓他回家向父母認錯及懺悔,他會記取這次教訓,不會再發生憾事。

                朱家龍律師表示,朱家龍已和郭女家屬達成和解,和解金也已全數匯款賠償完畢,但並未透露金額。

                蔡逸學及洪聖晏也做無罪答辯;洪聖晏表示,已與死者家屬和解,他會盡力去彌補及贖罪,過兩天就是清明節,之前奶奶過世,他都沒去上香,希望法官讓他具保停押。

                一、二審依藥事法轉讓偽藥致人於死罪判朱家龍10年徒刑;蔡逸學、洪聖晏各被判刑10年、10年6月。最高法院將朱家龍、蔡逸學、洪聖晏所涉部分發回高院更審,高院更一審今天宣判。
                台灣高等法院審理「W飯店女子命案」,今天做出更一審判決,認為朱家龍等人轉讓藥品與女子死亡無相當因果關係,依藥事法轉讓偽藥或禁藥罪,改判朱2年10月徒刑。


                土豪哥朱家龍(前左)被控「W飯店女模案件」。(中央社/資料照)
                更多
                「土豪哥」朱家龍被控於民國105年12月2日訂房入住W Hotel,邀約友人洪聖晏、蔡逸學舉辦毒品派對,另邀郭姓被害女子等人參加,並提供大批毒軟糖、毒梅片同歡,導致郭女於12月7日因用毒過量身亡。

                朱家龍4月初在高院更一審就W飯店命案庭做無罪答辯,強調對死者死亡結果感到抱歉,他遭押2年多,請求法官讓他交保回家向父母懺悔。他在庭上指出,對自己之前吸毒玩樂感到後悔,也對死者死亡結果感到遺憾及抱歉,已和死者家屬達成和解,法律上他應負的責任不會逃避,但他已遭押2年多,也2年多沒看到父母,希望法官能讓他交保,讓他回家向父母認錯及懺悔,他會記取這次教訓,不會再發生憾事。

                朱家龍律師表示,朱家龍已和郭女家屬達成和解,和解金也已全數匯款賠償完畢,但並未透露金額。

                蔡逸學及洪聖晏也做無罪答辯;洪聖晏表示,已與死者家屬和解,他會盡力去彌補及贖罪,過兩天就是清明節,之前奶奶過世,他都沒去上香,希望法官讓他具保停押。

                一、二審依藥事法轉讓偽藥致人於死罪判朱家龍10年徒刑;蔡逸學、洪聖晏各被判刑10年、10年6月。最高法院將朱家龍、蔡逸學、洪聖晏所涉部分發回高院更審,高院更一審今天宣判。
            </div>
        </div>

    </div>

</body>
</html>

重點

要知道階層對應關係(繼承與boxmodel與prestyle) 然後才去注意class扛敗

bootstrap 驗證狀態 ? 加上 jq 驗證寫法

樣式在不同瀏覽器不同效果

Bs有提供一些驗證狀態樣式

form 屬性novalidate不要驗證 ( 表單不驗證 input 屬性 required 必填驗證 ( 但按鈕驗證

keyword class 驗證產生文字位樣式

valid-feedback invalid-feedback

必須要在js寫驗證判斷才會顯示

其實只是驗證成功失敗時扛拜一個驗證成功或失敗的 class

Keyword class 驗證欄位樣式

Is-valid Is-invalid

兩種方式 同樣都要用js先驗證判斷值出現後決定要塞class 驗證通過或驗證失敗

然後 feedback 這 可以在文本內安排通過失敗文本 或 安排一個容器 用js改變class 也可以

正規表達式包覆 /^ 開始 $/ 結束 不是雙引號

Jq 檢測 Test 方法

題外話:右鍵檢查可以直接展開那個位置的程式碼

###/RWD/19ValidationStatus.html ( 條測函式前 ( 且鎖住 submit 不讓它 postback

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title></title>

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <link href="MyStyle.css" rel="stylesheet" />
</head>
<body>


    <div class="card bg-light">
        <div class="container">

            <form novalidate>
                <div class="form-group">
                    <label for="email">Email:</label>
                    <input id="email" type="email" class="form-control" placeholder="Enter email..." required />
                    <div>
                        
                    </div>
                </div>
                <div class="form-group">
                    <label for="pwd">Password:</label>
                    <input id="pwd" type="password" class="form-control" placeholder="Password" required />
                    <div>
                        
                    </div>
                </div>
                <div class="form-group form-check">
                    <input id="remember" type="checkbox" class="form-check-input" required />
                    <label for="remember">我同意</label>
                    <div>
                       
                    </div>
                </div>
              
                <input id="Button1" type="button" value="submit" class="btn btn-primary" />
            </form>
        </div>
    </div>
    <script src="Scripts/jquery-3.0.0.min.js"></script>

    <script>
        $('#Button1').click(function () {
            if ($('#email').val() == "") {
                $('#email').addClass('is-invalid');
                $('#email+div').addClass('invalid-feedback').text('Required!!');
            }
            else {
                $('#email').removeClass('is-invalid').addClass('is-valid');
                $('#email+div').removeClass().text('');
            }

            var rex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

            if (!rex.test($('#email').val())) {
                $('#email').addClass('is-invalid');
                $('#email+div').addClass('invalid-feedback').text('Please Check Email Format!!');
            }
            else {
                $('#email').removeClass('is-invalid').addClass('is-valid');
                $('#email+div').removeClass().text('');
            }

            if ($('#pwd').val() == "") {
                $('#pwd').addClass('is-invalid');
                $('#pwd+div').addClass('invalid-feedback').text('Required!!');
            }
            else {
                $('#pwd').removeClass('is-invalid').addClass('is-valid');
                $('#pwd+div').removeClass().text('');
            }

            if (!$('#remember').is(':checked')) {
                $('#remember').addClass('is-invalid');
                $('#remember+label+div').addClass('invalid-feedback').text('Please Check it!!');
            }
            else {
                $('#remember').removeClass('is-invalid').addClass('is-valid');
                $('#remember+label+div').removeClass().text('');
            }
        });

        

    </script>
</body>
</html>

##接著調整架構 (內聚力高耦合力低)

一樣的地方放在 function 不一樣的地方當作參數傳入 function

接著寫 click 觸發後

驗證過

呼叫 function

if

通過就傳通過的參數 沒通過就傳沒通過的參數

然後驗證呼叫的這件事情也可以調整架構

但只能相同驗證方式同一架構

###巢狀 必填驗證先驗證後 如果有填才進行別的驗證 避免 字被蓋掉

##JQ 內DOM選擇器

+: 下一個兄弟結點NODE ~:下N個兄弟結點NODE

#接著處理submit postback問題

下旗標 ? ( 用來輔助驗證通過或失敗的變數

將form取id

使用submit方法

然後弄個旗標值做true或false判斷

##最後 改成 keyboard 事件 只要有打字就觸發格式驗證

但是必填還是要由click觸發

##預設submit是會送true

在這邊我們用 submit(function () 接手 再去判斷 true or false

純html狀態消失才算送出去

但webform會保留狀態就不能這樣判斷

###RWD/19ValidationStatus.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title></title>

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <link href="MyStyle.css" rel="stylesheet" />
</head>
<body>


    <div class="card bg-light">
        <div class="container">

            <form novalidate id="login">
                <div class="form-group">
                    <label for="email">Email:</label>
                    <input id="email" type="email" class="form-control" placeholder="Enter email..." required />
                    <div>
                        
                    </div>
                </div>
                <div class="form-group">
                    <label for="pwd">Password:</label>
                    <input id="pwd" type="password" class="form-control" placeholder="Password" required />
                    <div>
                        
                    </div>
                </div>
                <div class="form-group form-check">
                    <input id="remember" type="checkbox" class="form-check-input" required />
                    <label for="remember">我同意</label>
                    <div>
                       
                    </div>
                </div>
              
                <input id="Button1" type="submit" value="submit" class="btn btn-primary" />
            </form>
        </div>
    </div>
    <script src="Scripts/jquery-3.0.0.min.js"></script>

    <script>
        var flag2 = false;
        var flag = false;
        var rex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

        function StateChange(state,objID,text) {
            if (state) {
                $(objID).removeClass('is-invalid').addClass('is-valid');
                $(objID + '~div').removeClass().text('');              
            }
            else {
                $(objID).removeClass('is-valid').addClass('is-invalid');
                $(objID + '~div').addClass('invalid-feedback').text(text);
            }
            flag = state;
        }

       

        $('#login').submit(function () {
            if (flag2) {
                if ($('#email').val() == "") {
                    StateChange(false, "#email", "Required!!");
                }
                else {
                    StateChange(true, "#email", "");
                }

                if ($('#pwd').val() == "") {
                    StateChange(false, "#pwd", "Required!!");
                }
                else {
                    StateChange(true, "#pwd", "");
                }
                if (!$('#remember').is(':checked')) {
                    StateChange(false, "#remember", "Please Check it!!")
                    flag = false;
                }
                else {
                    StateChange(true, "#remember", "")
                    flag = true;

                }
            }
            console.log(flag);
            console.log(flag2);

            if (flag && flag2 )
                return true;
          

            return false;


        });

        $('#email').keyup(function () {

            if (!rex.test($('#email').val())) {
                StateChange(false, "#email", "Please Check Email Format!!!!");
                flag2 = false;
            }
            else {
                StateChange(true, "#email", "");
                flag2 = true;
            }
        })
        
        
            
        $('#pwd').keyup(function () {
            if ($('#pwd').val().length < 8) {
                StateChange(false, "#pwd", ">8!!");
                flag2 = false;
            }
            else {
                StateChange(true, "#pwd", "");
                flag2 = true;
            }
        })


        //$('#Button1').click(function () {
            
        //});

        

    </script>
</body>
</html>

MVC_ CRUD 接續昨天

昨天做完查詢(要自己改成輸入)跟刪除

新增

因為index是範本產出裡面已經有create連結

所以我們直接用controll新增get create 的actionresult用來 return View()

第二個用來post的create 表單mether是post就會呼叫這個action

先用簡單繫結法把所有欄位當作參數傳入,必須要跟表單上的name一樣

圖片”檔案”必須要用HttpPostedFileBase型態傳

然後try catch

這裡不處理檔名重複問題 ( 實務上要判別

System.IO.Path.GetExtension(fImg.FileName) 可以從主檔名內抓副檔名

寫判斷如果抓到的東西

利用fImg.ContentLength 檔案大小 大於 0

fImg.SaveAs(Server.MapPath(“~/images/“+fImg.FileName)將檔案轉移到伺服器 ???

將參數轉至變數物件( 包含檔名等等

存檔至資料庫

以上為簡單繫結的方式 也可以用複雜繫結

寫好功能後利用這個action右鍵新增檢視使用範本

添加 form的

method post

action 用 @Url.Action(“Creat”)

enctype=”multipart/form-data”表單類型改為這種 要傳檔案的

產生token

action檢查token

HttpPost底下要加上

範本只需要動

上傳圖片那裏(因為範本的是只要傳圖片檔名(但我們是要檔案

改為input id="fImg" name="fImg" type="file"

底下submit底下把try catch的

@ViewBag.Error補上

###06CRUD/Controllers/HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//00-1-6 using _06CRUD.Models;
using _06CRUD.Models;

namespace _06CRUD.Controllers
{
    public class HomeController : Controller
    {
        //00-1-7 使用Entity建立DB物件
        dbProductEntities db = new dbProductEntities();
        // GET: Home
        //00-2-1 在HomeController裡撰寫Index的Action
        public ActionResult Index()
        {
            return View(db.tProduct.ToList());
        }

        //00-5-1 在HomeController裡撰寫GET及POST的Create Action
        public ActionResult Delete(string id)
        {
            var products = db.tProduct.Where(m => m.fId == id).FirstOrDefault();
            string fileName = products.fImg;
            System.IO.File.Delete(Server.MapPath("~/images/"+fileName));
            db.tProduct.Remove(products);
            db.SaveChanges();

            return RedirectToAction("Index");
        }



        public ActionResult Create()
        {

            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg)
        {
            try
            {
                //處理商品圖片檔
                string subname = System.IO.Path.GetExtension(fImg.FileName);
                if (subname == ".jpg" || subname==".png")
                {
                    if(fImg.ContentLength>0)
                    {
                        fImg.SaveAs(Server.MapPath("~/images/"+ fImg.FileName));
                    }
                }

                tProduct product = new tProduct();
                product.fId = fId;
                product.fName = fName;
                product.fPrice = fPrice;
                product.fImg = fImg.FileName;

                db.tProduct.Add(product);
                db.SaveChanges();

                return RedirectToAction("Index");

            }
            catch(Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View();
        }


    }
}



###06CRUD/Views/Home/Create.cshtml

@model _06CRUD.Models.tProduct

@{
    ViewBag.Title = "新增產品";
}

<h2>新增產品</h2>

@*@using (Html.BeginForm()) 
{*@
<form method="post" action="@Url.Action("Create")" enctype="multipart/form-data">
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        @*<h4>tProduct</h4>*@
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.fId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fId, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fPrice, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fPrice, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fPrice, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fImg, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @*@Html.EditorFor(model => model.fImg, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fImg, "", new { @class = "text-danger" })*@
                <input id="fImg" name="fImg" type="file" class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
                @ViewBag.Error
            </div>
        </div>
    </div>
    @*}*@
</form>
<div>
    @Html.ActionLink("返回列表", "Index")
</div>

###老師步驟

//00-1 利用Entity Framework建立Model(DB First)
//00-1-1 建立dbProduct.mdb資料庫Model
//       在Models上按右鍵,選擇加入,新增項目,資料,ADO.NET實體資料模型,名稱輸入"ProductModel",按新增
//       來自資料庫的EF Designer
//       連接dbProduct.mdf資料庫,連線名稱不修改,按下一步按鈕
//       選擇Entity Framework 6.x, 按下一步按鈕
//       資料表勾選"tProuct", 按完成鈕
//       若跳出詢問方法按確定鈕
//00-1-2 在專案上按右鍵,建置
//00-1-3 在tProduct.cs裡加入欄位名稱顯示(需using System.ComponentModel)
//00-1-4 在Controllers資料夾上按右鍵,加入,控制器,選擇 MVC5Controller-Empty
//00-1-5 指定控制器名稱為HomeController,並開啟HomeController
//00-1-6 using _00MVC.Models
//00-1-7 使用Entity建立DB物件


//00-2 製作Index頁面的顯示所有產品功能
//00-2-1 在HomeController裡撰寫Index的Action
//00-2-2 在public ActionResult Index()上按右鍵,新增檢視,建立Index View
//00-2-3 進行下列設定:
//       View name:Index
//       Template:List
//       Model class:tStudent(_00MVC.Models)
//       Data context class:dbProductEntities(_00MVC.Models)
//       勾選Use a layout pages
//       按下Add
//00-2-5 修改Index View,英文文字為中文
//00-2-6 修改圖片顯示處

//00-3 製作刪除功能
//00-3-1 在HomeController裡撰寫Delete的Action

//00-4 製作Create頁面及新增產品功能
//00-4-1 在HomeController裡撰寫GET及POST的Create Action
//00-4-2 在public ActionResult Create()上按右鍵,新增檢視,建立Create View
//00-4-3 進行下列設定:
//       View name:Create
//       Template:Create
//       Model class:tStudent(_00MVC.Models)
//       Data context class:dbProductEntities(_00MVC.Models)
//       勾選Use a layout pages
//       按下Add
//00-4-4 修改Index View,英文文字為中文
//00-4-5 修改form的HTML Helper為一般的from
//00-4-6 修改圖片上傳處表單
//00-4-7 加入例外訊息顯示處

Debug ie 問題 抓 filename抓出來的值不一樣 以上從改 (資安問題

D:\AAA\img.jpg IE

img.jpg chrome

要利用GetFileName方法

順道調整架構 整理成以下

#接著換修改

Action 沒有順序性先寫哪種沒關係

首先新增一個 Edit 的 action 然後

用get接參數 ( 簡單繫結即可

接著將參數用lamaba查詢到的資料 return丟回View

接著新增一個 post 一樣token

圖必須要看 (沒有就沒事

有沒有置換有的話就要刪除原來的圖然後上傳新檔案

還要傳圖片目前的檔名才能夠去判斷是新還舊

接著 如果有置換

就刪除 system.io.file.delete(server.mappath(~~~~)

然後將舊檔名改為新檔名

存檔

如果沒改則把新檔名改為舊檔名做存檔

### 06CRUD/Controllers/HomeController.cs

@model _06CRUD.Models.tProduct

@{
    ViewBag.Title = "新增產品";
}

<h2>新增產品</h2>

@*@using (Html.BeginForm()) 
{*@
<form method="post" action="@Url.Action("Create")" enctype="multipart/form-data">
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        @*<h4>tProduct</h4>*@
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.fId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fId, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fPrice, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fPrice, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fPrice, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fImg, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @*@Html.EditorFor(model => model.fImg, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fImg, "", new { @class = "text-danger" })*@
                <input id="fImg" name="fImg" type="file" class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
                @ViewBag.Error
            </div>
        </div>
    </div>
    @*}*@
</form>
<div>
    @Html.ActionLink("返回列表", "Index")
</div>

接著新增一個edit的view一樣預設範本 但是把 form 手動編輯

然後圖片那裡用隱藏按鈕用於簡單繫結傳送舊檔名資料

預設的範本 pk不能改 應為改了 你整個動態網頁的東西都會有機會出錯

然後範本很多東西都重複產生可能都要註解 ( 熟悉才能註解不然會出錯

剛剛錯誤是 寫入資料庫時pk重複

新增是增加的

修改是修改重複的

物件一定要有傳過來做查詢顯示用

但是不能新增add

要直接save

以下為改過的 control

### /06CRUD/Controllers/HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//00-1-6 using _06CRUD.Models;
using _06CRUD.Models;

namespace _06CRUD.Controllers
{
    public class HomeController : Controller
    {
        //00-1-7 使用Entity建立DB物件
        dbProductEntities db = new dbProductEntities();
        // GET: Home
        //00-2-1 在HomeController裡撰寫Index的Action
        public ActionResult Index()
        {
            return View(db.tProduct.ToList());
        }

        //00-5-1 在HomeController裡撰寫GET及POST的Create Action
        public ActionResult Delete(string id)
        {
            var products = db.tProduct.Where(m => m.fId == id).FirstOrDefault();
            string fileName = products.fImg;
            System.IO.File.Delete(Server.MapPath("~/images/"+fileName));
            db.tProduct.Remove(products);
            db.SaveChanges();

            return RedirectToAction("Index");
        }


        //00-5-1 在HomeController裡撰寫GET及POST的Edit Action
        public ActionResult Create()
        {

            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg)
        {
            try
            {
                //處理商品圖片檔
                string fileName = "";
                string subname = System.IO.Path.GetExtension(fImg.FileName);
                if (subname == ".jpg" || subname==".png")
                {
                    if(fImg.ContentLength>0)
                    {
                        fileName = System.IO.Path.GetFileName(fImg.FileName);
                        fImg.SaveAs(Server.MapPath("~/images/"+ fileName));
                    }
                }

                tProduct product = new tProduct();
                product.fId = fId;
                product.fName = fName;
                product.fPrice = fPrice;
                product.fImg = fileName;

                db.tProduct.Add(product);
                db.SaveChanges();

                return RedirectToAction("Index");

            }
            catch(Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View();
        }


        public ActionResult Edit(string id)
        {

            return View(db.tProduct.Where(m=>m.fId==id).FirstOrDefault());
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg,string oldImg)
        {
            try
            {
                
                string fileName = "";

                if (fImg != null)
                {
                    //處理商品圖片檔
                    string subname = System.IO.Path.GetExtension(fImg.FileName);
                    if (subname == ".jpg" || subname == ".png")
                    {
                        if (fImg.ContentLength > 0)
                        {
                            System.IO.File.Delete(Server.MapPath("~/images/" + oldImg));

                            fileName = System.IO.Path.GetFileName(fImg.FileName);
                            fImg.SaveAs(Server.MapPath("~/images/" + fileName));
                        }
                    }

                }
                else
                {
                    fileName = oldImg;
                }
                //tProduct product = new tProduct();
                //product.fId = fId;
                var product= db.tProduct.Where(m => m.fId == fId).FirstOrDefault();

                product.fName = fName;
                product.fPrice = fPrice;
                product.fImg = fileName;

                //db.tProduct.Add(product);
                db.SaveChanges();

                return RedirectToAction("Index");

            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View();
        }

    }
}

最後會貼一次 完整的 CRUD所有的程式碼與大概網站結構圖

###06CRUD/App_Data/dbProduct.mdf

### /06CRUD/Models/tProduct.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     這個程式碼是由範本產生。
//
//     對這個檔案進行手動變更可能導致您的應用程式產生未預期的行為。
//     如果重新產生程式碼,將會覆寫對這個檔案的手動變更。
// </auto-generated>
//------------------------------------------------------------------------------

namespace _06CRUD.Models
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    
    public partial class tProduct
    {
        [DisplayName("產品編號")]
        public string fId { get; set; }
        [DisplayName("品名")]
        public string fName { get; set; }
        [DisplayName("單價")]
        public Nullable<decimal> fPrice { get; set; }
        [DisplayName("圖示")]
        public string fImg { get; set; }
    }
}

###06CRUD/Controllers/HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//00-1-6 using _06CRUD.Models;
using _06CRUD.Models;

namespace _06CRUD.Controllers
{
    public class HomeController : Controller
    {
        //00-1-7 使用Entity建立DB物件
        dbProductEntities db = new dbProductEntities();
        // GET: Home
        //00-2-1 在HomeController裡撰寫Index的Action
        public ActionResult Index()
        {
            return View(db.tProduct.ToList());
        }

        //00-5-1 在HomeController裡撰寫GET及POST的Create Action
        public ActionResult Delete(string id)
        {
            var products = db.tProduct.Where(m => m.fId == id).FirstOrDefault();
            string fileName = products.fImg;
            System.IO.File.Delete(Server.MapPath("~/images/"+fileName));
            db.tProduct.Remove(products);
            db.SaveChanges();

            return RedirectToAction("Index");
        }


        //00-5-1 在HomeController裡撰寫GET及POST的Edit Action
        public ActionResult Create()
        {

            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg)
        {
            try
            {
                //處理商品圖片檔
                string fileName = "";
                string subname = System.IO.Path.GetExtension(fImg.FileName);
                if (subname == ".jpg" || subname==".png")
                {
                    if(fImg.ContentLength>0)
                    {
                        fileName = System.IO.Path.GetFileName(fImg.FileName);
                        fImg.SaveAs(Server.MapPath("~/images/"+ fileName));
                    }
                }

                tProduct product = new tProduct();
                product.fId = fId;
                product.fName = fName;
                product.fPrice = fPrice;
                product.fImg = fileName;

                db.tProduct.Add(product);
                db.SaveChanges();

                return RedirectToAction("Index");

            }
            catch(Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View();
        }


        public ActionResult Edit(string id)
        {

            return View(db.tProduct.Where(m=>m.fId==id).FirstOrDefault());
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg,string oldImg)
        {
            try
            {
                
                string fileName = "";

                if (fImg != null)
                {
                    //處理商品圖片檔
                    string subname = System.IO.Path.GetExtension(fImg.FileName);
                    if (subname == ".jpg" || subname == ".png")
                    {
                        if (fImg.ContentLength > 0)
                        {
                            System.IO.File.Delete(Server.MapPath("~/images/" + oldImg));

                            fileName = System.IO.Path.GetFileName(fImg.FileName);
                            fImg.SaveAs(Server.MapPath("~/images/" + fileName));
                        }
                    }

                }
                else
                {
                    fileName = oldImg;
                }
                //tProduct product = new tProduct();
                //product.fId = fId;
                var product= db.tProduct.Where(m => m.fId == fId).FirstOrDefault();

                product.fName = fName;
                product.fPrice = fPrice;
                product.fImg = fileName;

                //db.tProduct.Add(product);
                db.SaveChanges();

                return RedirectToAction("Index");

            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View();
        }

    }
}

###06CRUD/Views/Shared/_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="~/Scripts/modernizr-2.6.2.js"></script>
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                </ul>
            </div>
        </div>
    </div>

    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
</body>
</html>

###06CRUD/Views/Home/Index.cshtml

@model IEnumerable<_06CRUD.Models.tProduct>
@*//00-2-5 修改Index View,英文文字為中文*@
@{
    ViewBag.Title = "產品列表";
}

<h2>產品列表</h2>

<p>
    @Html.ActionLink("新增商品", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.fName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.fPrice)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.fImg)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.fName)
            </td>
            <td>

                @Html.DisplayFor(modelItem => item.fPrice)
            </td>
            <td>
                @*//00-2-6 修改圖片顯示處*@
                @*@Html.DisplayFor(modelItem => item.fImg)*@
                <img src="~/images/@item.fImg" width="120" />
            </td>
            <td>
                @Html.ActionLink("修改", "Edit", new { id = item.fId }) |
                @*@Html.ActionLink("Details", "Details", new { id=item.fId }) |*@
                @Html.ActionLink("刪除", "Delete", new { id = item.fId }, new { onclick = "return confirm('確定刪除??')" })
            </td>
        </tr>
    }

</table>

###06CRUD/Views/Home/Create.cshtml

@model _06CRUD.Models.tProduct
@*//00-4-4 修改Index View,英文文字為中文*@
@{
    ViewBag.Title = "新增產品";
}

<h2>新增產品</h2>

@*//00-4-6 修改圖片上傳處表單*@
@*@using (Html.BeginForm())
    {*@
<form method="post" action="@Url.Action("Create")" enctype="multipart/form-data">
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        @*<h4>tProduct</h4>*@
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.fId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fId, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fPrice, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fPrice, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fPrice, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fImg, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @*@Html.EditorFor(model => model.fImg, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.fImg, "", new { @class = "text-danger" })*@
                @*//00-4-6 修改圖片上傳處表單*@
                <input id="fImg" name="fImg" type="file" class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
                @*//00-4-7 加入例外訊息顯示處*@
                @ViewBag.Error
            </div>
        </div>
    </div>
    @*}*@
</form>
<div>
    @Html.ActionLink("返回列表", "Index")
</div>

###06CRUD/Views/Home/Edit.cshtml

@model _06CRUD.Models.tProduct

@{
    ViewBag.Title = "產品編輯";
}

<h2>產品編輯</h2>

@*@using (Html.BeginForm())
{*@
<form method="post" action="@Url.Action("Edit")" enctype="multipart/form-data">


    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        @*<h4>tProduct</h4>*@
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.fId)
        @*<input id="fId" name="fId" type="hidden" value="@Model.fId" />*@
        <div class="form-group">
            @Html.LabelFor(model => model.fName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fPrice, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fPrice, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fPrice, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fImg, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @*@Html.EditorFor(model => model.fImg, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fImg, "", new { @class = "text-danger" })*@
                <input id="oldImg" name="oldImg" type="hidden" value="@Model.fImg" />
                <img src="~/images/@Model.fImg" width="200" />
                
                <input id="fImg" name="fImg" type="file" class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
                @ViewBag.Error
            </div>
        </div>
    </div>
    @*}*@
</form>
<div>
    @Html.ActionLink("Back to List", "Index")
</div>

###老師步驟

//00-1 利用Entity Framework建立Model(DB First)
//00-1-1 建立dbProduct.mdb資料庫Model
//       在Models上按右鍵,選擇加入,新增項目,資料,ADO.NET實體資料模型,名稱輸入"ProductModel",按新增
//       來自資料庫的EF Designer
//       連接dbProduct.mdf資料庫,連線名稱不修改,按下一步按鈕
//       選擇Entity Framework 6.x, 按下一步按鈕
//       資料表勾選"tProuct", 按完成鈕
//       若跳出詢問方法按確定鈕
//00-1-2 在專案上按右鍵,建置
//00-1-3 在tProduct.cs裡加入欄位名稱顯示(需using System.ComponentModel)
//00-1-4 在Controllers資料夾上按右鍵,加入,控制器,選擇 MVC5Controller-Empty
//00-1-5 指定控制器名稱為HomeController,並開啟HomeController
//00-1-6 using _00MVC.Models
//00-1-7 使用Entity建立DB物件


//00-2 製作Index頁面的顯示所有產品功能
//00-2-1 在HomeController裡撰寫Index的Action
//00-2-2 在public ActionResult Index()上按右鍵,新增檢視,建立Index View
//00-2-3 進行下列設定:
//       View name:Index
//       Template:List
//       Model class:tStudent(_00MVC.Models)
//       Data context class:dbProductEntities(_00MVC.Models)
//       勾選Use a layout pages
//       按下Add
//00-2-5 修改Index View,英文文字為中文
//00-2-6 修改圖片顯示處

//00-3 製作刪除功能
//00-3-1 在HomeController裡撰寫Delete的Action

//00-4 製作Create頁面及新增產品功能
//00-4-1 在HomeController裡撰寫GET及POST的Create Action
//00-4-2 在public ActionResult Create()上按右鍵,新增檢視,建立Create View
//00-4-3 進行下列設定:
//       View name:Create
//       Template:Create
//       Model class:tStudent(_00MVC.Models)
//       Data context class:dbProductEntities(_00MVC.Models)
//       勾選Use a layout pages
//       按下Add
//00-4-4 修改Index View,英文文字為中文
//00-4-5 修改form的HTML Helper為一般的from
//00-4-6 修改圖片上傳處表單
//00-4-7 加入例外訊息顯示處

#六月份會從頭做到尾一次給我們看

驗證的js要怎寫? 問google keyword

https://www.google.com/search?rlz=1C1GCEU_zh-TWTW835TW836&q=mail+javascript+regex&spell=1&sa=X&ved=0ahUKEwjbpMTeiJ_iAhXHx4sBHSWJAigQBQgoKAA&biw=1920&bih=936
表單 (Forms)getbootstrap
控制項 - Google SearchGoogle
fieldset legend - Google SearchGoogle
Logo
Logo
Logo