public void List_country(string id) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @" select * from DealersC where R_no=@R_no"; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("R_no", id); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); ((DropDownList)this.Master.FindControl("ContentPlaceHolder1").FindControl(("C_no"))).Items.Clear(); while (dr.Read()) { ((DropDownList)this.Master.FindControl("ContentPlaceHolder1").FindControl(("C_no"))).Items.Add(new ListItem(dr[2].ToString(), dr[1].ToString())); } } catch (Exception ex) { DB_string.log("Dealers_List_country:", ex.ToString()); } finally { Conn.Close(); } }
public static DataTable GetNo(string nokey, string ap) { //宣告SQL的連線 SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select REPLICATE('0',7- Len(cast(isnull(max(substring(" + nokey + ",9,7)),0)+1 as varchar(7)) )) + cast(isnull(max(substring(" + nokey + ",9,7)),0)+1 as varchar(7)) as sno from [" + ap + "]"; SqlCommand cmd = new SqlCommand(CmdString, Conn); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); return(dt); } catch (Exception ex) { DB_string.log("GetNo:", ex.ToString()); return(null); } finally { Conn.Close(); } }
//綁定grid 參數表parameter 值 public static string gridbind(string tablename, string keystring, string value) { string str_json = ""; SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); DataTable dt = new DataTable(); try { string SelCmdString = @""; SelCmdString = @"select value_string from Parameter where Table_name=@tablename and Key_string=@key_string and Value=@value "; SqlCommand Selcmd = new SqlCommand(SelCmdString, Conn); Selcmd.Parameters.AddWithValue("tablename", tablename); Selcmd.Parameters.AddWithValue("key_string", keystring); Selcmd.Parameters.AddWithValue("value", value); Selcmd.ExecuteNonQuery(); SqlDataReader dr = Selcmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); str_json = dt.Rows[0]["value_string"].ToString(); } catch (Exception ex) { DB_string.log("AuthInit:", ex.ToString()); str_json = "{\"Type\": \"失敗\"}"; } finally { Conn.Close(); } return(str_json); }
protected void Region_sel() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select * from DealersR "; SqlCommand cmd = new SqlCommand(CmdString, Conn); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); foreach (DataRow dr_ in dt.Rows) { dl_Region.Items.Add(new ListItem(dr_["Region"].ToString(), dr_["R_no"].ToString())); } } catch (Exception ex) { DB_string.log("Contact_dl:", ex.ToString()); } finally { Conn.Close(); } }
public static DataTable Dealers() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select * from DealersR "; SqlCommand cmd = new SqlCommand(CmdString, Conn); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); return(dt); } catch (Exception ex) { DB_string.log("Dealers:", ex.ToString()); return(null); } finally { Conn.Close(); } }
public static DataTable News_sel(string id) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select Title,Context from News where Newsno=@Newsno"; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("Newsno", id); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); return(dt); } catch (Exception ex) { DB_string.log("News_view:", ex.ToString()); return(null); } finally { Conn.Close(); } }
protected void Rpt_sidebar_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataRowView drv = (DataRowView)e.Item.DataItem; string t_no = drv["T_no"].ToString(); Repeater childRepeater = (Repeater)e.Item.FindControl("Rpt_sidebar_detail"); SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @" select * from tabledetail where t_no = @t_no order by seq "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("t_no", t_no); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); childRepeater.DataSource = dt; childRepeater.DataBind(); } catch (Exception ex) { DB_string.log("Sel_sidebar_detail:", ex.ToString()); } finally { Conn.Close(); } } }
protected void del_Click(object sender, EventArgs e) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"delete from Yachts where Yachtsno=@id "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("id", id.Value); Conn.Open(); cmd.ExecuteNonQuery(); del_img(id.Value); del_file(id.Value); } catch (Exception ex) { DB_string.log("Yachts_del:", ex.ToString()); ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "<script>swal('刪除失敗')</script>", false); } finally { Conn.Close(); Response.Redirect("Yachts.aspx?type=yachts"); } }
public void DBinit() { try { if (!Directory.Exists(HttpContext.Current.Server.MapPath("/") + @"/sqlimages/Album/" + id.Value)) { //新增資料夾 Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/") + @"/sqlimages/Album/" + id.Value); } DirectoryInfo di = new DirectoryInfo(Server.MapPath("/sqlimages/Album/" + id.Value)); FileInfo[] fi = di.GetFiles(); DataTable dt = new DataTable(); DataColumn dcFilename = new DataColumn("strFilename", Type.GetType("System.String")); dt.Columns.Add(dcFilename); Object[] data = new object[1]; foreach (FileInfo file in fi) { data[0] = id.Value + "/" + file.Name; dt.Rows.Add(data); } Rpt_Yachts.DataSource = dt; Rpt_Yachts.DataBind(); } catch (Exception ex) { DB_string.log("Yachts_DBinit:", ex.ToString()); } }
public static DataTable Shiptype_sel() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @" select Yachtsno,Modal,Modal_n,Isnew from Yachts "; SqlCommand cmd = new SqlCommand(CmdString, Conn); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); return(dt); } catch (Exception ex) { DB_string.log("Yachts_Shiptype_sel:", ex.ToString()); return(null); } finally { Conn.Close(); } }
public DataTable Get_Init() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @" select Group_view from GroupDetail where G_no=@G_no "; SqlCommand cmd = new SqlCommand(CmdString, Conn); Conn.Open(); cmd.Parameters.AddWithValue("G_no", id.Value); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); return(dt); } catch (Exception ex) { DB_string.log("Auth_edit_init:", ex.ToString()); return(null); } finally { Conn.Close(); } }
//權限群組 刪除--auth_edit.aspx--del public static string AuthDel(string G_no) { string str_json = ""; SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); SqlTransaction tran = Conn.BeginTransaction(); try { string DelCmdString = @""; DelCmdString = @"delete from GroupDetail where G_no=@G_no "; SqlCommand Delcmd = new SqlCommand(DelCmdString, Conn, tran); Delcmd.Parameters.AddWithValue("G_no", G_no); Delcmd.ExecuteNonQuery(); tran.Commit(); } catch (Exception ex) { tran.Rollback(); DB_string.log("AuthDel:", ex.ToString()); str_json = "{\"Type\": \"失敗\"}"; } finally { Conn.Close(); } return(str_json); }
//權限群組 初始化--auth_edit.aspx--init public static string Init(string G_no) { string str_json = ""; SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); DataTable dt = new DataTable(); try { string SelCmdString = @""; SelCmdString = @"select Group_view from GroupDetail where G_no=@G_no "; SqlCommand Selcmd = new SqlCommand(SelCmdString, Conn); Selcmd.Parameters.AddWithValue("G_no", G_no); Selcmd.ExecuteNonQuery(); SqlDataReader dr = Selcmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); str_json = JsonConvert.SerializeObject(dt, Newtonsoft.Json.Formatting.Indented); str_json = "{\"Type\": \"成功\",\"detail\":" + str_json + "}"; } catch (Exception ex) { DB_string.log("AuthInit:", ex.ToString()); str_json = "{\"Type\": \"失敗\"}"; } finally { Conn.Close(); } return(str_json); }
public void Employee(string id) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select * from Employee where Username=@Username "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("Username", id); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); Username.Value = dt.Rows[0]["Username"].ToString(); Password.Value = dt.Rows[0]["Password"].ToString(); Auth.SelectedValue = dt.Rows[0]["Auth"].ToString(); } catch (Exception ex) { DB_string.log("Employee_edit:", ex.ToString()); } finally { Conn.Close(); } }
protected void del_Click(object sender, EventArgs e) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"DELETE FROM DealersR where R_no=@R_no"; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("R_no", id.Value); Conn.Open(); cmd.ExecuteNonQuery(); Conn.Close(); Response.Redirect("Dealers.aspx?type=dealers"); } catch (Exception ex) { DB_string.log("Dealers_edit_del:", ex.ToString()); ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "<script>swal('刪除失敗','地區尚未全刪除')</script>", false); } finally { } }
public void Default_sel() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @" select top 1 Yachtsno from Yachts "; SqlCommand cmd = new SqlCommand(CmdString, Conn); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); if (dt.Rows.Count > 0) { id.Value = dt.Rows[0]["Yachtsno"].ToString(); } } catch (Exception ex) { DB_string.log("Yachts_Default_sel:", ex.ToString()); } finally { Conn.Close(); } }
protected void pwd_save_Click() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); SqlTransaction tran = Conn.BeginTransaction(); DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"update Employee set Password=@pwd where Username=@Username "; SqlCommand cmd = new SqlCommand(CmdString, Conn, tran); cmd.Parameters.AddWithValue("Username", Session["Username"].ToString()); string des_Password = DB_fountion.EncryptDES(npwd.Value);//加密 cmd.Parameters.AddWithValue("pwd", des_Password); cmd.ExecuteNonQuery(); tran.Commit(); ScriptManager.RegisterStartupScript(Page, GetType(), "alert_success", "<script>swal('修改成功')</script>", false); } catch (Exception ex) { tran.Rollback(); DB_string.log("Account:", ex.ToString()); } finally { Conn.Close(); } }
protected void del_row(string id_) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); SqlTransaction tran = Conn.BeginTransaction(); DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"delete from DealersC where R_no=@R_no and C_no=@C_no"; SqlCommand cmd = new SqlCommand(CmdString, Conn, tran); cmd.Parameters.AddWithValue("R_no", id.Value); cmd.Parameters.AddWithValue("C_no", id_); cmd.ExecuteNonQuery(); tran.Commit(); } catch (Exception ex) { tran.Rollback(); DB_string.log("Dealers_edit:", ex.ToString()); } finally { Conn.Close(); } }
protected void Detail(string id) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select * from DealersC where R_no=@R_no "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("R_no", id); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); ViewState["Detail"] = dt; Grid_DealersC.DataSource = dt; Grid_DealersC.DataBind(); } catch (Exception ex) { DB_string.log("Dealers_edit:", ex.ToString()); } finally { Conn.Close(); } }
public void Dealers(string id) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select * from DealersR where R_no=@R_no "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("R_no", id); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); R_no.Value = dt.Rows[0]["R_no"].ToString(); Region.Value = dt.Rows[0]["Region"].ToString(); } catch (Exception ex) { DB_string.log("Dealers_edit:", ex.ToString()); } finally { Conn.Close(); } }
public void Context_sel() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @" select Modal,Modal_n,Specification from Yachts where Yachtsno = @id"; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("id", id.Value); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); if (dt.Rows.Count > 0) { context.InnerHtml = dt.Rows[0]["Specification"].ToString(); ship_name.InnerText = dt.Rows[0]["Modal"].ToString() + " " + dt.Rows[0]["Modal_n"].ToString(); ship_name_nav.InnerText = dt.Rows[0]["Modal"].ToString() + " " + dt.Rows[0]["Modal_n"].ToString(); } } catch (Exception ex) { DB_string.log("Yachts_Context_sel:", ex.ToString()); } finally { Conn.Close(); } }
protected void save_Click() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"insert into Employee (Username,Password,Auth) values (@Username,@Password,@Auth)"; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("id", id.Value); cmd.Parameters.AddWithValue("Username", Username.Value); string des_Password = DB_fountion.EncryptDES(Password.Value);//加密 cmd.Parameters.AddWithValue("Password", des_Password); cmd.Parameters.AddWithValue("Auth", Auth.SelectedValue); cmd.ExecuteNonQuery(); } catch (Exception ex) { DB_string.log("Employee_ins:", ex.ToString()); } finally { Conn.Close(); Response.Redirect("Employee.aspx?type=basic"); } }
protected void Del_Click(string R_no) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"DELETE FROM DealersR where R_no=@R_no "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("R_no", R_no); Conn.Open(); cmd.ExecuteNonQuery(); DataTable dt2 = Dealers(); Grid_Dealers.DataSource = dt2; Grid_Dealers.DataBind(); ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "<script>swal('刪除成功')</script>", false); } catch (Exception ex) { DB_string.log("Dealers_del:", ex.ToString()); ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "<script>swal('刪除失敗','地區尚未全刪除')</script>", false); } finally { Conn.Close(); } }
public DataTable News_sel() { //分頁用 int currentPage = Request["page"] == null ? 1 : int.Parse(Request["page"]); SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"with tstation as ( select row_number() over(order by inday desc) as rownumber, * from News )select *from tstation where rownumber>=@start and rownumber <=@end "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.Add("@start", SqlDbType.Int); cmd.Parameters["@start"].Value = ((currentPage - 1) * PageSize) + 1; cmd.Parameters.Add("@end", SqlDbType.Int); cmd.Parameters["@end"].Value = currentPage * PageSize; Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); //分頁 SqlCommand totalcommand; totalcommand = new SqlCommand(@"select count('x') from News ", Conn); SqlDataAdapter totalAdapter = new SqlDataAdapter(totalcommand); DataTable totalTable = new DataTable(); totalAdapter.Fill((totalTable)); int total = Convert.ToInt32(totalTable.Rows[0][0]); Pagination1.totalitems = total; Pagination1.limit = PageSize; Pagination1.targetpage = "News.aspx"; //技巧:利用這種方式才可以呼叫usercontrol裡的public method Pagination1.showPageControls(); return(dt); } catch (Exception ex) { DB_string.log("News:", ex.ToString()); return(null); } finally { Conn.Close(); } }
protected void save_Click() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); DataTable dt = new DataTable(); try { string state = Request.QueryString["action"]; //string id = ""; //if ((Session["id"] != null) && (Session["id"].ToString() != "")) //{ // id = Session["id"].ToString(); //} string CmdString = @""; if (state == "ins") { CmdString = @"insert into Employee (Username,Password,Auth) values (@Username,@Password,@Auth)"; } else {//,Password=@Password CmdString = @"update Employee set Username=@Username,Auth=@Auth where Username=@id"; } SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("id", id.Value); cmd.Parameters.AddWithValue("Username", Username.Value); //string des_Password = DB_fountion.EncryptDES(Password.Value);//加密 //cmd.Parameters.AddWithValue("Password", des_Password); cmd.Parameters.AddWithValue("Auth", Auth.SelectedValue); cmd.ExecuteNonQuery(); } catch (Exception ex) { DB_string.log("Employee_edit:", ex.ToString()); } finally { Conn.Close(); Response.Redirect("Employee.aspx?type=basic"); } }
public void Yachts(string id) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"select * from Yachts where Yachtsno=@Yachtsno "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("Yachtsno", id); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); Yachtsno.Value = dt.Rows[0]["Yachtsno"].ToString(); Modal.Value = dt.Rows[0]["Modal"].ToString(); Modal_n.Value = dt.Rows[0]["Modal_n"].ToString(); Overview.Value = dt.Rows[0]["Overview"].ToString(); Layout.Value = dt.Rows[0]["Layout"].ToString(); Specification.Value = dt.Rows[0]["Specification"].ToString(); Isnew.SelectedValue = dt.Rows[0]["Isnew"].ToString(); //圖 if (!string.IsNullOrEmpty(dt.Rows[0]["Img"].ToString())) { Random rand = new Random(); img.ImageUrl = "~/sqlimages/Yachts/" + dt.Rows[0]["Yachtsno"].ToString() + "/" + dt.Rows[0]["Img"].ToString() + "?" + rand.Next(1000).ToString(); img_temp.Value = dt.Rows[0]["Img"].ToString(); } ////檔案 //file_url.HRef = "~/sqlimages/Yachts_file/" + id + "/" + dt.Rows[0]["Files"].ToString(); //file_url.InnerText = dt.Rows[0]["Files"].ToString(); } catch (Exception ex) { DB_string.log("Yachts_edit:", ex.ToString()); } finally { Conn.Close(); } }
protected void DBInit() { //宣告SQL的連線 SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string str = ""; if (ser1.Text != "") { str += " and R_no like @ser1"; } if (ser2.Text != "") { str += " and Region like @ser2"; } string CmdString = @""; CmdString = @"select R_no, Region from DealersR where 1=1 " + str; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("ser1", "%" + ser1.Text + "%"); cmd.Parameters.AddWithValue("ser2", "%" + ser2.Text + "%"); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); ViewState["detail"] = dt; GridView1.DataSource = dt; GridView1.DataBind(); } catch (Exception ex) { DB_string.log("FindDealersR:", ex.ToString()); } finally { Conn.Close(); } }
public void DealearD(string id) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @" select * from DealersD d join DealersC c on d.C_no = c.C_no and d.R_no = c.R_no join DealersR r on d.R_no = r.R_no where d.D_no=@D_no "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("D_no", id); Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(dr); R_no.Value = dt.Rows[0]["R_no"].ToString(); Region.Value = dt.Rows[0]["Region"].ToString(); List_country(R_no.Value);//先產生下拉的值 C_no.SelectedValue = dt.Rows[0]["C_no"].ToString(); D_no.Value = dt.Rows[0]["D_no"].ToString(); Info.Value = dt.Rows[0]["Info"].ToString(); //圖 if (!string.IsNullOrEmpty(dt.Rows[0]["Img"].ToString())) { Random rand = new Random(); img.ImageUrl = "~/sqlimages/Dealers/" + dt.Rows[0]["D_no"].ToString() + "/min_" + dt.Rows[0]["Img"].ToString() + "?" + rand.Next(1000).ToString(); img_temp.Value = dt.Rows[0]["Img"].ToString(); } } catch (Exception ex) { DB_string.log("Dealers_edit:", ex.ToString()); } finally { Conn.Close(); } }
protected void save_Click() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); SqlTransaction tran = Conn.BeginTransaction(); DataTable dt = new DataTable(); try { string selCmdString = @""; selCmdString = @"select IDENT_CURRENT('DealersD')+1 "; SqlCommand selcmd = new SqlCommand(selCmdString, Conn, tran); SqlDataReader dr = selcmd.ExecuteReader(); while (dr.Read()) { Update_img(dr[0].ToString());//新增圖片 dr[0] 圖片下一個新增的sql identity序號 } dr.Close(); string CmdString = @""; CmdString = @"INSERT INTO DealersD (R_no, C_no, Info,Img) VALUES (@R_no,@C_no,@Info,@Img); "; SqlCommand cmd = new SqlCommand(CmdString, Conn, tran); cmd.Parameters.AddWithValue("R_no", R_no.Value); cmd.Parameters.AddWithValue("C_no", C_no.SelectedValue); cmd.Parameters.AddWithValue("Info", Info.Value); cmd.Parameters.AddWithValue("Img", img_temp.Value); cmd.ExecuteNonQuery(); tran.Commit(); } catch (Exception ex) { tran.Rollback(); DB_string.log("DealersDetail_ins:", ex.ToString()); } finally { Conn.Close(); Response.Redirect("DealersDetail.aspx?type=dealers"); } }
protected void save_Click() { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; Conn.Open(); DataTable dt = new DataTable(); DataTable serial = new DataTable(); try { string CmdString = @""; CmdString = @"insert into News (Newsno,Title,Info,Context,Inday,Img,Priority) values (@Newsno,@Title,@Info,@Context,@Inday,@Img,@Priority)"; serial = DB_fountion.GetNo("Newsno", "News"); Update_img(DateTime.Now.ToString("yyyyMMdd") + serial.Rows[0]["sno"].ToString());//新增圖片 SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("Newsno", DateTime.Now.ToString("yyyyMMdd") + serial.Rows[0]["sno"].ToString()); cmd.Parameters.AddWithValue("Title", Title_.Value); cmd.Parameters.AddWithValue("Info", Info.Value); cmd.Parameters.AddWithValue("Context", Context_.Value); cmd.Parameters.AddWithValue("Inday", Inday_.Value); cmd.Parameters.AddWithValue("Img", img_temp.Value); cmd.Parameters.AddWithValue("Priority", Priority.SelectedValue); cmd.ExecuteNonQuery(); } catch (Exception ex) { DB_string.log("News_ins:", ex.ToString()); } finally { Conn.Close(); //Response.Redirect("News.aspx?type=news"); Response.Redirect("News_edit.aspx?type=news&id=" + DateTime.Now.ToString("yyyyMMdd") + serial.Rows[0]["sno"].ToString()); //ScriptManager.RegisterStartupScript(Page, GetType(), "success", @"<script> swal({title: '新增成功',text: '跳向編輯頁',},function() {document.location.href = 'News_edit.aspx?type=news&id="+ DateTime.Now.ToString("yyyyMMdd") + serial.Rows[0]["sno"].ToString()+"';});</script>", false); } }