zoukankan      html  css  js  c++  java
  • 乱写

        #region 申请开门
            /// <summary>
            /// 申请开门
            /// </summary>
            string sWebsRet = "";//二维码
            public BDCom PutinBdcom = new BDCom();
            //string sopenbox = "";
            private void button1_Click(object sender, EventArgs e)
            {
                string url = "https://192.168.1.101/httpOrg/create";
                Encoding encoding = Encoding.GetEncoding("utf-8");
                IDictionary<string, string> parameters = new Dictionary<string, string>();
                parameters.Add("code", "*****");
                parameters.Add("wcode", "*****");
    
                HttpWebResponse response = CreatePostHttpResponse(url, parameters, encoding);
                //打印返回值  
                Stream stream = response.GetResponseStream();   //获取响应的字符串流  
                StreamReader sr = new StreamReader(stream); //创建一个stream读取流  
                string html = sr.ReadToEnd();   //从头读到尾,放到字符串html  
                Console.WriteLine(html);
            }
            #endregion
    
    
            private HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, Encoding encoding)
            {
              
                try
                {
                    HttpWebRequest request = null;
                    //HTTPSQ请求  
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    request = WebRequest.Create(url) as HttpWebRequest;
                    request.ProtocolVersion = HttpVersion.Version10;
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.UserAgent = DefaultUserAgent;
                    //如果需要POST数据     
                    if (!(parameters == null || parameters.Count == 0))
                    {
                        StringBuilder buffer = new StringBuilder();
                        int i = 0;
                        foreach (string key in parameters.Keys)
                        {
                            if (i > 0)
                            {
                                buffer.AppendFormat("&{0}={1}", key, parameters[key]);
                            }
                            else
                            {
                                buffer.AppendFormat("{0}={1}", key, parameters[key]);
                            }
                            i++;
                        }
                        byte[] data = null; //charset.GetBytes(buffer.ToString());
                        using (Stream stream = request.GetRequestStream())
                        {
                            stream.Write(data, 0, data.Length);
                        }
                    }
                    return request.GetResponse() as HttpWebResponse;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return null;
                }
    
            }
    
            private bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            {
                return true;//总是接受
            }
    
            #region 第二步查询空箱子
            /// <summary>
            /// 第二步查询空箱子
            /// </summary>
            /// <returns></returns>
            private int PutInboxCard(string strcode)
            {
                string sBoxNo = "";
                string strcardId = strcode;
                //////////////////////
                // 查询当前是否存物
                //////////////////////
                // 0. 查询存物记录
                //////////////////////
                string sThisBoxNoSql = " select OperTime, BoxNo from BoxInOut where OperID='" + strcardId + "' and OperType='1' and OperStatus='1' ";
                string sOperTime = ""; string sThisBoxNo = "";
                try
                {
                    SQLiteDbHelper ScabHelper11 = new SQLiteDbHelper(TrhaConst.trhaSCAB);
                    if (ScabHelper11.dbConnection.State == ConnectionState.Open)
                    {
                        IDataReader sqReader = ScabHelper11.ExecuteQuery(sThisBoxNoSql);
                        while (sqReader.Read())
                        {
                            sOperTime = sqReader.GetString(sqReader.GetOrdinal("OperTime"));
                            sThisBoxNo = sqReader.GetString(sqReader.GetOrdinal("BoxNo"));
                            //MessageBox.Show("第一次"+sThisBoxNo);
                        }
                    }
                    if (ScabHelper11.dbConnection.State == ConnectionState.Open) ScabHelper11.CloseSqlConnection();
                }
                catch
                {
                    return -1;
                }
                if (sThisBoxNo != "")
                {
                    //lblSendMessage.Text = "您正在使用" + sThisBoxNo + "号箱。";
                    TrhaConst.sPutinBoxNo = sThisBoxNo;
                    //if (ScabHelper1.dbConnection.State == ConnectionState.Open) ScabHelper1.CloseSqlConnection();
                    return 2;
                }
                //////////////////////
                // 随机选取一个柜箱
                //////////////////////
                // 1. 获取当前空箱总数
                //////////////////////
                string sBoxNoSql = " select count(*) iBoxNoCnt from ScabBox where BoxStatus='0' ";
                int iBoxNoCnt = 0;
                try
                {
                    SQLiteDbHelper ScabHelper2 = new SQLiteDbHelper(TrhaConst.trhaSCAB);
                    if (ScabHelper2.dbConnection.State == ConnectionState.Open)
                    {
                        IDataReader sqReader = ScabHelper2.ExecuteQuery(sBoxNoSql);
                        while (sqReader.Read())
                        {
                            iBoxNoCnt = sqReader.GetInt32(sqReader.GetOrdinal("iBoxNoCnt"));
                        }
                    }
                    if (ScabHelper2.dbConnection.State == ConnectionState.Open) ScabHelper2.CloseSqlConnection();
                }
                catch
                {
                    return -1;
                }
                if (iBoxNoCnt == 0)
                {
                    //MessageBox.Show("所有箱门已存物,请您稍候!");
                    return 3;
                }
                /////////////////////////
                // 2. 随机选择一个空箱
                /////////////////////////
                int iRandomBoxNo = TrhaConst.GetRandom(0, iBoxNoCnt);
                sBoxNoSql = " select BoxNo from ScabBox where BoxStatus='0' ";
                try
                {
                    SQLiteDbHelper ScabHelper3 = new SQLiteDbHelper(TrhaConst.trhaSCAB);
                    if (ScabHelper3.dbConnection.State == ConnectionState.Open)
                    {
                        IDataReader sqReader = ScabHelper3.ExecuteQuery(sBoxNoSql);
                        int BoxNoIdx = 0;
                        while (sqReader.Read())
                        {
                            sBoxNo = sqReader.GetString(sqReader.GetOrdinal("BoxNo"));
                            if (BoxNoIdx == iRandomBoxNo) { break; }
                            BoxNoIdx++;
                        }
                    }
                    if (ScabHelper3.dbConnection.State == ConnectionState.Open) ScabHelper3.CloseSqlConnection();
                }
                catch
                {
                    //MessageBox.Show("本地数据库访问失败,请联系技术服务人员!");
    
                    return -1;
                }
                if (sBoxNo == "")
                {
                    //MessageBox.Show("获取空箱号失败,请联系技术服务人员!");
    
                    return -1;
                }
    
                int iCabinComm = 0;
                SQLiteDbHelper ScabHelper4 = new SQLiteDbHelper(TrhaConst.trhaSCAB);
                try
                {
                    if (ScabHelper4.dbConnection.State == ConnectionState.Open)
                    {
                        IDataReader sqReader = ScabHelper4.ReadFullTable("BarComm");
                        while (sqReader.Read())
                        {
                            iCabinComm = Convert.ToInt32(sqReader.GetString(sqReader.GetOrdinal("CabinComm")));
                        }
                        sqReader.Close();
                    }
                    if (ScabHelper4.dbConnection.State == ConnectionState.Open) ScabHelper4.CloseSqlConnection();
                }
                catch
                {
                    //MessageBox.Show("本地数据库访问失败,请联系技术服务人员!");
    
                    return -1;
                }
    
                if (iCabinComm == 0)
                {
                    //MessageBox.Show("本地数据库访问失败,请联系技术服务人员!");
                    return -1;
                }
    
                TrhaConst.iCabinComm = iCabinComm;  // 柜箱使用串口号
                TrhaConst.sPutinBoxNo = sBoxNo;     // 使用柜箱号           
                return 4;
            }
            #endregion
    
            #region  第三步zhj-2018-12-30写进数据库存记录     
            /// <summary>
            /// 写进数据库存记录
            /// </summary>
            /// <returns></returns>
            private int WriteBoxInOut()
            {
                int retwbi = 0;
                //"OperTime"操作时间, "OperDate"操作日期, "OperType"1存0取, "OperStatus"操作状态, "BoxNo"箱号, "OperID"使用人, "RecStatus" 记录状态上传服务器0是未上传1是已上传, 
                //zhj-2019-01-03新增"OutBoxTime"取物时间, "CardId"证件号码, "UserName"姓名,InOutStatus:取物有效状态:永久有效,取后失效(存的时候是取后失效,登记存入的时候,永久有效)
                //OperTime"操作时间, "OperDate"操作日期, "OperType"1存0, "OperStatus"操作状态, "BoxNo"箱号, "OperID"使用人, "RecStatus"记录上传状态, "CourtID"法院ID, "UserName"姓名, "CardId"身份证号, "LawyerCard"律师号码, "Purpose"采访事由, "Mobile"手机号
                string[] colItems = { "OperTime", "OperDate", "OperType", "OperStatus", "BoxNo", "OperID", "RecStatus", "CourtID", "UserName", "CardId", "LawyerCard", "Purpose", "Mobile" };
                string[] valueItems = new string[13];
    
                System.DateTime currentTime = new System.DateTime();
                currentTime = System.DateTime.Now;
                valueItems[0] = currentTime.ToString("yyyy-MM-dd HH:mm:ss"); valueItems[1] = currentTime.ToString("yyyy-MM-dd"); valueItems[2] = "1"; valueItems[3] = "1";
                //valueItems[4] = TrhaConst.sPutinBoxNo; valueItems[5] = sOperID; valueItems[6] = "0";
                //valueItems[7] = sCourtID; valueItems[8] = sUserName; valueItems[9] = sCardId;
                //valueItems[10] = sLawyerCard; valueItems[11] = sPurpose; valueItems[12] = sMobile;
                string[] sPutinSqls = new string[2];
                try
                {
                    SQLiteDbHelper ScabHelper1 = new SQLiteDbHelper(TrhaConst.trhaSCAB);
                    if (ScabHelper1.dbConnection.State == ConnectionState.Open)
                    {
                        //更新柜子的状态是1为占用状态,
                        sPutinSqls[0] = " update ScabBox set BoxStatus='1',";
                        sPutinSqls[0] = sPutinSqls[0] + "OperID='" + valueItems[5] + "',";//使用人
                        sPutinSqls[0] = sPutinSqls[0] + "OperDate='" + valueItems[1] + "',";//操作日期
                        sPutinSqls[0] = sPutinSqls[0] + "OperTime='" + valueItems[0] + "',";//操作时间
                        sPutinSqls[0] = sPutinSqls[0] + "OperDesc='存入' ";
                        sPutinSqls[0] = sPutinSqls[0] + "where BoxNo='" + valueItems[4] + "' ";
                        sPutinSqls[1] = " insert into BoxInOut (" + colItems[0];
                        for (int ii = 1; ii < colItems.Length; ++ii)
                        {
                            sPutinSqls[1] += ", " + colItems[ii];
                        }
                        sPutinSqls[1] += ") values('";
                        sPutinSqls[1] += valueItems[0];
                        for (int ii = 1; ii < valueItems.Length; ++ii)
                        {
                            sPutinSqls[1] += "', '" + valueItems[ii];
                        }
                        sPutinSqls[1] += "') ";
    
                        bool bTransExe = ScabHelper1.ExecuteTrans(sPutinSqls);
                        if (bTransExe)
                        {
                            retwbi = 1;
                        }
                        else
                        {
                            retwbi = -1;
                        }
                    }
                    if (ScabHelper1.dbConnection.State == ConnectionState.Open) ScabHelper1.CloseSqlConnection();
                }
                catch
                {
                    retwbi = -1;
                }
    
                return retwbi;
            }
            #endregion
            private void button2_Click(object sender, EventArgs e)
            {
                string[] sboxinoutrecs = new string[1];
                sboxinoutrecs[0] = "1ww";
    
                string[] sArrBoxInOut = new string[0];
    
                Thread sendThread1 = new Thread(send);
                sendThread1.Start(sboxinoutrecs);
    
            }
    
            private void send(object sboxrecs)
            {
                //string IP = "localhost";
                string IP = "10.80.16.38";
                string sServerPort = "8081";
                string swebsurl = "http://" + IP + ":" + sServerPort + "/phyServer/services/ImportDataService?wsdl"; //wsdl地址  
                string swebsname = "webServN";
                TrhaConst.wsdScab = new WebServiceProxy(swebsurl, swebsname);
                string[] sboxinoutrecs = (string[])sboxrecs;
    
                string funname = "interfaceTest";
                try
                {
                    sWebsRet = (string)TrhaConst.wsdScab.ExecuteQuery(funname, sboxinoutrecs);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
    View Code
  • 相关阅读:
    c# 抽象类(abstract)
    c# 虚方法(virtual)与 多态(Polymorphism)
    02.JavaScript基础上
    第 12 章 Ajax
    第 11 章 动画效果
    第 10 章 高级事件
    第 9 章 事件对象
    第 8 章 基础事件
    第 7 章 表单选择器
    第6章 DOM节点操作
  • 原文地址:https://www.cnblogs.com/aijiao/p/10396375.html
Copyright © 2011-2022 走看看