private void button2_Click_1(object sender, EventArgs e) { try { DBO.AccountsConnection = new System.Data.SqlClient.SqlConnection(DBO.Connection); DBO.AccountsConnection.Open(); DBO.AccountTransaction = DBO.AccountsConnection.BeginTransaction(); for (int i = 0; i < grdVoucher.RowCount; i++) { String AccountId = grdVoucher.Rows[i].Cells[1].Value.ToString(); String Edate = Convert.ToDateTime(grdVoucher.Rows[i].Cells[0].Value.ToString()).ToShortDateString(); String AccountNum = grdVoucher.Rows[i].Cells[2].Value.ToString(); String Description = grdVoucher.Rows[i].Cells[3].Value.ToString(); String TransactionType = grdVoucher.Rows[i].Cells[4].Value.ToString(); String Amount = grdVoucher.Rows[i].Cells[5].Value.ToString(); if (Amount == "0") { Amount = grdVoucher.Rows[i].Cells[6].Value.ToString(); } Accounts.InsertJournalAndPosting(AccountId, AccountNum, Amount, Description, TransactionType, Convert.ToDateTime(Edate)); } DBO.AccountTransaction.Commit(); DBO.AccountsConnection.Close(); ClearControls(); } catch (Exception Ep) { DBO.AccountTransaction.Rollback(); DBO.AccountsConnection.Close(); MessageBox.Show(Ep.ToString()); } }
/// <summary> /// Recepción de datos del puerto serial enviados por arduino /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { //-------------------------Recepción de datos del arduino------------------------------ _bufferint = serialPort1.ReadLine(); //-------------Convirtiendo valores recibidos a datos tipo double------------------ bool valnum1 = double.TryParse(_bufferint, out _data1); //-------------------Muestreo de datos para filtrar errores de medición------------- if (valnum1) // Validando que el dato recibido sea un número { _dataHcsr04 = _data1; ErrorIntegral(_dataHcsr04 * 0.017); _sumHcsr04 = _sumHcsr04 + _dataHcsr04; _contador++; } //--------------Promediando datos del muestreo y calculando distancias------------------ if (_contador == 29) { _promHcsr04 = _sumHcsr04 / 30; _contador = 0; _sumHcsr04 = 0; _sumTime = 0; _distanceHcsr04 = _promHcsr04 * 0.017; ErrorProporcional(_distanceHcsr04); ErrorDerivativo(_distanceHcsr04); //-------------Mandando distancia sensada por el sensor al monitor------------------ BufferContentHcsr04(Math.Round(_distanceHcsr04, 1).ToString()); BufferOutEp(Ep.ToString()); BufferOutEint(Ei.ToString()); BufferOutEderiv(Ed.ToString()); BufferOutPwm(_pwmPid.ToString()); //-----------------Envio de datos al arduino y graficación--------------------------- serialPort1_SenddataProportional(_distanceHcsr04); Updategraph(i++, _distanceHcsr04); serialPort1.DiscardInBuffer(); //-----------------Añadiendo datos a lista para su ingreso al excel------------------- Posiciones.Add(_distanceHcsr04); Errores.Add(Ep); if (i > 100) { i = 0; } } }
/* * public static BigInteger Pow(BigInteger value, BigInteger exponent) * { * BigInteger originalValue = value; * while (exponent-- > 1) * value = BigInteger.Multiply(value, originalValue); * return value; * }*/ public static MyRSAProvider.MyMyKeys GenerateKey(int Keysize) { //initialize constructor MyRSAProvider.MyMyKeys MyKeys = new MyRSAProvider.MyMyKeys(); //Get prime P P = GetPrime(Keysize); //Get prime Q Q = GetPrime(Keysize); //calculate the modulus N = GetN(P, Q); //calculate the totient or phi To = GetTotient(P, Q); // Get the value of the public exponent...(65537) E = GetE(); //compute the value of the private exponent such that (D*E % To) = 1 D = GetD(E, To); //calculate other properties of the private and public keys to be used in chinese remender theorem Dp = D % (P - 1); Dq = D % (Q - 1); Ep = E % (P - 1); Eq = E % (Q - 1); Qinv = GetD(Q, P); //get the keysize into our constructor MyKeys.KeySize = Keysize; //do checks to see that everything is in other else calculate again if (P == 0 || Q == 0 || N == 0 || To == 0 || D == 0 || P == Q || (D * E % To) != 1) { GenerateKey(Keysize); } //Add the private key values to the constructor MyKeys.PrivateKey.Add(new MyRSAProvider.PrivateKey { D = D.ToString(), N = N.ToString(), Dp = Dp.ToString(), Dq = Dq.ToString(), Qinv = Qinv.ToString(), P = P.ToString(), Q = Q.ToString() }); //Add the public key values to the constructor MyKeys.PublicKey.Add(new MyRSAProvider.PublicKey { E = E.ToString(), N = N.ToString(), Ep = Ep.ToString(), Eq = Eq.ToString(), Qinv = Qinv.ToString(), P = P.ToString(), Q = Q.ToString() }); return(MyKeys); }