/// <summary> ///执行一个不需要返回值的SqlCommand命令,通过指定专用的连接字符串。 /// 使用参数数组形式提供参数列表 /// </summary> /// <remarks> /// 使用示例: /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); /// </remarks> /// <param name="connectionString">一个有效的数据库连接字符串</param> /// <param name="commandType">SqlCommand命令类型 (存储过程, T-SQL语句, 等等。)</param> /// <param name="commandText">存储过程的名字或者 T-SQL 语句</param> /// <param name="commandParameters">以数组形式提供SqlCommand命令中用到的参数列表</param> /// <returns>返回一个数值表示此SqlCommand命令执行后影响的行数</returns> public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { try { iRedoTimes++; Mylog.Info(cmdText); SqlCommand cmd = new SqlCommand(); using (SqlConnection conn = new SqlConnection(connectionString)) { //通过PrePareCommand方法将参数逐个加入到SqlCommand的参数集合中 PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters); int val = cmd.ExecuteNonQuery(); //清空SqlCommand中的参数列表 cmd.Parameters.Clear(); return(val); } } catch (Exception ex) { Mylog.Error(ex.Message); if (ex.ToString().Contains("死锁") || ex.ToString().Contains("无法访问") || ex.ToString().Contains("超时") || ex.ToString().Contains("传输级")) { if (iRedoTimes % 10 != 0) { return(ExecuteNonQuery(connectionString, cmdType, cmdText, commandParameters)); } // MessageBox.Show("网络异常,点击确定后系统自动重试。如果此异常长时间没有解除,请检查设备或者联系13164846310。\r\b" + ex.ToString().Substring(0, 200)); } else { Mylog.Error(ex.ToString()); } return(0); } }
/// <summary> /// 执行事务 /// </summary> /// <param name="connectionString">一个有效的数据库连接字符串</param> /// <param name="cmdType">SqlCommand命令类型 (存储过程, T-SQL语句, 等等。)</param> /// <returns>return a bool</returns> public static bool ExecuteSqlTran(string connectionString, string strSQL) { char[] de = { ';' }; string strChildSQL; int i; string[] strSQLArr = strSQL.Split(de); bool IsControll = true; SqlConnection conn = new SqlConnection(connectionString); SqlCommand myCommand = new SqlCommand(); SqlTransaction myTrans = null; Mylog.Info(strSQL); try { conn.Open(); myTrans = conn.BeginTransaction(); myCommand.Connection = conn; myCommand.Transaction = myTrans; for (i = 0; i < strSQLArr.Length; i++) { strChildSQL = strSQLArr[i]; myCommand.CommandText = strChildSQL; myCommand.ExecuteNonQuery(); } myTrans.Commit(); IsControll = true; } catch (Exception ex) { Mylog.Error(ex.Message); try { IsControll = false; if (myTrans != null) { myTrans.Rollback(); } //ExecuteSqlTran(connectionString, strSQL); } catch (SqlException sex) { Mylog.Error(sex.Message); } } finally { conn.Close(); } return(IsControll); }
//回复图片信息 public void A_image(string FromUserName, string ToUserName, string MediaId, HttpResponseBase Response) { Mylog.Addlog(MediaId, "img", ""); //回复图片 string resxml = string.Format(@"<xml> <ToUserName><![CDATA[{0}]]></ToUserName> <FromUserName><![CDATA[{1}]]></FromUserName> <CreateTime>{2}</CreateTime> <MsgType><![CDATA[image]]></MsgType> <Image> <MediaId><![CDATA[{3}]]></MediaId> </Image> </xml>", FromUserName, ToUserName, ConvertDateTimeInt(DateTime.Now), MediaId); Response.Write(resxml); }
/// <summary> /// 执行一条返回结果集的SqlCommand命令,通过专用的连接字符串。 /// 使用参数数组提供参数 /// </summary> /// <remarks> /// 使用示例: /// SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); /// </remarks> /// <param name="connectionString">一个有效的数据库连接字符串</param> /// <param name="commandType">SqlCommand命令类型 (存储过程, T-SQL语句, 等等。)</param> /// <param name="commandText">存储过程的名字或者 T-SQL 语句</param> /// <param name="commandParameters">以数组形式提供SqlCommand命令中用到的参数列表</param> /// <returns>返回一个包含结果的SqlDataReader</returns> public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand cmd = new SqlCommand(); SqlConnection conn = new SqlConnection(connectionString); // 在这里使用try/catch处理是因为如果方法出现异常,则SqlDataReader就不存在, //CommandBehavior.CloseConnection的语句就不会执行,触发的异常由catch捕获。 //关闭数据库连接,并通过throw再次引发捕捉到的异常。 try { PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); cmd.Parameters.Clear(); return(rdr); } catch (Exception ex) { Mylog.Error(ex.Message); conn.Close(); throw; } }
public string dowimg(string serverId) { try { APPIdAndSecret App = new APPIdAndSecret(); string access_token = TokenMannger.Instance.GetToken("test", App.AppID, App.AppSecret); string path = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=" + access_token + "&media_id=" + serverId; WebClient wc = new WebClient(); string name = serverId + ".jpg"; var photofolder = Server.MapPath("~/Images/"); if (!Directory.Exists(photofolder)) { Directory.CreateDirectory(photofolder); } if ((System.IO.File.Exists(photofolder + name))) { return(name); } Mylog.Error(path + " : " + photofolder + "\\" + name); wc.Credentials = CredentialCache.DefaultCredentials; //获取或设置用于向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData = wc.DownloadData(path); //从指定网站下载数据 string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是GB2312 if (!pageHtml.Contains("errmsg")) { wc.DownloadFile(path, photofolder + "\\" + name);//将图片拷贝到 return(name); } else { Mylog.Error(pageHtml); return(""); } } catch (Exception ex) { Mylog.Error(ex.Message); throw; } }
/// <summary> /// return a dataset /// </summary> /// <param name="connectionString">一个有效的数据库连接字符串</param> /// <param name="cmdType">SqlCommand命令类型 (存储过程, T-SQL语句, 等等。)</param> /// <param name="cmdText">存储过程的名字或者 T-SQL 语句</param> /// <param name="commandParameters">以数组形式提供SqlCommand命令中用到的参数列表</param> /// <returns>return a dataset</returns> public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlConnection conn = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(); Mylog.Info(cmdText); try { PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters); SqlDataAdapter da = new SqlDataAdapter(); DataSet ds = new DataSet(); da.SelectCommand = cmd; da.Fill(ds); return(ds); } catch (Exception ex) { Mylog.Error(ex.Message); if (ex.ToString().Contains("死锁") || ex.ToString().Contains("无法访问") || ex.ToString().Contains("超时") || ex.ToString().Contains("传输级")) { if (iRedoTimes % 10 != 0) { return(ExecuteDataSet(connectionString, cmdType, cmdText, commandParameters)); } // MessageBox.Show("网络异常,点击确定后系统自动重试。如果此异常长时间没有解除,请检查设备或者联系13164846310。\r\b" + ex.ToString().Substring(0, 200)); } else { Mylog.Error(ex.ToString()); } return(null); } finally { conn.Close(); } }
private void Dtuw_EventMylog(string type, string log) { Mylog ml = new Mylog(addMylog); textBox1.Invoke(ml, new object[] { txtLog, type + "--" + log }); }
private void HttpServer_EventMylog(string type, string log) { Mylog ml = new Mylog(addMylog); listBox3.Invoke(ml, new object[] { listBox3, type + "--" + log }); }
private void Gw_EventMylog(string type, string log) { Mylog ml = new Mylog(addMylog); txtLog.Invoke(ml,new object[]{ txtLog , type+"--"+log }); }
/// <summary> /// 照片相识度对比 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonResult Compare(string Species, SpeciesPople model) { // <param name="Species">种类(1.1:娃像谁 3人照片 1张;1.2:娃像谁 单人照 3张 ;2.1:夫妻相 双人照 1张;2.2夫妻相 2张)</param> int isLock = 0; string ImgMsg = "图片未完全上传!"; string xiangsidu = string.Empty; Mylog.Log("Species =" + Species + " Child= " + model.Child + " Dad= " + model.Dad + " ManAndWife= " + model.ManAndWife + " ManAndWifeAndChild= " + model.ManAndWifeAndChild + " Mom= " + model.Mom); string fileName = string.Empty; List <DetectResultModels> listmodel = new List <DetectResultModels>(); switch (Species) { case "1.1": //Family3 if (!string.IsNullOrWhiteSpace(model.ManAndWifeAndChild)) { #region MyRegion // model.ManAndWifeAndChild //测试相识度,返回对应信息(孩子像谁????) //下载图片 获取 faceId json fileName = dowimg(model.ManAndWifeAndChild); if (!string.IsNullOrWhiteSpace(fileName)) { controller.Detect(model.ManAndWifeAndChild, fileName); //获取的face信息 model.ManAndWifeAndChild = controller.rest; controller.rest = null; } else { return(Json(new { isLock = 0, ImgMsg = "图片上传出错,请稍后重试;" }, JsonRequestBehavior.AllowGet)); } if (model.ManAndWifeAndChild != null) { //获取照片信息 foreach (var item in JsonConvert.DeserializeObject <dynamic>(model.ManAndWifeAndChild)) { var ResultModels = new DetectResultModels(); ResultModels.faceId = item.faceId; ResultModels.FileName = item.fileName; ResultModels.Age = item.age; ResultModels.Gender = item.gender == "male" ? "男" : "女"; ResultModels.Smile = item.smile; listmodel.Add(ResultModels); } if (listmodel.Count == 3) { isLock = 1; #region 先找出年龄最小的(孩子) if (listmodel[0].Age > listmodel[1].Age) { if (listmodel[1].Age > listmodel[2].Age) { // listmodel[2];//是孩子 #region MyRegion if (listmodel[0].Gender == "男") { double DadAndChild = Getconfidence(listmodel[0].faceId, listmodel[2].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[1].faceId, listmodel[2].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } else { double DadAndChild = Getconfidence(listmodel[1].faceId, listmodel[2].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[0].faceId, listmodel[2].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } #endregion } else { // listmodel[1]//是孩子 #region MyRegion if (listmodel[0].Gender == "男") { double DadAndChild = Getconfidence(listmodel[0].faceId, listmodel[1].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[2].faceId, listmodel[1].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } else { double DadAndChild = Getconfidence(listmodel[2].faceId, listmodel[1].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[0].faceId, listmodel[1].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } #endregion } } else { if (listmodel[0].Age > listmodel[2].Age) { // listmodel[2];//是孩子 #region MyRegion if (listmodel[0].Gender == "男") { double DadAndChild = Getconfidence(listmodel[0].faceId, listmodel[2].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[1].faceId, listmodel[2].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } else { double DadAndChild = Getconfidence(listmodel[1].faceId, listmodel[2].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[0].faceId, listmodel[2].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } #endregion } else { // listmodel[0];//是孩子 #region MyRegion if (listmodel[1].Gender == "男") { double DadAndChild = Getconfidence(listmodel[1].faceId, listmodel[0].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[2].faceId, listmodel[0].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } else { double DadAndChild = Getconfidence(listmodel[2].faceId, listmodel[0].faceId); //孩子与爸爸对比 double WifeAndChild = Getconfidence(listmodel[1].faceId, listmodel[0].faceId); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } #endregion } } #endregion } else { ImgMsg = "请上传一张清晰的一个孩子与父母的合影!"; } } else { ImgMsg = "图片处理失败!请重新上传清晰的图片"; //图片处理失败(获取faceId 失败) } #endregion } listmodel = null; break; case "1.2": //Family if (!string.IsNullOrWhiteSpace(model.Child) && !string.IsNullOrWhiteSpace(model.Mom) && !string.IsNullOrWhiteSpace(model.Dad)) { #region 载图片 获取 faceId json fileName = dowimg(model.Mom); if (!string.IsNullOrWhiteSpace(fileName)) { controller.Detect(model.Mom, fileName); //获取的face信息 model.Mom = controller.rest; controller.rest = null; } else { return(Json(new { isLock = 0, ImgMsg = "图片上传出错,请稍后重试;" }, JsonRequestBehavior.AllowGet)); } fileName = dowimg(model.Dad); if (!string.IsNullOrWhiteSpace(fileName)) { controller.Detect(model.Dad, fileName); //获取的face信息 model.Dad = controller.rest; controller.rest = null; } else { return(Json(new { isLock = 0, ImgMsg = "图片上传出错,请稍后重试;" }, JsonRequestBehavior.AllowGet)); } fileName = dowimg(model.Child); if (!string.IsNullOrWhiteSpace(fileName)) { controller.Detect(model.Child, fileName); //获取的face信息 model.Child = controller.rest; controller.rest = null; } else { return(Json(new { isLock = 0, ImgMsg = "图片上传出错,请稍后重试;" }, JsonRequestBehavior.AllowGet)); } #endregion #region MyRegion if (model.Child != null && model.Mom != null && model.Dad != null) { //获取照片信息 model.Child = JsonConvert.DeserializeObject <dynamic>(model.Child)[0].faceId; model.Mom = JsonConvert.DeserializeObject <dynamic>(model.Mom)[0].faceId; model.Dad = JsonConvert.DeserializeObject <dynamic>(model.Dad)[0].faceId; isLock = 1; double DadAndChild = Getconfidence(model.Dad, model.Child); //孩子与爸爸对比 double WifeAndChild = Getconfidence(model.Mom, model.Child); //孩子与妈妈对比 ImgMsg = GetConfidenceMsg(DadAndChild, WifeAndChild); } else { ImgMsg = "图片处理失败!请重新上传清晰的图片"; //图片处理失败(获取faceId 失败) } #endregion } listmodel = null; break; case "2.1": //Couple2 if (!string.IsNullOrWhiteSpace(model.ManAndWife)) { #region MyRegion fileName = dowimg(model.ManAndWife); if (!string.IsNullOrWhiteSpace(fileName)) { #region MyRegion controller.Detect(model.ManAndWife, fileName); //获取的face信息 model.ManAndWife = controller.rest; if (model.ManAndWife != null) { //获取照片信息 foreach (var item in JsonConvert.DeserializeObject <dynamic>(model.ManAndWife)) { var ResultModels = new DetectResultModels(); ResultModels.faceId = item.faceId; ResultModels.FileName = item.fileName; ResultModels.Age = item.age; ResultModels.Gender = item.gender == "male" ? "男" : "女"; ResultModels.Smile = item.smile; listmodel.Add(ResultModels); } if (listmodel.Count == 2) { isLock = 1; double DadAndChild = Getconfidence(listmodel[0].faceId, listmodel[1].faceId); //孩子与爸爸对比 ImgMsg = "你们的夫妻相是:" + DadAndChild * 100 + "% "; } else { ImgMsg = "请上传一张清晰的帅哥与美女的合影!"; } } else { ImgMsg = "图片处理失败!请重新上传清晰的图片"; //图片处理失败(获取faceId 失败) } #endregion } else { ImgMsg = "图片上传出错,请稍后重试;"; } #endregion } listmodel = null; break; case "2.2": //Couple if (!string.IsNullOrWhiteSpace(model.Dad) && !string.IsNullOrWhiteSpace(model.Mom)) { #region 载图片 获取 faceId json fileName = dowimg(model.Mom); if (!string.IsNullOrWhiteSpace(fileName)) { controller.Detect(model.Mom, fileName); //获取的face信息 model.Mom = controller.rest; controller.rest = null; } else { return(Json(new { isLock = 0, ImgMsg = "图片上传出错,请稍后重试;" }, JsonRequestBehavior.AllowGet)); } fileName = dowimg(model.Dad); if (!string.IsNullOrWhiteSpace(fileName)) { // System.Threading.Thread.Sleep(5000); controller.Detect(model.Dad, fileName); //获取的face信息 model.Dad = controller.rest; controller.rest = null; } else { return(Json(new { isLock = 0, ImgMsg = "图片上传出错,请稍后重试;" }, JsonRequestBehavior.AllowGet)); } #endregion #region MyRegion if (model.Mom != null && model.Dad != null) { model.Mom = JsonConvert.DeserializeObject <dynamic>(model.Mom)[0].faceId; model.Dad = JsonConvert.DeserializeObject <dynamic>(model.Dad)[0].faceId; isLock = 1; double DadAndChild = Getconfidence(model.Dad, model.Mom); ImgMsg = "你们的夫妻相是:" + DadAndChild * 100 + "% "; } else { ImgMsg = "图片处理失败!请重新上传清晰的图片"; //图片处理失败(获取faceId 失败) } #endregion } listmodel = null; break; default: break; } return(Json(new { isLock = isLock, ImgMsg = ImgMsg }, JsonRequestBehavior.AllowGet)); }
public JsonResult GetAccess() { try { //读取微信推送的内容 StreamReader sr = new StreamReader(Request.InputStream); XMLcolent = sr.ReadToEnd(); //说明有推送内容过来 if (XMLcolent != "") { root = XElement.Parse(XMLcolent); string FromUserName = root.Element("FromUserName").Value; //谁发送 string ToUserName = root.Element("ToUserName").Value; //设接收 //读取消息类型 string MsgType = root.Element("MsgType").Value; Mylog.Addlog(XMLcolent, "查询微信推送的消息", "" + MsgType); //在键值对中匹配相应的 //string Method = DTO_TYPE.type[MsgType]; //微信推送的是 事件 if (MsgType == "event") { //取出事件类型 string Event = root.Element("Event").Value; Mylog.Addlog(XMLcolent + ":" + Event, "取出xml里面具体的值", ""); if (Event == "subscribe")//被关注时 { Mylog.Addlog(XMLcolent + ":" + Event, "取出xml里面具体的值", ""); //被动给发送者回复信息 DTO_Method method = new DTO_Method(); method.Subscribe(FromUserName, ToUserName, "感谢关注!!", Response); } } //微信推送过来的是 文本类型 if (MsgType == "text") { //接收用户发过来的信息 string Content = root.Element("Content").Value; //被动给发送者回复信息 DTO_Method method = new DTO_Method(); method.Text(FromUserName, ToUserName, "用户传来的信息是:" + Content, Response); } //微信推送过来的是 图片类型 if (MsgType == "image") { //接收用户发过来的 图片id string MediaId = root.Element("MediaId").Value; //被动给发送者回复 单独的一张原图 DTO_Method method = new DTO_Method(); method.A_image(FromUserName, ToUserName, MediaId, Response); } if (MsgType == "click") { //被动回复图文 DTO_Method method = new DTO_Method(); method.Image_Text(FromUserName, ToUserName, Response); } if (MsgType == "media_id") { DTO_Method method = new DTO_Method(); //被动回复视频 method.BD_Video(FromUserName, ToUserName, Response); } } else { } } catch (Exception ex) { //记录错误 Mylog.Addlog(ex.Message, "错误信息", ""); } return(Json("", JsonRequestBehavior.AllowGet)); }