protected void btnAdd_Click(object sender, EventArgs e) { string ErrorMsg = ""; this.ErrorMsgLabel.Text = ""; string PurchaseNo = ""; DataTable dtTransItem = new DataTable(); DataTable dtTransGift = new DataTable(); try { string UserID = Session["UID"].ToString(); string CreateDate = DateTime.Now.ToString("yyyyMMddHHmmss"); VGIModel.ImportAccept dbo = new VGIModel.ImportAccept(ConnectionDB); if (GridView1.Rows.Count == 0) { this.ErrorMsgLabel.Text = "請先匯入資料"; return; } bool haveData = false; for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chbYes = (CheckBox)GridView1.Rows[i].FindControl("chbYes"); if (chbYes.Checked) { haveData = true; } } if (haveData == false) { this.ErrorMsgLabel.Text = "請先選擇需要產生驗收單資料"; return; } DataTable dtItem = new DataTable(); dtItem.Columns.Add("item"); dtItem.Columns.Add("period"); dtItem.Columns.Add("chan_source_no"); for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chbYes = (CheckBox)GridView1.Rows[i].FindControl("chbYes"); Label lblItem = (Label)GridView1.Rows[i].FindControl("lblItem"); Label lblPeriod = (Label)GridView1.Rows[i].FindControl("lblPeriod"); Label lblchan_source_no = (Label)GridView1.Rows[i].FindControl("lblchan_source_no"); if (chbYes.Checked) { DataRow drItem = dtItem.NewRow(); drItem["item"] = lblItem.Text; drItem["period"] = lblPeriod.Text; drItem["chan_source_no"] = lblchan_source_no.Text; dtItem.Rows.Add(drItem); } } DataRow[] drList; for(int i = 0;i<dtItem.Rows.Count;i++) { drList = dtItem.Select("item = '" + dtItem.Rows[i]["item"].ToString() + "' and period = '" + dtItem.Rows[i]["period"].ToString() + "'"); if (drList.Length > 1) { throw new Exception("選取資料品號及期別相同,無法同時驗收,請重新選擇"); } } bool IsOK = dbo.CheckData(txtChanNo.Text, UserID, CreateDate, dtItem, null, out ErrorMsg, out PurchaseNo, out dtTransItem, out dtTransGift); if (IsOK == false) { ErrorMsgLabel.Text = ErrorMsg; return; } Session["VGI014Detl"] = dtTransItem; if (dtTransGift.Rows.Count > 0) { Session["VGI104Gift"] = dtTransGift; } Response.Redirect("VGI012.aspx?Code=VGI01&PageMode=1"); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
protected void btnImport_Click(object sender, EventArgs e) { try { ErrorMsgLabel.Text = ""; if (txtChanNo.Text == string.Empty) { ErrorMsgLabel.Text = "請輸入匯入批號"; return; } string UserID = Session["UID"].ToString(); string CreateDate = DateTime.Now.ToString("yyyyMMddHHmmss"); VGIModel.ImportAccept dbo = new VGIModel.ImportAccept(ConnectionDB); ParameterList.Clear(); ParameterList.Add(txtChanNo.Text); ParameterList.Add(UserID); ParameterList.Add(CreateDate); ParameterList.Add("AA"); DataTable dtResult = dbo.GetSourcetData(ParameterList,null); GridView1.DataSource = dtResult; GridView1.DataBind(); if (GridView1.Rows.Count != 0) { for (int i = 0; i < GridView1.Rows.Count; i++) { Label lblNote = (Label)GridView1.Rows[i].FindControl("lblNote"); CheckBox chbYes = (CheckBox)GridView1.Rows[i].FindControl("chbYes"); chbYes.Enabled = lblNote.Text == string.Empty; } } else { throw new Exception("查無匯入批號資料"); } //dbo.CheckData(txtChanNo.Text,UserID,CreateDate, } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }