private PaymentModeActionStatus UpdatePaymentMode(PaymentModeInfo paymentMode) { PaymentModeActionStatus status = PaymentModeActionStatus.UnknowError; //连接MySql数据库 using (MySqlConnection connection = DbHelperMySQL.GetConnection) { if (connection.State == ConnectionState.Closed) { connection.Open(); } using (MySqlTransaction transaction = connection.BeginTransaction()) { try { string strSql = string.Format("Select DisplaySequence From Pay_PaymentTypes where ModeId={0}", paymentMode.ModeId); MySqlParameter[] pars = { }; object objSeq = DbHelperMySQL.GetSingle4Trans(new CommandInfo(strSql, pars), transaction); int displaySequence = Common.Globals.SafeInt(objSeq, -1); if (displaySequence != paymentMode.DisplaySequence) { List <CommandInfo> sqllist = new List <CommandInfo>(); StringBuilder strSql1 = new StringBuilder(); strSql1.AppendFormat("UPDATE Pay_PaymentTypes set DisplaySequence = DisplaySequence + 1 where DisplaySequence >= {0} ;", paymentMode.DisplaySequence); MySqlParameter[] parameters1 = { }; sqllist.Add(new CommandInfo(strSql1.ToString(), parameters1, EffentNextType.ExcuteEffectRows)); DbHelperMySQL.ExecuteSqlTran4Indentity(sqllist, transaction); } List <CommandInfo> sqllist2 = new List <CommandInfo>(); string str2 = @"UPDATE Pay_PaymentTypes SET MerchantCode=?MerchantCode, EmailAddress=?EmailAddress, SecretKey=?SecretKey, SecondKey=?SecondKey, Password=?Password,Partner=?Partner, Name=?Name, Description=?Description, Gateway=?Gateway, DisplaySequence=?DisplaySequence, Charge=?Charge, IsPercent=?IsPercent, AllowRecharge=?AllowRecharge,Logo=?Logo,DrivePath=?DrivePath WHERE ModeId = ?ModeId;"; MySqlParameter[] pars2 = { new MySqlParameter("?MerchantCode", MySqlDbType.VarChar, 300), new MySqlParameter("?EmailAddress", MySqlDbType.VarChar, 255), new MySqlParameter("?SecretKey", MySqlDbType.VarChar, 4000), new MySqlParameter("?SecondKey", MySqlDbType.VarChar, 4000), new MySqlParameter("?Password", MySqlDbType.VarChar, 4000), new MySqlParameter("?Partner", MySqlDbType.VarChar, 300), new MySqlParameter("?Name", MySqlDbType.VarChar, 100), new MySqlParameter("?Description", MySqlDbType.Text), new MySqlParameter("?Gateway", MySqlDbType.VarChar, 200), new MySqlParameter("?DisplaySequence", MySqlDbType.Int32, 4), new MySqlParameter("?Charge", MySqlDbType.Decimal, 8), new MySqlParameter("?IsPercent", MySqlDbType.Int16, 2), new MySqlParameter("?AllowRecharge", MySqlDbType.Int16, 2), new MySqlParameter("?Logo", MySqlDbType.VarChar, 255), new MySqlParameter("?DrivePath", MySqlDbType.VarChar, 255), new MySqlParameter("?ModeId", MySqlDbType.Int32, 4) }; pars2[0].Value = paymentMode.MerchantCode; pars2[1].Value = paymentMode.EmailAddress; pars2[2].Value = paymentMode.SecretKey; pars2[3].Value = paymentMode.SecondKey; pars2[4].Value = paymentMode.Password; pars2[5].Value = paymentMode.Partner; pars2[6].Value = paymentMode.Name; pars2[7].Value = paymentMode.Description; pars2[8].Value = paymentMode.Gateway; pars2[9].Value = paymentMode.DisplaySequence; pars2[10].Value = paymentMode.Charge; pars2[11].Value = paymentMode.IsPercent; pars2[12].Value = paymentMode.AllowRecharge; pars2[13].Value = paymentMode.Logo; pars2[14].Value = paymentMode.DrivePath; pars2[15].Value = paymentMode.ModeId; sqllist2.Add(new CommandInfo(str2, pars2, EffentNextType.ExcuteEffectRows)); string strDel = string.Format("DELETE From Pay_PaymentCurrencys Where ModeId={0}", paymentMode.ModeId); sqllist2.Add(new CommandInfo(strDel, pars2, EffentNextType.None)); DbHelperMySQL.ExecuteSqlTran4Indentity(sqllist2, transaction); List <CommandInfo> sqllist3 = new List <CommandInfo>(); StringBuilder strSql3 = new StringBuilder(); int num = 0; foreach (string str in paymentMode.SupportedCurrencys) { strSql3.AppendFormat("INSERT INTO Pay_PaymentCurrencys(ModeId,Code) Values({0},'{1}');", paymentMode.ModeId, str); num++; } if (strSql3.Length > 0) { MySqlParameter[] parameters3 = { }; sqllist3.Add(new CommandInfo(strSql3.ToString(), parameters3, EffentNextType.ExcuteEffectRows)); DbHelperMySQL.ExecuteSqlTran4Indentity(sqllist3, transaction); } transaction.Commit(); status = PaymentModeActionStatus.Success; } catch (MySqlException) { transaction.Rollback(); throw; } } } return(status); }