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)
{
Log.Debug("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)=("
+ com + "," + baud + "," + kmm + "," + kzt
+ kh + "," + dqdm + "," + yhh + "," + tm
+ ql + "," + csql + "," + ccsql + "," + cs
+ ljgql + "," + bkcs + "," + ljyql + "," + bjql
+ czsx + "," + tzed + "," + sqrq + "," + cssqrq
+ oldprice + "," + newprice + "," + sxrq + "," + sxbj
+ ")");
byte [] cardNo = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);
byte[] yh = System.Text.Encoding.GetEncoding(1252).GetBytes(yhh);
byte[] cardid = new byte[20];
byte[] customeid = new byte[20];
int result = -1;
//写新卡前先格式化卡
//格式化卡之前先判断是否为新卡
byte[] Istrue =new byte[20];
int i = StaticCheckGasCard(com, Istrue);
int istrue1 =int.Parse(Encoding.ASCII.GetString(Istrue, 0, 1));
Log.Debug("CheckGasCardiSNew and i is" + i + " and isTrue is " + istrue1);
//判卡成功
//是新卡,则不需清卡 if (Istrue == 0)
//不是新卡,清卡 ,先读卡
if (istrue1 == 1)
{
Log.Debug("克罗姆写新卡非新卡清卡");
Log.Debug("WriteNewCard->StaticFormatGasCard(com, baud, mm, 2, cardNO, bdqdm)=(" + com + "," + baud + "," + kmm + "," + 2 + "," + cardNo + "," + dqdm + ")");
Int32 syql = 0;//当前表剩余气量
Int32 klxs = 0; //卡类型
Int32 ljgql1 = 0;
Int32 orderamount = 0;
Int32 orderNum = 0;
byte[] cardid1 = new byte[20];
byte[] customeid1 = new byte[20];
//清卡前先读卡 确保传入卡中的卡号等参数正确
Log.Debug("ReadGasCard(com, cardid, customeid, ref orderamount, ref orderNum, ref ljgql, ref syql, ref klx" + com + "," + cardid + "," +
customeid + "," + orderamount + "," + orderNum + "," + ljgql + "," + syql + "," + klx);
int readresult = ReadGasCard(com, cardid1, customeid1, ref orderamount, ref orderNum, ref ljgql1, ref syql, ref klx);
Log.Debug("ReadGasCard(com, cardid, customeid, ref orderamount, ref orderNum, ref ljgql, ref syql, ref klx)" + readresult);
byte[] customeNo = customeid1;
string yhhq = Encoding.ASCII.GetString(customeNo, 0, 10);
Log.Debug("FormatGasCard(short com, int baud, string kmm, string kh, string dqdm)=(" + com + "," + baud + "," + kmm + "," + kh + "," + dqdm + ")");
//清卡需要传入端口号 用户号
result = StaticFormatGasCard(com, customeNo);
Log.Debug("FormatGasCard(short com, int baud, string kmm, string kh, string dqdm)=" + result);
//清卡失败
if (result != 0)
{
Log.Debug("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)=" + result);
return result;
}
}
Log.Debug("WriteNewCard->StaticFormatGasCard(com, baud, mm, 2, cardNO, bdqdm)=(" + com + "," + baud + "," + kmm + "," + 2 + "," + cardNo + "," + dqdm + ")=" + result);
//kzt==0 表示新开户 写卡
if (0 == kzt)
{
result = MakeGasCard(com, cardNo, yh, 1, ql);
}
//kzt==1 表示补卡 写卡
else if(1 == kzt)
{
result = MakeGasCard(com, cardNo, yh, cs, ql);
}
String buf;
Log.Debug("发卡后读卡格式:");
MingHua.GetSnapShot(com, baud, out buf);
Log.Debug(buf);
Log.Debug("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)=("
+ com + "," + baud + "," + kmm + "," + kzt
+ kh + "," + dqdm + "," + yhh + "," + tm
+ ql + "," + csql + "," + ccsql + "," + cs
+ ljgql + "," + bkcs + "," + ljyql + "," + bjql
+ czsx + "," + tzed + "," + sqrq + "," + cssqrq
+ oldprice + "," + newprice + "," + sxrq + "," + sxbj
+ ")=" + result);
//转换错误代码
return result;
}
/// <summary>