private void DbInit() { using (SqlConnection Conn = new SqlConnection(strConnectString)) { DataTable dt = new DataTable(); string sqlstr = selectsql(); SqlDataAdapter myAdapter = new SqlDataAdapter(sqlstr, Conn); myAdapter.Fill(dt); ACRGV.DataSource = dt; ACRGV.DataBind(); } }
protected void ACRGV_RowCommand(object sender, GridViewCommandEventArgs e) { using (var conn = new GGFEntitiesMGT()) { int iid = 0; if (e.CommandName == "編輯") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string strid = ACRGV.DataKeys[row.RowIndex].Values[0].ToString(); int.TryParse(strid, out iid); Show(true); if (iid > 0) { var dset = db.快遞單.Where(p => p.id == iid); foreach (var item in dset) { 快遞日期TB.Text = item.提單日期.ToString("yyyy-MM-dd"); 快遞廠商DDL.SelectedValue = item.快遞廠商; 提單號碼TB.Text = item.提單號碼; //送件地點DDL.SelectedValue = (string.IsNullOrEmpty(送件地點DDL.Items.FindByValue(item.送件地點).Value)) ? "其他" : item.送件地點; Session["送件地點"] = item.送件地點; 部門DDL.SelectedValue = item.送件部門 ?? "業務部"; 地點備註TB.Text = item.地點備註 ?? ""; idHF.Value = item.id.ToString(); 寄件地點DDL.SelectedValue = item.寄件地點 ?? "振大"; } Session["提單日期"] = (string.IsNullOrEmpty(快遞時間TB.Text.Trim())) ? "%" : 快遞時間TB.Text.Trim(); Session["提單號碼"] = (string.IsNullOrEmpty(快遞單號TB.Text.Trim())) ? "%" : 快遞單號TB.Text.Trim(); } } else if (e.CommandName == "刪除") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string strid = ACRGV.DataKeys[row.RowIndex].Values[0].ToString(); using (var transaction = conn.Database.BeginTransaction()) { try { int.TryParse(strid, out iid); var 刪除快遞單 = conn.快遞單.Where(o => o.id == iid).FirstOrDefault(); 刪除快遞單.IsDeleted = true; 刪除快遞單.修改日期 = DateTime.Now; conn.SaveChanges(); transaction.Commit(); ACRGV.DataBind(); Show(false); } catch (Exception ex1) { try { Log.ErrorLog(ex1, "Delete Error :", "MGT001.aspx"); } catch (Exception ex2) { Log.ErrorLog(ex2, "Delete Error Error:", "MGT001.aspx"); } finally { transaction.Rollback(); //Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('刪除失敗請連絡MIS');</script>"); } } } } else if (e.CommandName == "新增明細") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string strid = ACRGV.DataKeys[row.RowIndex].Values[0].ToString(); Session.RemoveAll(); Session["id"] = strid; Session["提單號碼"] = ACRGV.Rows[row.RowIndex].Cells[2].Text; Session["提單日期"] = ACRGV.Rows[row.RowIndex].Cells[4].Text; Response.Redirect("MGT002.aspx"); } } }
protected void DbInit() { 寄件地點DDL.DataBind(); 送件地點DDL.DataBind(); ACRGV.DataBind(); }
protected void ACRGV_RowCommand(object sender, GridViewCommandEventArgs e) { using (var conn = new GGFEntitiesMGT()) { int iuid = 0, iid = 0; int.TryParse(idHF.Value, out iid); if (e.CommandName == "編輯") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string strid = ACRGV.DataKeys[row.RowIndex].Values[0].ToString(); int.TryParse(strid, out iuid); if (!F_確認結案(iid)) { if (iuid > 0) { if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { F_showDHL(true); } else { F_showDHL(false); } var dset = db.快遞單明細.Where(p => p.uid == iuid); foreach (var item in dset) { 寄件人工號TB.Text = item.寄件人工號; 分機TB.Text = item.寄件人分機; 客戶名稱TB.Text = item.客戶名稱; 收件人TB.Text = item.收件人; 重量TB.Text = item.重量.ToString(); 責任歸屬TB.Text = item.責任歸屬; 到付CB.Checked = (item.付款方式.Length > 0) ? true : false; 備註TB.Text = item.備註二; 明細TB.Text = item.明細; uidHF.Value = item.uid.ToString(); 原因歸屬DDL.SelectedValue = item.原因歸屬 ?? ""; if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { 款號TB.Text = item.備註; 數量TB.Text = item.快遞數量.ToString(); 單位DDL.SelectedValue = item.快遞單位 ?? ""; } } 新增BT.Visible = false; 更新BT.Visible = true; EditListPanel_ModalPopupExtender.Show(); } } else { 結案顯示(); } } else if (e.CommandName == "刪除") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string strid = ACRGV.DataKeys[row.RowIndex].Values[0].ToString(); using (var transaction = conn.Database.BeginTransaction()) { try { int.TryParse(strid, out iuid); var 刪除快遞單 = conn.快遞單明細.Where(o => o.uid == iuid).FirstOrDefault(); 刪除快遞單.IsDeleted = true; 刪除快遞單.修改日期 = DateTime.Now; conn.SaveChanges(); transaction.Commit(); ACRGV.DataBind(); ClearEdit(); } catch (Exception ex1) { try { Log.ErrorLog(ex1, "Delete Error :", "MGT002.aspx"); } catch (Exception ex2) { Log.ErrorLog(ex2, "Delete Error Error:", "MGT002.aspx"); } finally { transaction.Rollback(); } } } } else if (e.CommandName == "列印") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string struid = ACRGV.DataKeys[row.RowIndex].Values[0].ToString(); Session.RemoveAll(); Session["uid"] = struid; Session["id"] = ACRGV.Rows[row.RowIndex].Cells[1].Text; //Session["提單日期"] = ACRGV.Rows[row.RowIndex].Cells[3].Text; //Response.Redirect("MGT003.aspx"); Response.Redirect("MGT005.aspx"); } } }
protected void DbInit() { ACRGV.DataBind(); }