public static Param[] Decrypt(string Parameters) { Parameters = "*" + Parameters; // musim pridat '*' Param[] retParams = null; const char ParamStart = '*'; const char ParamSeparator = '&'; const char ParamEqual = '='; int i = Parameters.IndexOf(ParamStart); //int i = 0; int j = i; int k; if (i >= 0) { while ((i < Parameters.Length) || (i == -1)) { j = Parameters.IndexOf(ParamEqual, i); if (j > i) { //first param! if (retParams == null) { retParams = new Param[1]; retParams[0] = new Param(); } else { Param[] rettempParams = new Param[retParams.Length + 1]; retParams.CopyTo(rettempParams, 0); rettempParams[rettempParams.Length - 1] = new Param(); retParams = new Param[rettempParams.Length]; rettempParams.CopyTo(retParams, 0); } k = Parameters.IndexOf(ParamSeparator, j); retParams[retParams.Length - 1].Name = Parameters.Substring(i + 1, j - i - 1); //case'est la fin et il n'y a rien if (k == j) { retParams[retParams.Length - 1].Value = ""; } // cas normal else if (k > j) { retParams[retParams.Length - 1].Value = Parameters.Substring(j + 1, k - j - 1); } //c'est la fin else { retParams[retParams.Length - 1].Value = Parameters.Substring(j + 1, Parameters.Length - j - 1); } if (k > 0) i = Parameters.IndexOf(ParamSeparator, k); else i = Parameters.Length; } else i = -1; } } return retParams; }
/// <summary> /// /// </summary> /// <param name="param"></param> public static bool Parse(Param[] param) { for (int i = 0; i < param.Length; i++) { if (param[i].Value == "NULL") param[i].Value = "0"; switch (param[i].Name) { case "result": HttpData.result = param[i].Value; break; case "event": HttpData.events = int.Parse(param[i].Value); break; case "card": HttpData.card = param[i].Value; break; case "exception": HttpData.exception = param[i].Value; break; case "uniqueid": HttpData.uniqueid = param[i].Value; break; case "rows": HttpData.rows = int.Parse(param[i].Value); break; case "confirmed": HttpData.confirmed = param[i].Value; break; ; } // settings if (HttpData.events == 100) { switch (param[i].Name) { case "company": Settings.company = int.Parse(param[i].Value); break; case "name": Settings.name = param[i].Value; break; case "currency": Settings.currency = param[i].Value; break; case "poscount": Settings.buttonNumber = int.Parse(param[i].Value); break; case "isclosed": Settings.isClosed = int.Parse(param[i].Value); break; default: break; } } // lahev if (HttpData.events == 101) { switch (param[i].Name) { case "position": BottleData.position = int.Parse(param[i].Value); break; case "plu": BottleData.plu = int.Parse(param[i].Value); break; case "name": if (param[i].Value == "0") BottleData.name = "Neobsazeno"; else BottleData.name = param[i].Value; break; case "grower": BottleData.grower = param[i].Value; break; case "country": BottleData.country = param[i].Value; break; case "attribute": BottleData.attribute = param[i].Value; break; case "vintage": BottleData.vintage = param[i].Value; break; case "volume": BottleData.volume = int.Parse(param[i].Value); break; case "svolume": BottleData.smallVolume = int.Parse(param[i].Value); break; case "sprice": BottleData.smallPrice = int.Parse(param[i].Value); break; case "mvolume": BottleData.middleVolume = int.Parse(param[i].Value); break; case "mprice": BottleData.middlePrice = int.Parse(param[i].Value); break; case "lvolume": BottleData.largeVolume = int.Parse(param[i].Value); break; case "lprice": BottleData.largePrice = int.Parse(param[i].Value); break; case "isclosed": BottleData.isclosed = int.Parse(param[i].Value); break; default: break; } } // karta if (HttpData.events == 200) { switch (param[i].Name) { case "name": DataCard.Name = param[i].Value; break; case "surname": DataCard.LName = param[i].Value; break; case "firstname": DataCard.FName = param[i].Value; break; case "credit": DataCard.Credit = Int64.Parse(param[i].Value); break; case "type": DataCard.Role = ((CardRole)int.Parse(param[i].Value)); break; case "discount": DataCard.Discount = int.Parse(param[i].Value); break; case "validity": DataCard.Validity = int.Parse(param[i].Value); break; default: break; } } // vydej if (HttpData.events == 201) { switch (param[i].Name) { // davka case "volume": HttpData.dosevolume = int.Parse(param[i].Value); break; // cena case "price": HttpData.doseprice = int.Parse(param[i].Value); break; } } } // end for return true; }
private void ParamParse(Param[] param) { byte[] reply; for (int i = 0; i < param.Length; i++) { switch (param[i].Name) { case "ver": if (param[i].Value == "?") { reply = Encoding.UTF8.GetBytes("*ver=basic+\t\r\n"); } else { reply = Encoding.UTF8.GetBytes("*bad data\t\r\n"); } com.Write(reply, 0, reply.Length); break; case "dir": if (param[i].Value == "log") { reply = Encoding.UTF8.GetBytes("*log=\r\n"); com.Write(reply, 0, reply.Length); int c = SendListFiles(@"SD\logg\"); reply = Encoding.UTF8.GetBytes("#dir=OK\t\r\n"); } else if (param[i].Value == "bill") { reply = Encoding.UTF8.GetBytes("*bill=\r\n"); com.Write(reply, 0, reply.Length); int c = SendListFiles(@"SD\account\"); reply = Encoding.UTF8.GetBytes("#dir=OK\t\r\n"); } else { reply = Encoding.UTF8.GetBytes("#bad data\t\r\n"); } com.Write(reply, 0, reply.Length); break; case "del": if (Backup(param[i].Value)) { reply = Encoding.UTF8.GetBytes("*del=1\r#del=OK\t\r\n"); } else { reply = Encoding.UTF8.GetBytes("*del=0\r#del=0\t\r\n"); } com.Write(reply, 0, reply.Length); break; case "set": if (param[i].Value == "?") { string set = GetSettings(); reply = Encoding.UTF8.GetBytes("*set=\r" + set + "\t\r#OK\r\n"); } else if (param[i].Value.Substring(0, 1) == "!") { string data = param[i].Value.Substring(1).Trim(); bool result = SaveSettings(data); if (result == true) { reply = Encoding.UTF8.GetBytes("*set=OK\t\r\n"); } else { reply = Encoding.UTF8.GetBytes("*set=ERROR\t\r\n"); } } else { reply = Encoding.UTF8.GetBytes("#bad data\t\r\n"); } com.Write(reply, 0, reply.Length); break; case "btl": int b = int.Parse(param[i].Value.Substring(1, 2)); reply = Encoding.UTF8.GetBytes("*btl="); com.Write(reply, 0, reply.Length); if (param[i].Value.Substring(0, 1) == "?") { string set = GetBottle(b); reply = Encoding.UTF8.GetBytes("?" + b + "\r" + set + "\t\r#btl?=OK\r\n"); } else if (param[i].Value.Substring(0, 1) == "!") { string dataparse = param[i].Value.Substring(3).Trim(); string[] data = dataparse.Split('/'); calib c = calibration.GetCalib(b); c.Caluclate(int.Parse(data[8]), int.Parse(data[12]), int.Parse(data[16])); data[7] = c.small.ToString(); data[11] = c.medium.ToString(); data[15] = c.large.ToString(); dataparse = calibration.Join('/', data); calibration.SaveCalib(b, c); SaveBtl(b, dataparse); ButtonRS485.SendSettings(b); ButtonRS485.IsEmpty(b); reply = Encoding.UTF8.GetBytes("!" + b + "\t\r#btl!=OK\r\n"); OnCom3Event(this, new Com3EventArgs() { Command = (int)ChangeCmd.bottle, Value = b }); } else { reply = Encoding.UTF8.GetBytes("\t\r#btl=bad data\r\n"); } com.Write(reply, 0, reply.Length); break; case "get": string path = param[i].Value; reply = Encoding.UTF8.GetBytes("*get=" + path + "\r"); com.Write(reply, 0, reply.Length); if ((path.IndexOf(".log") != -1) || (path.IndexOf(".LOG") != -1)) { string fullpath = @"SD\logg\" + path; SendFileData(fullpath); reply = Encoding.UTF8.GetBytes("\t#get=OK\r\n"); } else if ((path.IndexOf(".txt") != -1) || (path.IndexOf(".TXT") != -1)) { string fullpath = @"SD\account\" + path; SendFileData(fullpath); reply = Encoding.UTF8.GetBytes("\t#get=OK\r\n"); } else { reply = Encoding.UTF8.GetBytes("#get=bad data\t\r\n"); } com.Write(reply, 0, reply.Length); break; default: reply = Encoding.UTF8.GetBytes("\t#get=bad param\r\n"); com.Write(reply, 0, reply.Length); break; } } }