protected void gv_Detail_RowDataBound(object sender, GridViewRowEventArgs e) { StringBuilder sb1 = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); StringBuilder sb3 = new StringBuilder(); StringBuilder sb4 = new StringBuilder(); StringBuilder sb5 = new StringBuilder(); #region 設定 GridView Button 的隱藏與顯示狀態 if (e.Row.RowType == DataControlRowType.Header) { if (this.hid_PageStatus.Value != "INSERT") { e.Row.Cells[12].Visible = true; } else { e.Row.Cells[12].Visible = false; } } #endregion switch (e.Row.RowType) { case DataControlRowType.Header: sb1.Remove(0, sb1.Length); sb2.Remove(0, sb2.Length); sb3.Remove(0, sb3.Length); sb4.Remove(0, sb4.Length); sb5.Remove(0, sb5.Length); //先把供應商欄位開啟 在明細時再做判斷 if (this.hid_PageStatus.Value == "EDIT" || this.hid_PageStatus.Value == "INSERT") { PUR_VendorCode.ReadOnly = false; } break; case DataControlRowType.DataRow: if (this.hid_PageStatus.Value == "VIEW") { ((SLP_SKU_Vender)e.Row.FindControl("PUR_SKU")).ReadOnly = true; ((SLP_ItemPeriod)e.Row.FindControl("PUR_Period")).ReadOnly = true; ((TextBox)e.Row.FindControl("PurQty")).ReadOnly = true; ((TextBox)e.Row.FindControl("PurQty")).CssClass = "readtxtbox"; ((SLPDate)e.Row.FindControl("slpDeliverDate")).ReadOnly = true; ((TextBox)e.Row.FindControl("txtMsg")).ReadOnly = true; ((TextBox)e.Row.FindControl("txtMsg")).CssClass = "readtxtbox"; ((Button)e.Row.FindControl("btnCloseCase")).Enabled = false; ((Button)e.Row.FindControl("btnDelete")).Enabled = false; } else if (this.hid_PageStatus.Value == "EDIT") { SLP_SKU_Vender PUR_SKU = ((SLP_SKU_Vender)e.Row.FindControl("PUR_SKU")); PUR_SKU.ReadOnly = true; SLP_ItemPeriod PUR_PERIOD = ((SLP_ItemPeriod)e.Row.FindControl("PUR_Period")); PUR_PERIOD.ReadOnly = true; TextBox txtCT = (TextBox)e.Row.FindControl("txtCloseType"); if (txtCT.Text.Trim() == "") { //判斷採購單的項目是否有"在途單" MaintainPurchaseOrder bco = new MaintainPurchaseOrder(ConntionDB); bool IsOK = bco.CheckPurItemIsOnWay(this.tbxPUR_No.Text, PUR_SKU.Text, PUR_PERIOD.Text); if (IsOK) { ((Button)e.Row.FindControl("btnCloseCase")).Enabled = false; ((Button)e.Row.FindControl("btnDelete")).Enabled = false; } else { ((Button)e.Row.FindControl("btnCloseCase")).Enabled = true; ((Button)e.Row.FindControl("btnDelete")).Enabled = true; } ((TextBox)e.Row.FindControl("txtMsg")).ReadOnly = false; ((TextBox)e.Row.FindControl("txtMsg")).CssClass = ""; ((TextBox)e.Row.FindControl("PurQty")).ReadOnly = false; ((TextBox)e.Row.FindControl("PurQty")).CssClass = ""; ((SLPDate)e.Row.FindControl("slpDeliverDate")).ReadOnly = false; HiddenField txtIS_ADD = (HiddenField)e.Row.FindControl("txtIS_ADD"); if (txtIS_ADD.Value.ToString() == "1") { ((SLP_SKU_Vender)e.Row.FindControl("PUR_SKU")).ReadOnly = false; ((SLP_ItemPeriod)e.Row.FindControl("PUR_Period")).ReadOnly = false; ((TextBox)e.Row.FindControl("txtMsg")).ReadOnly = false; ((TextBox)e.Row.FindControl("txtMsg")).CssClass = ""; } } else { ((Button)e.Row.FindControl("btnCloseCase")).Enabled = false; ((Button)e.Row.FindControl("btnDelete")).Enabled = false; ((TextBox)e.Row.FindControl("txtMsg")).ReadOnly = true; ((TextBox)e.Row.FindControl("txtMsg")).CssClass = "readtxtbox"; ((TextBox)e.Row.FindControl("PurQty")).ReadOnly = true; ((TextBox)e.Row.FindControl("PurQty")).CssClass = "readtxtbox"; ((SLPDate)e.Row.FindControl("slpDeliverDate")).ReadOnly = true; ((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).ReadOnly = true; ((ASP.itm_slp_slp_itemperiod_ascx)e.Row.FindControl("PUR_Period")).ReadOnly = true; } //假如供應商未設定 則明細不可輸入 if ((PUR_VendorCode.Text.Trim() == "") || (PUR_VendorCode.TextBox_Name.Text.Trim() == "查無資料")) { ((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).ReadOnly = true; ((ASP.itm_slp_slp_itemperiod_ascx)e.Row.FindControl("PUR_Period")).ReadOnly = true; } //假如有明細資料了 則供應商不可輸入 if ( (((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).Text.Trim() != "") || (((ASP.itm_slp_slp_itemperiod_ascx)e.Row.FindControl("PUR_Period")).Text.Trim() != "") ) { PUR_VendorCode.ReadOnly = true; } else if (DetailHaveData() == true) { PUR_VendorCode.ReadOnly = true; } } else if (this.hid_PageStatus.Value == "INSERT") { ((SLP_SKU_Vender)e.Row.FindControl("PUR_SKU")).ReadOnly = false; ((SLP_ItemPeriod)e.Row.FindControl("PUR_Period")).ReadOnly = false; ((TextBox)e.Row.FindControl("txtMsg")).ReadOnly = false; ((TextBox)e.Row.FindControl("txtMsg")).CssClass = ""; ((TextBox)e.Row.FindControl("PurQty")).ReadOnly = false; ((TextBox)e.Row.FindControl("PurQty")).CssClass = ""; ((SLPDate)e.Row.FindControl("slpDeliverDate")).ReadOnly = false; //假如供應商未設定 則明細不可輸入 if ((PUR_VendorCode.Text.Trim() == "") || (PUR_VendorCode.TextBox_Name.Text.Trim() == "查無資料")) { ((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).ReadOnly = true; ((ASP.itm_slp_slp_itemperiod_ascx)e.Row.FindControl("PUR_Period")).ReadOnly = true; } //假如有明細資料了 則供應商不可輸入 if ( (((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).Text.Trim() != "") || (((ASP.itm_slp_slp_itemperiod_ascx)e.Row.FindControl("PUR_Period")).Text.Trim() != "") ) { PUR_VendorCode.ReadOnly = true; } else if (DetailHaveData() == true) { PUR_VendorCode.ReadOnly = true; } } //設定TextBox屬性,因用Label於GridView上,取值時,會因其Readlony屬性,導致取值時,皆取到初始值 TextBox txtPurQty = (TextBox)e.Row.FindControl("PurQty"); TextBox txtCostUP = (TextBox)e.Row.FindControl("txtCostUP"); if (txtCostUP.Text.Trim() != "") txtCostUP.Text = double.Parse(txtCostUP.Text).ToString("0.00"); TextBoxNoBorder(txtCostUP); TextBox txtMDC_Qty = (TextBox)e.Row.FindControl("txtMDC_Qty"); TextBoxNoBorder(txtMDC_Qty); TextBox txtCheckQty = (TextBox)e.Row.FindControl("txtCheckQty"); TextBoxNoBorder(txtCheckQty); TextBox txtCostSumy = (TextBox)e.Row.FindControl("txtCostSumy"); if (txtCostSumy.Text.Trim() != "") txtCostSumy.Text = double.Parse(txtCostSumy.Text).ToString("0.00"); TextBoxNoBorder(txtCostSumy); TextBox txtCloseType = (TextBox)e.Row.FindControl("txtCloseType"); if (txtCloseType.Text == "A") txtCloseType.Text = "自動"; else if (txtCloseType.Text == "M") txtCloseType.Text = "手動"; TextBoxNoBorder(txtCloseType); TextBox txtCloseDate = (TextBox)e.Row.FindControl("txtCloseDate"); TextBoxNoBorder(txtCloseDate); if (this.hid_PageStatus.Value != "INSERT") { e.Row.Cells[12].Visible = true; } else { e.Row.Cells[12].Visible = false; } Button btnCC = (Button)e.Row.Cells[12].FindControl("btnCloseCase"); btnCC.CommandArgument = e.Row.RowIndex.ToString(); #region [刪除]設定 Button btn_gv_Delete = (Button)e.Row.Cells[13].FindControl("btnDelete"); btn_gv_Delete.CommandArgument = e.Row.RowIndex.ToString(); #endregion if ((this.hid_PageStatus.Value == "INSERT") || (this.hid_PageStatus.Value == "EDIT")) { TextBox txtCT = (TextBox)e.Row.FindControl("txtCloseType"); if (txtCT.Text.Trim() == "") { if (((TextBox)((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).FindControl("TextBoxCode")).ReadOnly == false) { // 離開品名/品號 sb1.AppendFormat("SetCheck_1_2(\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",this);\r\n", ((HiddenField)e.Row.Cells[1].FindControl("HidenID")).ClientID, //0.GridView 識別行號 ID ((TextBox)e.Row.Cells[1].Controls[1].FindControl("TextBoxCode")).ClientID, //1.新值ITEM欄位ClientID ((HiddenField)e.Row.FindControl("HidenItem")).ClientID, //2.隱藏舊值的ITEM欄位ClientID ((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).ClientID, //3.新值Period欄位ClientID ((HiddenField)e.Row.Cells[2].FindControl("HidenPeriod")).ClientID, //4.隱藏舊值的Period欄位ClientID ((TextBox)this.PUR_PURDate.Controls[1].FindControl("TextBoxCode")).ClientID, //5.採購日期 "1", //6.Click哪個Button ((TextBox)e.Row.FindControl("PurQty")).ClientID.Replace("PurQty", ""), //7.RowClientID ((ASP.wui_slp_slp_slpdate_ascx)e.Row.FindControl("slpDeliverDate")).ClientID + "_TextBoxCode" //8.採購日期 ); ((TextBox)((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).FindControl("TextBoxCode")).Attributes["onblur"] = sb1.ToString(); ((TextBox)((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).FindControl("TextBoxCode")).Attributes["onfocus"] += "nowfocus='" + ((TextBox)((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).FindControl("TextBoxCode")).ClientID + "';"; ((TextBox)((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).FindControl("TextBoxCode")).Attributes["onfocus"] += "document.getElementById('" + this.BtnSave.ClientID + "').disabled=true;"; } if (((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).ReadOnly == false) { //離開期別 sb2.AppendFormat("SetCheck_1_2(\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",this);\r\n", ((HiddenField)e.Row.Cells[1].FindControl("HidenID")).ClientID, //0.GridView 識別行號 ID ((TextBox)e.Row.Cells[1].Controls[1].FindControl("TextBoxCode")).ClientID, //1.新值ITEM欄位ClientID ((HiddenField)e.Row.FindControl("HidenItem")).ClientID, //2.隱藏舊值的ITEM欄位ClientID ((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).ClientID, //3.新值Period欄位ClientID ((HiddenField)e.Row.Cells[2].FindControl("HidenPeriod")).ClientID, //4.隱藏舊值的Period欄位ClientID ((TextBox)this.PUR_PURDate.Controls[1].FindControl("TextBoxCode")).ClientID, //5.採購日期 "2", //6.Click哪個Button ((TextBox)e.Row.FindControl("PurQty")).ClientID.Replace("PurQty", ""), //7.RowClientID ((ASP.wui_slp_slp_slpdate_ascx)e.Row.FindControl("slpDeliverDate")).ClientID + "_TextBoxCode" //8.採購日期 ); ((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).Attributes["onblur"] = sb2.ToString(); ((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).Attributes["onfocus"] += "nowfocus='" + ((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).ClientID + "';"; ((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).Attributes["onfocus"] += "ParentSKU('" + ((TextBox)((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).FindControl("TextBoxCode")).ClientID + "');"; ((TextBox)e.Row.Cells[2].Controls[1].FindControl("TextBoxCode")).Attributes["onfocus"] += "document.getElementById('" + this.BtnSave.ClientID + "').disabled=true;"; ((Image)e.Row.Cells[2].Controls[1].FindControl("Image1")).Attributes["onmousedown"] += "ParentSKU('" + ((TextBox)((ASP.itm_slp_slp_sku_vender_ascx)e.Row.FindControl("PUR_SKU")).FindControl("TextBoxCode")).ClientID + "');"; } //離開採購數量 if (((TextBox)e.Row.Cells[6].FindControl("PurQty")).ReadOnly == false) { ((TextBox)e.Row.Cells[6].FindControl("PurQty")).Attributes["onkeypress"] = @"checkKeyPress(this,/^[0-9]+$/);"; ((TextBox)e.Row.Cells[6].FindControl("PurQty")).Attributes["onblur"] = "CAL_SUM('" + txtPurQty.ClientID + "','" + txtCostUP.ClientID + "','" + txtCostSumy.ClientID + "');"; } //離開交貨日期 //修改贈品的交貨日期等於明細的交貨日期 if (((TextBox)e.Row.Cells[7].Controls[1].FindControl("TextBoxCode")).ReadOnly == false) { ((TextBox)e.Row.Cells[7].Controls[1].FindControl("TextBoxCode")).Attributes["onfocus"] = "document.getElementById('" + this.BtnSave.ClientID + "').disabled=true;"; ((TextBox)e.Row.Cells[7].Controls[1].FindControl("TextBoxCode")).Attributes["onblur"] = "Enable_Progress();window.setTimeout(\"$get('ctl00_CPH_BtnRsfresh_Gift').click();\",1);"; } //限制欄位最多只能輸入60個字元 string strMaxLength = "60"; TextBox txtMsg = (TextBox)e.Row.FindControl("txtMsg"); txtMsg.Attributes["onkeypress"] += String.Format(@"return limit_length({0},{1});", txtMsg.ClientID, strMaxLength); txtMsg.Attributes["onblur"] += "limit_lengths('" + txtMsg.ClientID + "','" + strMaxLength + "');"; } } break; default: break; } }