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();
        }
Exemplo n.º 2
0
 private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     e.Cancel         = true;
     this.WindowState = FormWindowState.Minimized;
     if (serverFrm != null)
     {
         serverFrm.Hide();
     }
     this.Visible = false;
     this.Hide();
     this.ShowInTaskbar = false;
     this.nIcon.Visible = true;
     //关闭密码器
     if (SingletonInfo.GetInstance().m_UsbPwsSupport == "1" && !SingletonInfo.GetInstance().IsCompatible)
     {
         try
         {
             int nDeviceHandle = (int)phDeviceHandle;
             int nReturn       = usb.USB_CloseDevice(ref nDeviceHandle);
         }
         catch (Exception em)
         {
             MessageBox.Show("密码器关闭失败:" + em.Message);
         }
     }
     if (serverFrm != null)
     {
         serverFrm.Close();
         serverFrm.Dispose();
     }
     if (comm != null)
     {
         comm.Close();
         comm.Dispose();
     }
     if (sndComm != null)
     {
         sndComm.Close();
         sndComm.Dispose();
     }
     this.Dispose();                //释放资源
     Application.Exit();
     Application.ExitThread();
     Environment.Exit(0);
 }
Exemplo n.º 3
0
 private void GetPlatformInfo()
 {
     if (SingletonInfo.GetInstance().IsCompatible)
     {
         //兼容版本  平台基本数据从配置文件读取
         SingletonInfo.GetInstance().CurrentURL          = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "URL");
         SingletonInfo.GetInstance().CurrentResourcecode = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "HBRONO");
         SingletonInfo.GetInstance().PlatformEBRName     = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "EBRName");
         SingletonInfo.GetInstance().PlatformContact     = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "Contact");
         SingletonInfo.GetInstance().PlatformPhoneNumber = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "PhoneNumber");
         SingletonInfo.GetInstance().Longitude           = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "Longitude");
         SingletonInfo.GetInstance().Latitude            = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "Latitude");
         SingletonInfo.GetInstance().PlatformAddress     = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "Address");
         SingletonInfo.GetInstance().SendTarAddress      = SingletonInfo.GetInstance().serverini.ReadValue("CompatibleMode", "BJURL");
     }
     else
     {
         //不是兼容版本 平台基本数据需要从数据库获取
         string    sqlstr = "select * from PlatformResource";
         DataTable dt     = mainForm.dba.getQueryInfoBySQL(sqlstr);
         if (dt.Rows.Count > 0)
         {
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 if (dt.Rows[i]["platformType"].ToString() == "1")
                 {
                     SingletonInfo.GetInstance().CurrentURL          = dt.Rows[i]["ipAddress"].ToString();
                     SingletonInfo.GetInstance().CurrentResourcecode = dt.Rows[i]["sourceCode"].ToString();
                     SingletonInfo.GetInstance().PlatformEBRName     = dt.Rows[i]["platformName"].ToString();
                     SingletonInfo.GetInstance().PlatformContact     = dt.Rows[i]["contact"].ToString();
                     SingletonInfo.GetInstance().PlatformPhoneNumber = dt.Rows[i]["phone"].ToString();
                     SingletonInfo.GetInstance().Longitude           = dt.Rows[i]["longitude"].ToString();
                     SingletonInfo.GetInstance().Latitude            = dt.Rows[i]["latitude"].ToString();
                     SingletonInfo.GetInstance().PlatformAddress     = dt.Rows[i]["address"].ToString();
                 }
                 else
                 if (dt.Rows[i]["platformType"].ToString() == "-1")
                 {
                     SingletonInfo.GetInstance().SendTarAddress = dt.Rows[i]["ipAddress"].ToString();
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 文件签名
        /// </summary>
        /// <param name="strPath"></param>
        /// <param name="strEBDID"></param>
        public void GenerateSignatureFile(string strPath, string strEBDID)
        {
            if (SingletonInfo.GetInstance().m_UsbPwsSupport != "1")
            {
                return;
            }

            string sSignFileName = "\\EBDB_" + strEBDID + ".xml";

            using (FileStream SignFs = new FileStream(strPath + sSignFileName, FileMode.Open))
            {
                StreamReader signsr  = new StreamReader(SignFs, Encoding.UTF8);
                string       xmlsign = signsr.ReadToEnd();
                signsr.Close();
                responseXML signrp     = new responseXML();
                XmlDocument xmlSignDoc = new XmlDocument();
                try
                {
                    //对文件进行签名
                    int    nDeviceHandle = (int)phDeviceHandle;
                    byte[] pucSignature  = Encoding.UTF8.GetBytes(xmlsign);

                    string strSignture     = "";
                    string strpucCounter   = "";
                    string strpucSignCerSn = "";
                    string nReturn         = usb.Platform_CalculateSingature_String(nDeviceHandle, 1, pucSignature, pucSignature.Length, ref strSignture);
                    //生成签名文件
                    string xmlSIGNFileName = "\\EBDS_EBDB_" + strEBDID + ".xml";
                    xmlSignDoc = signrp.SignResponse(strEBDID, strpucCounter, strpucSignCerSn, nReturn);
                    CommonFunc cm = new CommonFunc();
                    cm.SaveXmlWithUTF8NotBOM(xmlSignDoc, strPath + xmlSIGNFileName);
                    if (cm != null)
                    {
                        cm = null;
                    }
                }
                catch (Exception ex)
                {
                    Log.Instance.LogWrite("签名文件错误:" + ex.Message);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 通用反馈  收到tar就回
        /// </summary>
        private void CurrencyTarBack(EBD ebdb, string value)
        {
            try
            {
                ServerForm.DeleteFolder(ServerForm.strBeSendFileMakeFolder);//删除原有XML发送文件的文件夹下的XML
                XmlDocument xmlDoc = new XmlDocument();
                responseXML rp     = new responseXML();
                string      fName  = "10" + SingletonInfo.GetInstance().CurrentResourcecode + BBSHelper.GetSequenceCodes();
                xmlDoc = rp.EBDResponse(ebdb, "EBDResponse", fName, value);
                string xmlSignFileName = "\\EBDB_" + fName + ".xml";

                CreateXML(xmlDoc, ServerForm.strBeSendFileMakeFolder + xmlSignFileName);

                //进行签名
                ServerForm.mainFrm.GenerateSignatureFile(ServerForm.strBeSendFileMakeFolder, fName);
                ServerForm.tar.CreatTar(ServerForm.strBeSendFileMakeFolder, ServerForm.sSendTarPath, fName);//使用新TAR
                string       sSendTarName = ServerForm.sSendTarPath + "\\EBDT_" + fName + ".tar";
                FileStream   fsSnd        = new FileStream(sSendTarName, FileMode.Open, FileAccess.Read);
                BinaryReader br           = new BinaryReader(fsSnd); //时间戳
                int          datalen      = (int)fsSnd.Length + 2;
                int          bufferLength = 4096;
                long         offset       = 0; //开始上传时间
                writeHeader(datalen.ToString(), "EBDT_" + fName + ".tar");

                byte[] buffer = new byte[4096]; //已上传的字节数
                int    size   = br.Read(buffer, 0, bufferLength);
                while (size > 0)
                {
                    outputStream.Write(buffer, 0, size);
                    offset += size;
                    size    = br.Read(buffer, 0, bufferLength);
                }
                outputStream.Write(Encoding.UTF8.GetBytes(sEndLine), 0, 2);
                outputStream.Flush();//提交写入的数据
                fsSnd.Close();
            }
            catch (Exception esb)
            {
                Console.WriteLine("401:" + esb.Message);
            }
        }
Exemplo n.º 6
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (txtServer.Text.Trim() == "")
     {
         MessageBox.Show("服务器不能为空,请输入!", "提示");
         txtServer.Focus();
         return;
     }
     if (txtDb.Text.Trim() == "")
     {
         MessageBox.Show("数据库不能为空,请输入!", "提示");
         txtDb.Focus();
         return;
     }
     if (txtDbuser.Text.Trim() == "")
     {
         MessageBox.Show("数据库用户名不能为空,请输入!", "提示");
         txtDbuser.Focus();
         return;
     }
     SingletonInfo.GetInstance().serverini.WriteValue("Database", "ServerName", txtServer.Text.Trim());
     SingletonInfo.GetInstance().serverini.WriteValue("Database", "DataBase", txtDb.Text.Trim());
     SingletonInfo.GetInstance().serverini.WriteValue("Database", "LogID", txtDbuser.Text.Trim());
 }
Exemplo n.º 7
0
 private void InfoSetForm_Load(object sender, EventArgs e)
 {
     txtSourceID.Text   = SingletonInfo.GetInstance().serverini.ReadValue("INFOSET", "SourceID");
     txtSourceName.Text = SingletonInfo.GetInstance().serverini.ReadValue("INFOSET", "SourceName");
     txtSourceType.Text = SingletonInfo.GetInstance().serverini.ReadValue("INFOSET", "SourceType");
 }
Exemplo n.º 8
0
 private void btnSet_Click(object sender, EventArgs e)
 {
     SingletonInfo.GetInstance().serverini.WriteValue("INFOSET", "SourceID", txtSourceID.Text);
     SingletonInfo.GetInstance().serverini.WriteValue("INFOSET", "SourceName", txtSourceName.Text);
     SingletonInfo.GetInstance().serverini.WriteValue("INFOSET", "SourceType", txtSourceType.Text);
 }
Exemplo n.º 9
0
        /// <summary>
        /// 验签函数 及通用反馈
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="PlatformVerifySignatureresule"></param>
        public void DealTarBack(string filepath, out bool PlatformVerifySignatureresule)
        {
            PlatformVerifySignatureresule = false;//验签是否通过
            EBD ebdb = null;

            if (File.Exists(filepath))
            {
                try
                {
                    #region 先删除预处理解压缩包中的文件
                    foreach (string xmlfiledel in Directory.GetFileSystemEntries(ServerForm.strBeUnTarFolder))
                    {
                        if (File.Exists(xmlfiledel))
                        {
                            FileInfo fi = new FileInfo(xmlfiledel);
                            if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                            {
                                fi.Attributes = FileAttributes.Normal;
                            }
                            File.Delete(xmlfiledel);//直接删除其中的文件
                        }
                    }
                    #endregion End
                    ServerForm.tar.UnpackTarFiles(filepath, ServerForm.strBeUnTarFolder);                  //把压缩包解压到专门存放接收到的XML文件的文件夹下
                    string[] xmlfilenames      = Directory.GetFiles(ServerForm.strBeUnTarFolder, "*.xml"); //从解压XML文件夹下获取解压的XML文件名
                    string   sTmpFile          = string.Empty;
                    string   sAnalysisFileName = "";
                    string   sSignFileName     = "";
                    if (SingletonInfo.GetInstance().m_UsbPwsSupport == "1")
                    {
                        if (xmlfilenames.Length < 2)//没有签名文件
                        {
                            PlatformVerifySignatureresule = false;
                        }
                    }

                    for (int i = 0; i < xmlfilenames.Length; i++)
                    {
                        sTmpFile = Path.GetFileName(xmlfilenames[i]);
                        if (sTmpFile.ToUpper().IndexOf("EBDB") > -1 && sTmpFile.ToUpper().IndexOf("EBDS_EBDB") < 0)
                        {
                            sAnalysisFileName = xmlfilenames[i];
                        }
                        else if (sTmpFile.ToUpper().IndexOf("EBDS_EBDB") > -1) //签名文件
                        {
                            sSignFileName = xmlfilenames[i];                   //签名文件
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(sAnalysisFileName))
                    {
                        using (FileStream fsr = new FileStream(sAnalysisFileName, FileMode.Open))
                        {
                            StreamReader sr      = new StreamReader(fsr, Encoding.UTF8);
                            string       xmlInfo = sr.ReadToEnd();
                            xmlInfo = xmlInfo.Replace("xmlns:xs", "xmlns");
                            sr.Close();
                            xmlInfo = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlInfo);
                            xmlInfo = XmlSerialize.GetLowOrderASCIICharacters(xmlInfo);
                            ebdb    = XmlSerialize.DeserializeXML <EBD>(xmlInfo);
                        }
                    }
                    string myEBDType = string.Empty;
                    if (ebdb != null)
                    {
                        myEBDType = ebdb.EBDType;
                    }
                    if (!string.IsNullOrWhiteSpace(sSignFileName) && myEBDType != "ConnectionCheck" && SingletonInfo.GetInstance().m_UsbPwsSupport == "1")
                    {
                        //读取xml中的文件,转换为byte字节
                        byte[] xmlArray = File.ReadAllBytes(sAnalysisFileName);

                        #region 签名处理
                        Console.WriteLine("开始验证签名文件!");
                        using (FileStream SignFs = new FileStream(sSignFileName, FileMode.Open))
                        {
                            StreamReader signsr  = new StreamReader(SignFs, Encoding.UTF8);
                            string       xmlsign = signsr.ReadToEnd();
                            signsr.Close();
                            responseXML signrp     = new responseXML();//签名回复
                            XmlDocument xmlSignDoc = new XmlDocument();
                            try
                            {
                                int nDeviceHandle = (int)ServerForm.mainFrm.phDeviceHandle;
                                xmlsign = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlsign);
                                xmlsign = XmlSerialize.GetLowOrderASCIICharacters(xmlsign);
                                Signature sign = XmlSerialize.DeserializeXML <Signature>(xmlsign);
                                xmlsign = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlsign);
                                xmlsign = XmlSerialize.GetLowOrderASCIICharacters(xmlsign);
                                string PucStr    = sign.SignatureValue;
                                byte[] pucsingVi = Encoding.UTF8.GetBytes(sign.SignatureValue);

                                //0是签名通过
                                var result = ServerForm.mainFrm.usb.PlatformVerifySignature(nDeviceHandle, 1, xmlArray, xmlArray.Length, pucsingVi);
                                PlatformVerifySignatureresule = result == 0;
                                Log.Instance.LogWrite(PlatformVerifySignatureresule ? "签名验证成功" : "签名验证失败-" + result);
                            }
                            catch (Exception ex)
                            {
                                Log.Instance.LogWrite("签名文件错误:" + ex.Message);
                            }
                        }
                        Console.WriteLine("结束验证签名文件!");
                        #endregion End
                    }

                    ServerForm.DeleteFolder(ServerForm.strBeSendFileMakeFolder);//删除原有XML发送文件的文件夹下的XML
                    if (!PlatformVerifySignatureresule && myEBDType != "ConnectionCheck" && SingletonInfo.GetInstance().m_UsbPwsSupport == "1")
                    {
                        //验签失败
                        CurrencyTarBack(ebdb, "4");
                        return;
                    }
                    Console.WriteLine("要解析文件:" + sAnalysisFileName);

                    #region 通用反馈  20181210
                    CurrencyTarBack(ebdb, "1");
                    #endregion

                    if (ebdb != null)
                    {
                        switch (ebdb.EBDType)
                        {
                        case "ConnectionCheck":
                            //要提示系统在线
                            ServerForm.mainFrm.serverFrm.OnlineCheck(true);
                            break;
                        }
                    }
                }
                catch (Exception ep)
                {
                    Log.Instance.LogWrite("验签过程异常:" + ep.Message);
                }
            }
        }
Exemplo n.º 10
0
        private void PostRequestDeal(StreamReader sr, string sFileForldPath)
        {
            //直接使用StreamReader为导致接收文件数据缺失,直接用Stream可接收所有数据,但需自行处理分行和结尾,
            //有其他更好方法请自行修改
            Console.WriteLine("361:" + sFileForldPath);
            if (this.httpHeaders.ContainsKey("Content-Length"))
            {
                int content_len = Convert.ToInt32(this.httpHeaders["Content-Length"]);
                if (content_len > MAX_POST_SIZE)
                {
                    Console.WriteLine(String.Format("POST Content-Length({0}) too big for this simple server", content_len));
                }
                try
                {
                    Stream        stream    = sr.BaseStream;
                    string        sFilePath = string.Empty;
                    int           charData  = 0;
                    List <byte>   data      = new List <byte>();
                    List <byte[]> dataArray = new List <byte[]>();
                    while (stream.Position != stream.Length && charData != -1)
                    {
                        charData = stream.ReadByte();
                        data.Add((byte)charData);
                    }
                    if (data.Count < 200)
                    {
                        return;
                    }
                    int index = data.IndexOf((byte)'\n');
                    while (index >= 0)
                    {
                        dataArray.Add(data.Take(index + 1).ToArray());
                        data.RemoveRange(0, index + 1);
                        index = data.IndexOf((byte)'\n');
                    }
                    int  startIndex = 0;
                    int  endIndex   = 0;
                    int  length     = 0;
                    bool flag       = false;//是否需要特殊处理  20180108
                    for (int j = 0; j < dataArray.Count; j++)
                    {
                        string str = Encoding.UTF8.GetString(dataArray[j], 0, dataArray[j].Length - 2);

                        #region 解析Content-Disposition
                        if (str.Contains("Content-Disposition"))
                        {
                            string[] sSeparateVaule = str.Split('=');
                            if (sSeparateVaule.Length > 1)
                            {
                                string revfilename = sSeparateVaule[sSeparateVaule.Length - 1];//文件名
                                if (revfilename != "")
                                {
                                    revfilename = revfilename.Replace("\"", "");
                                    sFilePath   = sFileForldPath + "\\" + revfilename;
                                }
                                else
                                {
                                    sFilePath = sFileForldPath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".tar";
                                }
                                revfilename = string.Empty;
                            }
                        }
                        #endregion
                        //判断是数据开头则退出循环
                        if (dataArray[j][0] == 69 && dataArray[j][1] == 66 && dataArray[j][2] == 68 && (dataArray[j][3] == 66 || dataArray[j][3] == 82 || dataArray[j][3] == 84 || dataArray[j][3] == 83))
                        {
                            if (dataArray[j][3] == 82 || dataArray[j][3] == 84 || dataArray[j][3] == 83)
                            {
                                flag = true;
                            }
                            startIndex = j;
                            break;
                        }
                        length += dataArray[j].Length;
                    }
                    for (int j = dataArray.Count - 1; j > 1; j--)
                    {
                        length += dataArray[j].Length;
                        string str = Encoding.UTF8.GetString(dataArray[j]);
                        //判断是http结尾则退出循环
                        if (str.Contains("--" + sSeparateString + "--") && sSeparateString != "")
                        {
                            if (dataArray[j - 1].Length == 2 && dataArray[j - 1][0] == '\r' && dataArray[j - 1][1] == '\n')
                            {
                                if (dataArray[j][3] == 83)
                                {
                                    endIndex = j;
                                    length  -= dataArray[j].Length; //ceshi
                                }
                                else
                                {
                                    endIndex = j - 1;
                                    length  += 2;
                                }
                            }
                            else
                            {
                                endIndex = j;
                                if (flag)
                                {
                                    length -= dataArray[j].Length;  //ceshi
                                }
                            }
                            break;
                        }
                    }
                    if (startIndex < 2)
                    {
                        return;
                    }
                    var bodyData  = new byte[stream.Length - length]; //文件数据
                    int dstLength = 0;
                    if (flag)
                    {
                        for (int j = startIndex; j < endIndex + 1; j++)
                        {
                            Array.Copy(dataArray[j], 0, bodyData, dstLength, dataArray[j].Length);
                            dstLength += dataArray[j].Length;
                        }
                    }
                    else
                    {
                        for (int j = startIndex; j < endIndex; j++)
                        {
                            Array.Copy(dataArray[j], 0, bodyData, dstLength, dataArray[j].Length);
                            dstLength += dataArray[j].Length;
                        }
                    }
                    //存储文件
                    File.WriteAllBytes(sFilePath, bodyData);
                    //处理接收的文件
                    bool verifySuccess = false;
                    DealTarBack(sFilePath, out verifySuccess);
                    if (SingletonInfo.GetInstance().m_UsbPwsSupport == "2")
                    {
                        //不支持签名
                        ServerForm.lRevFiles.Add(sFilePath);//完成接收文件后把文件增加到处理列表上去
                    }
                    else
                    {
                        //支持签名
                        if (verifySuccess)
                        {
                            ServerForm.lRevFiles.Add(sFilePath);//完成接收文件后把文件增加到处理列表上去
                        }
                    }
                }
                catch (Exception em)
                {
                    Console.WriteLine("HS422:" + em.Message);
                }
                Console.WriteLine("接收Tar文件成功!");
            }
        }
Exemplo n.º 11
0
 private void ServerSetForm_Load(object sender, EventArgs e)
 {
     txtZJPlat.Text = SingletonInfo.GetInstance().SendTarAddress;
 }