/// <summary> /// 保存商户信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { Merchant merchant = GetMerchantInfo(); // 修改卡信息:修改已经存在的商户信息 if (op == Operation.编辑) { if (CheckInput()) { string msg = string.Empty; if (Common.ModifyMerchant(merchant, out msg)) { formMain.UpdateRefesh(); MessageBox.Show("修改信息成功"); } else { MessageBox.Show("修改信息失败"); } } else { return; } } // 开卡:商户不存在,创建新的商户并且绑定IC卡 if (op == Operation.开卡) { if (cardNo != api.GetCardNo()) { MessageBox.Show("开卡过程中不能换卡"); return; } if (CheckInput()) { string msg = string.Empty; if (Common.CreateAccount(merchant, out msg)) { // 写卡 string cardId = merchant.ID;//卡id=客户id cardId = cardId + "0000000000000000000000"; string tmp; byte[] data = new byte[16]; int j = 0; for (int i = 0; i < 16; i++) { tmp = cardId.Substring(j, 2); data[i] = (byte)Convert.ToInt32(tmp, 16); j = j + 2; } if (!api.WriteCard(data)) { Clipboard.SetDataObject(merchant.CardID); MessageBox.Show(string.Format("写卡失败,请使用写卡功能将卡号写入,卡号已经被复制。", merchant.CardID)); } formMain.tbxCardId.Text = merchant.ID; formMain.UpdateRefesh(); MessageBox.Show("卡片绑定成功"); } else { MessageBox.Show("卡片绑定失败:" + msg); } } else { return; } } this.Close(); }