protected void DeleteBT_Click(object sender, EventArgs e) { int iid = 0; int.TryParse(idHF.Value, out iid); var x = db.快遞單.Find(iid); if (x != null) { try { x.IsDeleted = true; x.修改日期 = DateTime.Now; db.SaveChanges(); idHF.Value = null; } catch (Exception ex) { try { Log.ErrorLog(ex, "Delete Error :", "MGT001.aspx"); } catch (Exception ex2) { Log.ErrorLog(ex2, "Delete Error Error:", "MGT001.aspx"); } } } else { MessageLB.Text = "沒有快遞單資料"; AlertPanel_ModalPopupExtender.Show(); } Show(false); }
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 SaveBT_Click(object sender, EventArgs e) { String savePath = Server.MapPath(@"~\MGT\MGTFile\"); String fileName = FileUpload1.FileName.Trim(); if (FileUpload1.HasFile) { string 副檔名 = System.IO.Path.GetExtension(fileName); if (File.Exists(savePath + fileName)) { fileName = fileName.Substring(0, fileName.Length - 副檔名.Length) + DateTime.Now.ToString("yyyyMMddhhmmssfff") + 副檔名; } savePath = savePath + fileName; FileUpload1.SaveAs(savePath); } else { fileName = ""; } int iid = 0; using (var conn = new GGFEntitiesMGT()) { using (var transaction = conn.Database.BeginTransaction()) { try { int.TryParse(idHF.Value.ToString(), out iid); if (iid == 0) { var 新增快遞單 = new 快遞單(); 新增快遞單.提單日期 = Convert.ToDateTime(快遞日期TB.Text); 新增快遞單.快遞廠商 = 快遞廠商DDL.SelectedValue; 新增快遞單.提單號碼 = 提單號碼TB.Text.Trim(); 新增快遞單.IsDeleted = false; 新增快遞單.送件地點 = 送件地點DDL.SelectedValue; if (fileName.Length > 0) { 新增快遞單.快遞單檔案 = fileName; } 新增快遞單.送件部門 = 部門DDL.SelectedValue ?? "業務部"; 新增快遞單.地點備註 = 地點備註TB.Text.Trim(); 新增快遞單.寄件地點 = 寄件地點DDL.SelectedValue; conn.快遞單.Add(新增快遞單); } else { var 修改快遞單 = conn.快遞單.Find(iid); 修改快遞單.提單日期 = Convert.ToDateTime(快遞日期TB.Text); 修改快遞單.快遞廠商 = 快遞廠商DDL.SelectedValue; 修改快遞單.提單號碼 = 提單號碼TB.Text.Trim(); 修改快遞單.送件地點 = 送件地點DDL.SelectedValue; if (fileName.Length > 0) { 修改快遞單.快遞單檔案 = fileName; } 修改快遞單.送件部門 = 部門DDL.SelectedValue ?? "業務部"; 修改快遞單.地點備註 = 地點備註TB.Text.Trim(); 修改快遞單.修改日期 = DateTime.Now; 修改快遞單.寄件地點 = 寄件地點DDL.SelectedValue; } conn.SaveChanges(); transaction.Commit(); //DbInit(); } catch (Exception ex1) { try { Log.ErrorLog(ex1, "Insert Error :", "MGT001.aspx"); } catch (Exception ex2) { Log.ErrorLog(ex2, "Insert Error Error:", "MGT001.aspx"); } finally { transaction.Rollback(); } } finally { ClearData(); } } } }
protected void 確認GV_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { using (var conn = new GGFEntitiesMGT()) { int iid = 0; if (e.CommandName == "檢貨") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string strid = 確認GV.DataKeys[row.RowIndex].Values[0].ToString(); int.TryParse(strid, out iid); if (iid > 0) { int.TryParse(strid, out iid); using (var transaction = conn.Database.BeginTransaction()) { try { int.TryParse(strid, out iid); var 快遞單結案 = conn.快遞單.Where(o => o.id == iid).FirstOrDefault(); 快遞單結案.檢貨狀態 = true; 快遞單結案.檢貨時間 = DateTime.Now; conn.SaveChanges(); transaction.Commit(); 確認GV.DataBind(); //ACRGV.DataBind(); } catch (Exception ex1) { try { Log.ErrorLog(ex1, "檢貨 Error :", "MGT008.aspx"); } catch (Exception ex2) { Log.ErrorLog(ex2, "檢貨 Error Error:", "MGT008.aspx"); } finally { transaction.Rollback(); } } } } } else if (e.CommandName == "結案") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; string strid = 確認GV.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(); 快遞單結案.結案狀態 = (快遞單結案.結案狀態 == true)?false:true; 快遞單結案.結案時間 = DateTime.Now; conn.SaveChanges(); transaction.Commit(); 確認GV.DataBind(); //ACRGV.DataBind(); } catch (Exception ex1) { try { Log.ErrorLog(ex1, "結案 Error :", "MGT008.aspx"); } catch (Exception ex2) { Log.ErrorLog(ex2, "結案 Error Error:", "MGT008.aspx"); } finally { transaction.Rollback(); } } } } } }
private void 新增修改() { StringBuilder sbError = new StringBuilder(); using (var conn = new GGFEntitiesMGT()) { using (var transaction = conn.Database.BeginTransaction()) { try { int iuid = 0, iid = 0; decimal d重量 = 0; decimal.TryParse(重量TB.Text, out d重量); int.TryParse(uidHF.Value, out iuid); int.TryParse(idHF.Value, out iid); var 工號資料 = db.bas_employee.Where(p => p.site == "GGF" && p.employee_no == 寄件人工號TB.Text).FirstOrDefault(); if (iid == 0) { sbError.Append("Please search again"); } if (工號資料 == null) { sbErrorstring(sbError, "No ID"); } else { if (工號資料.employee_status == "IA") { sbErrorstring(sbError, "Invalid ID"); } } if (d重量 == 0) { sbErrorstring(sbError, "No weight"); } if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { sbErrorstring(sbError, (string.IsNullOrEmpty(數量TB.Text) || string.IsNullOrEmpty(單位DDL.SelectedValue))? 快遞廠商LB.Text + "快遞單需" : ""); if (string.IsNullOrEmpty(數量TB.Text)) { sbErrorstring(sbError, "No Qty"); } if (string.IsNullOrEmpty(單位DDL.SelectedValue)) { sbErrorstring(sbError, "No unit"); } if (!string.IsNullOrEmpty(客戶名稱TB.Text)) { if (!F_確認客戶代號()) { sbErrorstring(sbError, "Please enter the correct customer code"); } } } if (string.IsNullOrEmpty(收件人TB.Text.Trim())) { sbErrorstring(sbError, "No ID"); } if (string.IsNullOrEmpty(客戶名稱TB.Text.Trim())) { sbErrorstring(sbError, "No receive company"); } if (string.IsNullOrEmpty(責任歸屬TB.Text)) { sbErrorstring(sbError, "No responsibility:great giant payment key in GG"); } if (string.IsNullOrEmpty(明細TB.Text)) { sbErrorstring(sbError, "No detail"); } if (string.IsNullOrEmpty(原因歸屬DDL.SelectedValue)) { sbErrorstring(sbError, "No reason"); } if (F_確認結案(iid)) { sbErrorstring(sbError, "Express order closed,resend package tomorrow"); } if (sbError.Length > 0) { EditMessageLB.Text = sbError.ToString(); EditListPanel_ModalPopupExtender.Show(); } else { if (iuid == 0) { var 新增快遞單明細 = new 快遞單明細(); 新增快遞單明細.id = int.Parse(idHF.Value); 新增快遞單明細.付款方式 = (到付CB.Checked) ? "到付" : ""; 新增快遞單明細.寄件人工號 = 寄件人工號TB.Text.Trim(); 新增快遞單明細.寄件人 = 工號資料.employee_name; 新增快遞單明細.寄件人分機 = 分機TB.Text.Trim(); 新增快遞單明細.客戶名稱 = 客戶名稱TB.Text.Trim(); 新增快遞單明細.寄件人部門 = 工號資料.dept_no; 新增快遞單明細.收件人 = 收件人TB.Text.Trim(); 新增快遞單明細.IsDeleted = false; 新增快遞單明細.重量 = d重量; 新增快遞單明細.責任歸屬 = 責任歸屬TB.Text.Trim(); 新增快遞單明細.備註二 = 備註TB.Text.Trim(); 新增快遞單明細.明細 = 明細TB.Text.Trim(); 新增快遞單明細.email = 工號資料.email_address; 新增快遞單明細.原因歸屬 = 原因歸屬DDL.SelectedValue; if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { if (!string.IsNullOrEmpty(款號TB.Text)) { 新增快遞單明細.備註 = 款號TB.Text.Trim().ToUpper(); } 新增快遞單明細.快遞數量 = int.Parse(數量TB.Text); 新增快遞單明細.快遞單位 = 單位DDL.SelectedValue; } conn.快遞單明細.Add(新增快遞單明細); } else { var 新增快遞單明細 = conn.快遞單明細.Find(iuid); //新增快遞單明細.id = int.Parse(idHF.Value); 新增快遞單明細.付款方式 = (到付CB.Checked) ? "到付" : ""; 新增快遞單明細.寄件人工號 = 寄件人工號TB.Text.Trim(); 新增快遞單明細.寄件人 = 工號資料.employee_name; 新增快遞單明細.寄件人分機 = 分機TB.Text.Trim(); 新增快遞單明細.寄件人部門 = 工號資料.dept_no; 新增快遞單明細.收件人 = 收件人TB.Text.Trim(); 新增快遞單明細.重量 = d重量; 新增快遞單明細.責任歸屬 = 責任歸屬TB.Text.Trim(); 新增快遞單明細.備註二 = 備註TB.Text.Trim(); 新增快遞單明細.明細 = 明細TB.Text.Trim(); 新增快遞單明細.修改日期 = DateTime.Now; 新增快遞單明細.email = 工號資料.email_address; 新增快遞單明細.原因歸屬 = 原因歸屬DDL.SelectedValue; if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { if (!string.IsNullOrEmpty(款號TB.Text)) { 新增快遞單明細.備註 = 款號TB.Text.Trim().ToUpper(); } 新增快遞單明細.快遞數量 = int.Parse(數量TB.Text); 新增快遞單明細.快遞單位 = 單位DDL.SelectedValue; } } conn.SaveChanges(); transaction.Commit(); DbInit(); ClearEdit(); } } 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>"); } } } } }
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"); } } }
private void 新增修改() { StringBuilder sbError = new StringBuilder(); using (var conn = new GGFEntitiesMGT()) { using (var transaction = conn.Database.BeginTransaction()) { try { int iuid = 0, iid = 0; decimal d重量 = 0; decimal.TryParse(重量TB.Text, out d重量); int.TryParse(uidHF.Value, out iuid); int.TryParse(idHF.Value, out iid); string str快遞人 = ""; if (寄件人DDL.SelectedItem.Text == "河內快遞") { str快遞人 = "C180100"; } else if (寄件人DDL.SelectedItem.Text == "寧平快遞") { str快遞人 = "B180100"; } else { using (SqlConnection conn1 = new SqlConnection(strConnectEIPString)) { SqlCommand command = new SqlCommand(); command.Connection = conn1; command.CommandText = @"SELECT distinct top 1 dept_boss1 FROM [dbo].[Dept] where Dept = @Dept"; command.CommandType = CommandType.Text; command.Parameters.Add("@Dept", SqlDbType.NVarChar).Value = 寄件人DDL.SelectedItem.Text; conn1.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { if (reader.Read()) { //DataReader讀出欄位內資料的方式,通常也可寫Reader[0]、[1]...[N]代表第一個欄位到N個欄位。 str快遞人 = reader.GetString(0); } } reader.Close(); } } var 工號資料 = db.bas_employee.Where(p => p.site == "GGF" && p.employee_no == str快遞人).FirstOrDefault(); if (iid == 0) { sbError.Append("Please search again"); } if (工號資料 == null) { sbErrorstring(sbError, "No ID"); } else { if (工號資料.employee_status == "IA") { sbErrorstring(sbError, "Invalid ID"); } } //if (d重量 == 0) // sbErrorstring(sbError, "No weight"); if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { sbErrorstring(sbError, (string.IsNullOrEmpty(數量TB.Text) || string.IsNullOrEmpty(單位DDL.SelectedValue))? 快遞廠商LB.Text + "快遞單需" : ""); if (string.IsNullOrEmpty(數量TB.Text)) { sbErrorstring(sbError, "No Qty"); } if (string.IsNullOrEmpty(單位DDL.SelectedValue)) { sbErrorstring(sbError, "No unit"); } if (!string.IsNullOrEmpty(客戶名稱TB.Text)) { if (!F_確認客戶代號()) { sbErrorstring(sbError, "Please enter the correct customer code"); } } } if (string.IsNullOrEmpty(收件人TB.Text.Trim())) { sbErrorstring(sbError, "No receiver"); } if (string.IsNullOrEmpty(客戶名稱TB.Text.Trim())) { sbErrorstring(sbError, "No receive company"); } //if (string.IsNullOrEmpty(責任歸屬TB.Text)) // sbErrorstring(sbError, "No responsibility:great giant payment key in GG"); if (責任歸屬DDL.SelectedValue != "GG" && string.IsNullOrEmpty(責任歸屬備註TB.Text)) { sbErrorstring(sbError, "No 責任歸屬說明"); } if (string.IsNullOrEmpty(明細TB.Text)) { sbErrorstring(sbError, "No detail"); } if (string.IsNullOrEmpty(原因歸屬DDL.SelectedValue)) { sbErrorstring(sbError, "No reason"); } if (F_確認結案(iid)) { sbErrorstring(sbError, "Express order closed,resend package tomorrow"); } if (sbError.Length > 0) { EditMessageLB.Text = sbError.ToString(); EditListPanel_ModalPopupExtender.Show(); } else { if (iuid == 0) { var 新增快遞單明細 = new 快遞單明細(); //if (寄件人DDL.SelectedItem.Text == "河內快遞") //{ // 新增快遞單明細.寄件人部門 = "J010"; //} //else if (寄件人DDL.SelectedItem.Text == "寧平快遞") //{ // 新增快遞單明細.寄件人部門 = "J010"; //} //else // using (SqlConnection conn1 = new SqlConnection(strConnectEIPString)) // { // SqlCommand command = new SqlCommand(); // command.Connection = conn1; // command.CommandText = @"SELECT distinct top 1 Dept_ID // FROM [dbo].[Dept] where Dept = @Dept"; // command.CommandType = CommandType.Text; // command.Parameters.Add("@Dept_ID", SqlDbType.NVarChar).Value = 寄件人DDL.SelectedItem.Text; // conn1.Open(); // SqlDataReader reader = command.ExecuteReader(); // if (reader.HasRows) // { // if (reader.Read()) // { // //DataReader讀出欄位內資料的方式,通常也可寫Reader[0]、[1]...[N]代表第一個欄位到N個欄位。 // 新增快遞單明細.寄件人部門 = reader.GetString(0); // } // } // reader.Close(); // } 新增快遞單明細.寄件人部門 = 寄件人DDL.SelectedValue; 新增快遞單明細.id = int.Parse(idHF.Value); 新增快遞單明細.付款方式 = (到付CB.Checked) ? "到付" : ""; 新增快遞單明細.寄件人工號 = 工號資料.employee_no; 新增快遞單明細.寄件人 = 工號資料.employee_name; 新增快遞單明細.寄件人分機 = 分機TB.Text.Trim(); 新增快遞單明細.客戶名稱 = 客戶名稱TB.Text.Trim(); //新增快遞單明細.寄件人部門 = 工號資料.dept_no; 新增快遞單明細.收件人 = 收件人TB.Text.Trim(); 新增快遞單明細.IsDeleted = false; 新增快遞單明細.重量 = d重量; //新增快遞單明細.責任歸屬 = 責任歸屬TB.Text.Trim(); 新增快遞單明細.責任歸屬 = 責任歸屬DDL.SelectedValue; if (責任歸屬備註TB.Visible) { 新增快遞單明細.責任歸屬備註 = 責任歸屬備註TB.Text; } 新增快遞單明細.備註二 = 備註TB.Text.Trim(); 新增快遞單明細.明細 = 明細TB.Text.Trim(); 新增快遞單明細.email = 工號資料.email_address; 新增快遞單明細.原因歸屬 = 原因歸屬DDL.SelectedValue; if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { if (!string.IsNullOrEmpty(款號TB.Text)) { 新增快遞單明細.備註 = 款號TB.Text.Trim().ToUpper(); } 新增快遞單明細.快遞數量 = int.Parse(數量TB.Text); 新增快遞單明細.快遞單位 = 單位DDL.SelectedValue; } conn.快遞單明細.Add(新增快遞單明細); } else { var 新增快遞單明細 = conn.快遞單明細.Find(iuid); //if (寄件人DDL.SelectedItem.Text == "河內快遞") //{ // 新增快遞單明細.寄件人部門 = "J010"; //} //else if (寄件人DDL.SelectedItem.Text == "寧平快遞") //{ // 新增快遞單明細.寄件人部門 = "J010"; //} //else // using (SqlConnection conn1 = new SqlConnection(strConnectEIPString)) // { // SqlCommand command = new SqlCommand(); // command.Connection = conn1; // command.CommandText = @"SELECT distinct top 1 Dept_ID // FROM [dbo].[Dept] where Dept = @Dept"; // command.CommandType = CommandType.Text; // command.Parameters.Add("@Dept", SqlDbType.NVarChar).Value = 寄件人DDL.SelectedItem.Text; // conn1.Open(); // SqlDataReader reader = command.ExecuteReader(); // if (reader.HasRows) // { // if (reader.Read()) // { // //DataReader讀出欄位內資料的方式,通常也可寫Reader[0]、[1]...[N]代表第一個欄位到N個欄位。 // 新增快遞單明細.寄件人部門 = reader.GetString(0); // } // } // reader.Close(); // } 新增快遞單明細.寄件人部門 = 寄件人DDL.SelectedValue; //新增快遞單明細.id = int.Parse(idHF.Value); 新增快遞單明細.付款方式 = (到付CB.Checked) ? "到付" : ""; 新增快遞單明細.寄件人工號 = 工號資料.employee_no; 新增快遞單明細.寄件人 = 工號資料.employee_name; 新增快遞單明細.寄件人分機 = 分機TB.Text.Trim(); //新增快遞單明細.寄件人部門 = 工號資料.dept_no; 新增快遞單明細.收件人 = 收件人TB.Text.Trim(); 新增快遞單明細.重量 = d重量; //新增快遞單明細.責任歸屬 = 責任歸屬TB.Text.Trim(); 新增快遞單明細.責任歸屬 = 責任歸屬DDL.SelectedValue; 新增快遞單明細.責任歸屬備註 = (責任歸屬備註TB.Visible)?責任歸屬備註TB.Text:""; 新增快遞單明細.備註二 = 備註TB.Text.Trim(); 新增快遞單明細.明細 = 明細TB.Text.Trim(); 新增快遞單明細.修改日期 = DateTime.Now; 新增快遞單明細.email = 工號資料.email_address; 新增快遞單明細.原因歸屬 = 原因歸屬DDL.SelectedValue; if (快遞廠商LB.Text.ToUpper() == "DHL" || 快遞廠商LB.Text.ToUpper() == "FEDEX") { if (!string.IsNullOrEmpty(款號TB.Text)) { 新增快遞單明細.備註 = 款號TB.Text.Trim().ToUpper(); } 新增快遞單明細.快遞數量 = int.Parse(數量TB.Text); 新增快遞單明細.快遞單位 = 單位DDL.SelectedValue; } } conn.SaveChanges(); transaction.Commit(); DbInit(); ClearEdit(); } } 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>"); } } } } }