Exemple #1
0
 public Form1()
 {
     InitializeComponent();
     clsXMLSettings xml      = new clsXMLSettings();
     xmlSettings    settings = xml.ReadSettings();
     clsWeb         web      = new clsWeb(settings);
 }
        public Boolean Decode()
        {
            string[] keyarray   = new string[100];
            string[] valuearray = new string[100];
            Verified_Customer = false;
            int j = 0, k = 0, startindex;

            response = clsWeb.responseFromServer;

            // response = "bZmlyYXxic3R4ffGN8bmFtZA10g==ZXxzZWNvbmRfbmFtZXxiaXJ0aF9wbGFjZXxkYXRlX29mX2JpcnRoh3";      //testing
            //response = "dZmlycYXxi$3Rf5bmFtZXxzZWNvb7gmRfbmFtZQ==$$$h1";                       //test

            if (!((response == "0") || (response == "1") || (response == null)))
            {
                clsXMLSettings clsxml = new clsXMLSettings();
                try
                {
                    settings          = clsxml.ReadSettings();
                    DBInfo.ServerName = settings.serverName;
                    DBInfo.DBName     = settings.dbName;
                    DBInfo.DBPort     = settings.dbPort;
                    DBInfo.DBUser     = settings.userName;
                    DBInfo.DBPWD      = settings.password;
                    password          = DBInfo.DBName;

                    connectionstring = clsDBConnection.CreateConnectionString(DBInfo);
                    MySqlConnection cnn = new MySqlConnection(connectionstring);
                    cnn.Open();
                    if (Verified_Customer)
                    {
                        // clsDBConnection.updateVersion(cnn, response);
                        return(true);
                    }
                    else
                    {
                        int      len         = response.Length;
                        string[] stringArray = clsWeb.splitStringToArray(response);
                        string[] stringArr   = { stringArray[1], stringArray[3], stringArray[6] };
                        keyArrayLength   = Convert.ToInt32(stringArray[4]);
                        valueArrayLength = Convert.ToInt32(stringArray[8]);
                        mergedstring     = clsWeb.generateCode(stringArr);
                        int random = Int32.Parse(stringArray[2].ToString());

                        string[] array = clsWeb.splitByIntNum(mergedstring, random);

                        //// Split an Array into two arrays ////

                        /*        if(keyArrayLength<valueArrayLength)
                         *      {
                         *           startindex = 0;
                         *           keyarray = smallStrArray(startindex,array,keyArrayLength);
                         *           valuearray= largeStrArray(startindex+1,array,keyArrayLength);
                         *      }
                         *      else if(keyArrayLength>valueArrayLength)
                         *      {
                         *            startindex = 1;
                         *            keyarray = largeStrArray(startindex-1,array, valueArrayLength);
                         *            valuearray = smallStrArray(startindex,array, valueArrayLength);
                         *       }  */
                        while (keyArrayLength < valueArrayLength)
                        {
                            while (pos < keyArrayLength)
                            {
                                if (index % 2 == 0)
                                {
                                    keyarray[pos] = array[index];
                                    pos++;
                                }
                                else
                                {
                                    valuearray[pos1] = array[index];
                                    pos1++;
                                }
                                index++;
                            }
                            if (pos >= keyArrayLength)
                            {
                                valuearray[pos1] = array[index];
                                index++; pos1++;
                            }
                            if (index >= array.Length)
                            {
                                break;
                            }
                        }
                        while (valueArrayLength < keyArrayLength)
                        {
                            while (pos <= valueArrayLength)
                            {
                                if (index % 2 == 0)
                                {
                                    keyarray[pos] = array[index];
                                    pos++;
                                }
                                else
                                {
                                    valuearray[pos1] = array[index];
                                    pos1++;
                                }
                                index++;
                            }
                            if (index > valueArrayLength)
                            {
                                keyarray[pos] = array[index];
                                index++;
                                pos++;
                            }
                            if (index >= array.Length)
                            {
                                break;
                            }
                        }

                        keyarray   = keyarray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                        valuearray = valuearray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                        /////////////////////////

                        //// Find last element from array  and if "$" exist , Remove it    ////

                        keyarray   = removeLastEle(keyarray.Last(), keyarray);
                        valuearray = removeLastEle(valuearray.Last(), valuearray);

                        ////////////////////////

                        string   keystring   = clsWeb.generateCode(keyarray);
                        string   valuestring = clsWeb.generateCode(valuearray);
                        string   keys        = clsWeb.Base64Decode(keystring);
                        string   values      = clsWeb.Base64Decode(valuestring);
                        string[] keysArr     = clsWeb.decodedArray(keys);
                        string[] valuessArr  = clsWeb.decodedArray(values);
                        string   cust        = getValue(keysArr, valuessArr, "cus");
                        string   seq         = getValue(keysArr, valuessArr, "seq");
                        string   prd         = getValue(keysArr, valuessArr, "prd");
                        string   edn         = getValue(keysArr, valuessArr, "edn");

                        clsDBConnection.updateTable(cnn, cust, seq, prd, edn);
                    }
                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                    return(false);
                }
            }
            return(true);
        }