private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { try { int pp = 0; if (this.listView1.SelectedItems.Count > 0) { string id = this.listView1.FocusedItem.SubItems[0].Text; DialogResult dr = MessageBox.Show("确认删除吗?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { string sql = string.Format("delete from EBTime_Strategy where id='{0}'", id); mainForm.dba.DelDataBySQL(sql); timestrategies SELECTED = SingletonInfo.GetInstance().audit.TimeList.Find(C => C.ID.Equals(id)); SingletonInfo.GetInstance().audit.TimeList.Remove(SELECTED); pp = SingletonInfo.GetInstance().audit.TimeList.Count; // MessageBox.Show("策略数量:"+ pp.ToString()); FlashData(); } } else { MessageBox.Show("未选中任何行"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private SignatureStructReply CalculateSignature(string base64Message) { ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证 string url = "https://" + SingletonInfo.GetInstance().signatureIP + ":" + SingletonInfo.GetInstance().signaturePORT + "/api/security/message/signature"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json;charset=utf-8"; request.ReadWriteTimeout = 30 * 1000; request.Proxy = null; SignatureStruct pp = new SignatureStruct(); pp.base64Message = base64Message; string postStr = JsonHelper.SerializeObject(pp); byte[] data = Encoding.UTF8.GetBytes(postStr); request.ContentLength = data.Length; Stream myRequestStream = request.GetRequestStream(); myRequestStream.Write(data, 0, data.Length); myRequestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string content = myStreamReader.ReadToEnd(); myStreamReader.Close(); SignatureStructReply sigresult = JsonHelper.DeserializeJsonToObject <SignatureStructReply>(content); return(sigresult); }
private void mainForm_Load(object sender, EventArgs e) { try { // m_UsbPwsSupport = ini.ReadValue("USBPSW", "USBPSWSUPPART"); //MQStartFlag = ini.ReadValue("[MQInfo]", "IsStartFlag") == "1" ? true : false;//判断是否启用MQ //打开密码器 丽水松阳项目不使用此密码器 20180227 //if (m_UsbPwsSupport == "1") //{ // try // { // int nReturn = usb.USB_OpenDevice(ref phDeviceHandle); // if (nReturn != 0) // { // MessageBox.Show("密码器打开失败!"); // } // } // catch (Exception em) // { // MessageBox.Show("密码器打开失败:" + em.Message); // } //} //初始化签名验签函数 //int nReturn = scrambler.InitializeLSEB(); //if (nReturn != 0) //{ // MessageBox.Show("初始化签名验签失败!"); //} //初始化写日志线程 string sLogPath = Application.StartupPath + "\\Log"; if (!Directory.Exists(sLogPath)) { Directory.CreateDirectory(sLogPath); } Log.Instance.LogDirectory = sLogPath + "\\"; Log.Instance.FileNamePrefix = "EBD_"; Log.Instance.CurrentMsgType = MsgLevel.Debug; Log.Instance.logFileSplit = LogFileSplit.Daily; Log.Instance.MaxFileSize = 2; Log.Instance.InitParam(); AreaMappingHelper.InitDic(); AreaMapping.InitDic(); SingletonInfo.GetInstance().Longitude = ini.ReadValue("INFOSET", "Longitude"); SingletonInfo.GetInstance().Latitude = ini.ReadValue("INFOSET", "Latitude"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 验签 /// </summary> /// <param name="base64Message"></param> /// <param name="sign"></param> /// <returns></returns> public string Verifysignature(string base64Message, Signature sign) { ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证 string url = "https://" + SingletonInfo.GetInstance().signatureIP + ":" + SingletonInfo.GetInstance().signaturePORT + "/api/security/message/verifysignature"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json;charset=utf-8"; request.ReadWriteTimeout = 30 * 1000; VerifySignatureStruct pp = new VerifySignatureStruct(); byte[] IssuerIDlist = System.Text.Encoding.Default.GetBytes(sign.SignatureCert.IssuerID); //转成 Base64 形式的 System.String byte[] SNlist = System.Text.Encoding.Default.GetBytes(sign.SignatureCert.CertSN); pp.base64CertificateSN = Hexstr2Base64(sign.SignatureCert.CertSN); pp.base64IssuerID = Hexstr2Base64(sign.SignatureCert.IssuerID); pp.base64Message = base64Message; pp.base64Signature = sign.SignatureValue; pp.certType = sign.SignatureCert.CertType; pp.digestAlgorithm = "1"; pp.signatureAlgorithm = "1"; pp.signatureTime = Convert.ToInt64(sign.SignatureTime, 16).ToString(); string postStr = JsonHelper.SerializeObject(pp); byte[] data = Encoding.UTF8.GetBytes(postStr); request.ContentLength = data.Length; request.Proxy = null; Stream myRequestStream = request.GetRequestStream(); myRequestStream.Write(data, 0, data.Length); myRequestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string content = myStreamReader.ReadToEnd(); VerifySignatureStructReply reply = new VerifySignatureStructReply(); if (content != null) { reply = JsonHelper.DeserializeJsonToObject <VerifySignatureStructReply>(content); } myStreamReader.Close(); return(reply.result.ToString()); }
private void GetAuditData() { string sqlstr = "select * from EBTime_Strategy"; DataTable dt = mainForm.dba.getQueryInfoBySQL(sqlstr); for (int i = 0; i < dt.Rows.Count; i++) { timestrategies tt = new timestrategies(); tt.ID = dt.Rows[i][0].ToString(); tt.StartTime = dt.Rows[i][1].ToString(); tt.EndTime = dt.Rows[i][2].ToString(); tt.EvenType = dt.Rows[i][3].ToString(); SingletonInfo.GetInstance().audit.TimeList.Add(tt); } }
/// <summary> /// 区域对应码字典 /// </summary> public void InitData() { string MediaSQL = "select ORG_ID,ORG_DETAIL,GB_CODE from Organization"; DataTable dtOrga = dba.getQueryInfoBySQL(MediaSQL); if (dtOrga.Rows.Count > 0) { foreach (DataRow item in dtOrga.Rows) { OrganizationInfo tmp = new OrganizationInfo(); tmp.ORG_DETAIL = item["ORG_DETAIL"].ToString(); tmp.GB_CODE = item["GB_CODE"].ToString(); SingletonInfo.GetInstance().DicOrganizationCode.Add(item["ORG_ID"].ToString(), tmp); } } }
private void btn_AddEvent_Click(object sender, EventArgs e) { string StartTime = dtp_StartTime.Text; string EndTime = dtp_EndTime.Text; string EvenType = cbb_Type.SelectedValue.ToString(); string sql = string.Format("insert into EBTime_Strategy values('{0}','{1}','{2}') SELECT CAST(scope_identity() AS int)", StartTime, EndTime, EvenType); int ID = mainForm.dba.InsertDbBySQLRetID(sql); timestrategies pp = new timestrategies(); pp.ID = ID.ToString(); pp.StartTime = StartTime; pp.EndTime = EndTime; pp.EvenType = EvenType; SingletonInfo.GetInstance().audit.TimeList.Add(pp); FlashData(); }
/// <summary> /// 将本地文件上传到指定的服务器(HttpWebRequest方法) /// </summary> /// <param name="address">文件上传到的服务器</param> /// <param name="fileNamePath">要上传的本地文件(全路径)</param> /// <param name="saveName">文件上传后的名称</param> /// <returns>成功返回1,失败返回0</returns> public static string UploadFilesByPost(string address, string fileNamePath) { lock (SingletonInfo.GetInstance().lockedHttpSend) { try { int u = ServicePointManager.DefaultConnectionLimit; ServicePointManager.DefaultConnectionLimit = 200; string returnValue = "0"; // 要上传的文件 WebResponse webRespon = null; FileStream fs = new FileStream(fileNamePath, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); //时间戳 string sguidSplit = Guid.NewGuid().ToString(); string filename = fileNamePath.Substring(fileNamePath.LastIndexOf("\\") + 1); StringBuilder sb = new StringBuilder(300); string strPostHeader = sb.ToString(); HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(address)); httpReq.ServicePoint.Expect100Continue = false; httpReq.Method = "POST"; //对发送的数据不使用缓存 httpReq.AllowWriteStreamBuffering = false; //设置获得响应的超时时间(300秒) httpReq.Timeout = 60000; httpReq.ContentType = "multipart/form-data; boundary=" + sguidSplit; //"text/xml"; httpReq.Accept = "text/plain, */*"; httpReq.UserAgent = "WinHttpClient"; httpReq.Headers["Accept-Language"] = "zh-cn"; sb.Append("--" + sguidSplit + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n"); sb.Append("Content-Type: application/octet-stream;Charset=UTF-8\r\n"); sb.Append("\r\n"); byte[] boundaryBytes = Encoding.ASCII.GetBytes(sb.ToString()); //请求头部信息 byte[] bEndBytes = Encoding.ASCII.GetBytes("\r\n--" + sguidSplit + "--\r\n"); long length = fs.Length + boundaryBytes.Length + bEndBytes.Length; long fileLength = fs.Length; httpReq.ContentLength = length; try { int bufferLength = 4096; //每次上传4k byte[] buffer = new byte[bufferLength]; //已上传的字节数 long offset = 0; //开始上传时间 DateTime startTime = DateTime.Now; int size = r.Read(buffer, 0, bufferLength); Stream postStream = httpReq.GetRequestStream(); //发送请求头部消息 postStream.Write(boundaryBytes, 0, boundaryBytes.Length); while (size > 0) { postStream.Write(buffer, 0, size); offset += size; TimeSpan span = DateTime.Now - startTime; double second = span.TotalSeconds; Application.DoEvents(); size = r.Read(buffer, 0, bufferLength); } //添加尾部的时间戳 postStream.Write(bEndBytes, 0, bEndBytes.Length); postStream.Close(); //获取服务器端的响应 webRespon = httpReq.GetResponse(); Stream s = webRespon.GetResponseStream(); //读取服务器端返回的消息 StreamReader sr = new StreamReader(s); String sReturnString = sr.ReadLine(); s.Close(); sr.Close(); returnValue = "1"; } catch (Exception ex) { Console.WriteLine(ex); returnValue = "0"; } finally { fs.Close(); r.Close(); if (httpReq != null) { httpReq.Abort(); } if (webRespon != null) { webRespon.Close(); } GC.Collect(); } return(returnValue); } catch (Exception ex) { Console.WriteLine(ex); Thread.Sleep(500); } return("0"); } }
public string GetSequenceCodes() { SingletonInfo.GetInstance().SequenceCodes += 1; return(SingletonInfo.GetInstance().SequenceCodes.ToString().PadLeft(16, '0')); }
private void mainForm_Load(object sender, EventArgs e) { try { SingletonInfo.GetInstance().PlatformInformationFirst = ini.ReadValue("FIRST", "PlatformInformationFirst") == "true"?true:false; SingletonInfo.GetInstance().SequenceCodes = Convert.ToInt32(ini.ReadValue("SequenceCodes", "SequenceCodes")); m_UsbPwsSupport = ini.ReadValue("USBPSW", "USBPSWSUPPART"); //MQStartFlag = ini.ReadValue("[MQInfo]", "IsStartFlag") == "1" ? true : false;//判断是否启用MQ CipherExe = ini.ReadValue("USBPSW", "UsbCipherExe"); CipherPath = ini.ReadValue("USBPSW", "CipherPath"); ProcessManager pm = new ProccessChild(CipherExe, CipherPath); bool FirstMain = Convert.ToBoolean(ini.ReadValue("First", "FirstMain")); if (pm.CheckProcess(CipherPath + "\\" + CipherExe)) { } else { Thread.Sleep(10000); } #region //打开密码器 测试注释 20180812 //if (m_UsbPwsSupport == "1") //{ // try // { // int nReturn = usb.USB_OpenDevice(ref phDeviceHandle); // if (nReturn != 0) // { // MessageBox.Show("密码器打开失败!"); // } // } // catch (Exception em) // { // MessageBox.Show("密码器打开失败:" + em.Message); // } //} #endregion //初始化写日志线程 string sLogPath = Application.StartupPath + "\\Log"; if (!Directory.Exists(sLogPath)) { Directory.CreateDirectory(sLogPath); } Log.Instance.LogDirectory = sLogPath + "\\"; Log.Instance.FileNamePrefix = "EBD_"; Log.Instance.CurrentMsgType = MsgLevel.Debug; Log.Instance.logFileSplit = LogFileSplit.Daily; Log.Instance.MaxFileSize = 2; Log.Instance.InitParam(); #region 自启动 测试注释 20180812 //if (FirstMain) // mnuServerStart.PerformClick(); //else //{ // ini.WriteValue("FIRST", "FirstMain", "true"); //} #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } }