Card.HuaQing.WriteNewCard C# (CSharp) Метод

WriteNewCard() публичный Метод

public WriteNewCard ( short com, int baud, string &kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj, int klx, string meterid ) : int
com short
baud int
kmm string
kzt short
kh string
dqdm string
yhh string
tm string
ql int
csql int
ccsql int
cs short
ljgql int
bkcs short
ljyql int
bjql int
czsx int
tzed int
sqrq string
cssqrq string
oldprice int
newprice int
sxrq string
sxbj string
klx int
meterid string
Результат int
        public int WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj, int klx, string meterid)
        {
            //产生随机数
            Random example = new Random();
            byte[] Test1 = new byte[256];
            for (int i = 32; i <= 255; i++)
            {
                Test1[i] = byte.Parse(example.Next(1, 200).ToString());

            }
            String UserID = "0100010000"+kh;
            //读卡判断是否为新卡  读23位置  省略
            Log.Debug("HuaQing Write NewCard UserID is " + UserID);
            //上次购气日期本次购气日期未处理
            Test1[80] = 0x20;
            Test1[81] = 0x15;
            Test1[82] = 0x11;
            Test1[83] = 0x24;
            Test1[84] = 0xee;
            Test1[85] = 0x20;
            Test1[86] = 0x15;
            Test1[87] = 0x11;
            Test1[88] = 0x24;
            Test1[95] = 0x11;
            Test1[137] = byte.Parse((int.Parse(UserID.Substring(2, 1)) * 16 + int.Parse(UserID.Substring(3, 1))).ToString());
            Test1[138] = byte.Parse((int.Parse(UserID.Substring(4, 1)) * 16 + int.Parse(UserID.Substring(5, 1))).ToString());
            Test1[139] = byte.Parse((int.Parse(UserID.Substring(6, 1)) * 16 + int.Parse(UserID.Substring(7, 1))).ToString());

            Test1[140] = byte.Parse((int.Parse(UserID.Substring(8, 1)) * 16 + int.Parse(UserID.Substring(9, 1))).ToString());
            Test1[141] = byte.Parse((int.Parse(UserID.Substring(10, 1)) * 16 + int.Parse(UserID.Substring(11, 1))).ToString());
            Test1[142] = byte.Parse((int.Parse(UserID.Substring(12, 1)) * 16 + int.Parse(UserID.Substring(13, 1))).ToString());

            Test1[143] = byte.Parse((int.Parse(UserID.Substring(0, 1)) * 16 + int.Parse(UserID.Substring(1, 1))).ToString());
            Test1[161] = byte.Parse((int.Parse(UserID.Substring(0, 1)) * 16 + int.Parse(UserID.Substring(1, 1))).ToString());
            Test1[162] = byte.Parse((int.Parse(UserID.Substring(2, 1)) * 16 + int.Parse(UserID.Substring(3, 1))).ToString());

            Test1[163] = byte.Parse((int.Parse(UserID.Substring(4, 1)) * 16 + int.Parse(UserID.Substring(5, 1))).ToString());
            Test1[164] = byte.Parse((int.Parse(UserID.Substring(6, 1)) * 16 + int.Parse(UserID.Substring(7, 1))).ToString());
            Test1[165] = byte.Parse((int.Parse(UserID.Substring(8, 1)) * 16 + int.Parse(UserID.Substring(9, 1))).ToString());


            Test1[166] = byte.Parse((int.Parse(UserID.Substring(10, 1)) * 16 + int.Parse(UserID.Substring(11, 1))).ToString());
            Test1[167] = byte.Parse((int.Parse(UserID.Substring(12, 1)) * 16 + int.Parse(UserID.Substring(13, 1))).ToString());
            Test1[176] = 104;
            Test1[177] = 113;
            Test1[178] = 152;
            Test1[180] = byte.Parse((int.Parse(UserID.Substring(6, 1)) * 16 + int.Parse(UserID.Substring(7, 1))).ToString());
            Test1[181] = byte.Parse((int.Parse(UserID.Substring(8, 1)) * 16 + int.Parse(UserID.Substring(9, 1))).ToString());

            Test1[182] = byte.Parse((int.Parse(UserID.Substring(1, 1)) * 16 + int.Parse(UserID.Substring(5, 1))).ToString());
            Test1[183] = byte.Parse((int.Parse(UserID.Substring(10, 1)) * 16 + int.Parse(UserID.Substring(11, 1))).ToString());
            Test1[184] = byte.Parse((int.Parse(UserID.Substring(12, 1)) * 16 + int.Parse(UserID.Substring(13, 1))).ToString());
            Test1[186] = 255;
            Test1[187] = 255;
            Test1[188] = 255;
            Test1[190] = byte.Parse((cs % 256).ToString()); //写卡次数
            int tt = 1 % 256;
            tt = tt % 256;
            //  Test1[191]=byte.Parse(tt.ToString());
            Test1[191] = 0;
           
            //   Test1[192]=byte.Parse((ql%256).ToString());
            //Test1[193]=byte.Parse((Test1[192]%256).ToString());
            //   Test1[194]=byte.Parse((Test1[193]%256).ToString());
            //   Test1[195]=byte.Parse((Test1[194]%256).ToString());
            Int32 Z = ql;


            int x11 = Z / 256;
            int x21 = x11 / 256;
            int x31 = x21 / 256;
            int x41 = x31 % 256;
            Test1[195] = byte.Parse(x41.ToString());
            int x51 = Z / 256;
            int x61 = x51 / 256;
            int x71 = x61 % 256;
            Test1[194] = Byte.Parse(x71.ToString());
            int x81 = Z / 256;
            int x91 = x81 % 256;
            Test1[193] = Byte.Parse(x91.ToString());
            Test1[192] = Byte.Parse((ql % 256).ToString());
            Test1[205] = 1;
            Test1[206] = 177;
            Test1[96] = 104;
            Test1[97] = 113;
            Test1[98] = 152;

            int p1 = int.Parse(UserID.Substring(0, 4)) + int.Parse(UserID.Substring(4, 4));
            int p2 = int.Parse(UserID.Substring(8, 4)) + int.Parse(UserID.Substring(12, 2));
            int p3 = int.Parse(UserID.Substring(1, 4)) + int.Parse(UserID.Substring(9, 4));
            string ps = p1.ToString() + p2.ToString() + p3.ToString();
            Int32 X = Int32.Parse(ps);


            int x1 = X / 1000;
            int x2 = x1 / 256;
            int x3 = x2 / 256;
            int x4 = x3 % 256;
            Test1[106] = byte.Parse(x4.ToString());
            int x5 = X / 1000;
            int x6 = x5 / 256;
            int x7 = x6 % 256;
            Test1[108] = Byte.Parse(x7.ToString());
            int x8 = X / 1000;
            int x9 = x8 % 256;
            Test1[107] = Byte.Parse(x9.ToString());


            int T = ql * 1000000;
            x5 = T / 256;
            x6 = x5 / 256;
            x7 = x6 % 256;
            Test1[32] = Byte.Parse(x7.ToString());


            x1 = X / 1000;
            x2 = x1 / 256;
            x3 = x2 / 256;
            x4 = x3 % 256;
            Test1[33] = byte.Parse(x4.ToString());
            x8 = T / 256;
            x9 = x8 % 256;
            Test1[34] = Byte.Parse(x9.ToString());
            Test1[35] = 104;
            x5 = X / 1000;
            x6 = x5 / 256;
            x7 = x6 % 256;
            Test1[36] = Byte.Parse(x7.ToString());
            Test1[37] = Byte.Parse((T % 256).ToString());

            x1 = T / 256;
            x2 = x1 / 256;
            x3 = x2 / 256;
            x4 = x3 % 256;
            Test1[38] = byte.Parse(x4.ToString());
            x8 = X / 1000;
            x9 = x8 % 256;
            Test1[39] = Byte.Parse(x9.ToString());
            x5 = 10000000 / 256;
            x6 = x5 / 256;
            x7 = x6 % 256;
            Test1[40] = Byte.Parse(x7.ToString());
            x1 = 10000000 / 256;
            x2 = x1 / 256;
            x3 = x2 / 256;
            x4 = x3 % 256;
            Test1[41] = byte.Parse(x4.ToString());


            x5 = T / 256;
            x6 = x5 / 256;
            x7 = x6 % 256;
            byte[] temp = new byte[256];
         
            for (int i = 0; i <= 223; i++)
            {

                temp[i] = Test1[i + 32];
            }
            temp[224] = 0;
            byte[] Data1 = new byte[224];
            int icdev = ic_init(com, baud);

            byte[] passwd = new byte[3] { 0xff, 0xff, 0xff };


            int p11 = int.Parse(UserID.Substring(0, 4)) + int.Parse(UserID.Substring(4, 4));
            int p21 = int.Parse(UserID.Substring(8, 4)) + int.Parse(UserID.Substring(12, 2));
            int p31 = int.Parse(UserID.Substring(1, 4)) + int.Parse(UserID.Substring(9, 4));
            string ps1 = p11.ToString() + p21.ToString() + p31.ToString();
            Int32 XX = Int32.Parse(ps1);

            byte[] passwd1 = new byte[3];
            int x111 = XX / 1000;
            int x211 = x111 / 256;
            int x311 = x211 / 256;
            int x411 = x311 % 256;
            passwd1[0] = byte.Parse(x411.ToString());
            int x511 = XX / 1000;
            int x611 = x511 / 256;
            int x711 = x611 % 256;
            passwd1[1] = Byte.Parse(x711.ToString());
            int x811 = XX / 1000;
            int x911 = x811 % 256;
            passwd1[2] = Byte.Parse(x911.ToString());
            //  byte[] passhex = new byte[3];
            // int aaa = asc_hex(passwd1, passhex, 3);
            int z = 0;
            //    csc_4442(icdev, 3, passwd);
            ////修改密码
            z = csc_4442(icdev, 3, passwd);
            Log.Debug("HuaQing CheckPass end and z is " + z);
            int bbb = wsc_4442(icdev, 3, passwd1);


            Log.Debug("HuaQing ModifyPass Word end and z is " +bbb);



            int zzz = swr_4442(icdev, 0x20, 224, temp);
            Log.Debug("HuaQing WriteNewCard end and z is " + zzz);
            ic_exit(icdev);
            return zzz;
        }
        /// <summary>