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 ret = 1;
try
{
Log.Debug("生成设置码开始: kh is:" + kh);
if (0 == kzt)
{
string kh1=kh.Substring(kh.Length - 6, 6);
string result = (Encrypt(525252, Convert.ToInt32(kh1)) + "").PadLeft(8, '0');
// MessageBox.Show("设置码:"+result);
kmm = result;
Log.Debug("--kmm--" + kmm);
if(result.Equals(null))
{
ret = -1;
}
else
{
ret = 0;
}
}
else if(2 == kzt)
{
string result1 = (Encrypt(Convert.ToInt32(kh), 0) + "").PadLeft(8, '0');//生成清零码
string result2 = (Encrypt(Convert.ToInt32(kh), (cs) * 1000 + ql) + "").PadLeft(8, '0');//剩余气量吗
string result3 = (Encrypt(525252, Convert.ToInt32(kh)) + "").PadLeft(8, '0');//设置码
kmm = result1 + "|" + result3 + "|" + result2;
// MessageBox.Show("清零码:" + result1 + "---" + "设置码:" + result3 + "---" + "剩余气量码:" + result2);
ret = 0;
}
else //如果气量等于0,补卡
{
Log.Debug("生成解锁码开始:");
int mc = Convert.ToInt32(kh);
String codes = "";
// cs = (short)(cs - 1);
for (int i = cs - 1; i >= 0; i--)
{
codes = (Encrypt(mc, 1000 * (i + 1) + mc % 1000) + "").PadLeft(8, '0') + "|" + codes;
}
string opencodes = codes.TrimEnd(new Char[] { '|' });
//MessageBox.Show("解锁码:"+opencodes);
kmm = opencodes;
if (codes.Equals(null))
{
ret = -1;
}
else
{
ret = 0;
}
}
}
catch (Exception e)
{
Log.Debug("make card end:" + e.Message + "--stack--:" + e.StackTrace);
}
return ret;
}