/// <summary> /// 生成连续编码的流水号 /// </summary> /// <param name="insName"></param> /// <param name="num"></param> /// <returns></returns> public static string GetFlowID(string prefix, int num = 1) { try { string sql = "UPDATE autoins SET ins_number = string(cast(ins_number as numeric(10)) + ?) Where ins_id = ?"; OdbcTool.ExecuteSql(sql, num, prefix); sql = "SELECT ins_number FROM autoins Where autoins.ins_id = ?"; int x = int.Parse(OdbcTool.ExecuteSql(sql, prefix).ToString()); if (x == 0) { throw new Exception("流水号生成失败:" + prefix); } string str = "00000000" + x.ToString(); return(prefix + str.Substring(str.Length - 8, 8)); } catch (Exception) { throw; } }
/// <summary> /// 设置数据库值 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public static bool SetDbValue(string key, string value) { if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) { return(false); } string sql = "select count(*) from uoption where opt_id= ?;"; int cnt = (int)OdbcTool.ExecuteScalar(sql, key); if (cnt < 1) { sql = "insert into uoption(opt_id,note) values(?,?);"; cnt = (int)OdbcTool.ExecuteSql(sql, key, value); } else { sql = "update uoption set note = ? where opt_id = ?;"; cnt = (int)OdbcTool.ExecuteSql(sql, value, key); } return(cnt > 0); }
/// <summary> /// 添加客单 /// </summary> /// <returns></returns> public bool AddOrder(Curorder order, IList <CurorderDetail> details, int channel, string paycode) { int UserId = 0; string Phone = string.Empty; string HmeFlowId_Last = string.Empty; if (order == null || details.Count < 1) { throw new Exception("客单或客单明细不能为空"); } if (channel > 0) //如果非现金支付 { Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始提交预结账流水", "结账"); //提交消费流水(预流水) MsgArgs msg = (new HttpSubmitConsumeSerial("0")).Request(order, details); if (msg.Code != 1) { throw new Exception("提交流水失败\n" + msg.ErrMessage); } Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始支付", "结账"); //提交扫码支付 msg = (new HttpMicropay()).Request(order.HmeOrderId, channel, paycode); if (msg.Code != 1) { throw new Exception("付款失败\n" + msg.ErrMessage); } Debug.WriteLine(DateTime.Now.ToString() + "\r\n支付返回", "结账"); JObject jobj = JObject.Parse(msg.Content); if (string.IsNullOrEmpty(jobj["data"]["userId"].ToString())) { UserId = 0; } else { UserId = int.Parse(jobj["data"]["userId"].ToString()); } Phone = jobj["data"]["phone"].ToString(); } //转换当前客单及明细为历史客单及明细 Hisorder h = CurorderToHisorder(order); order.HmeUserId = UserId; h.HmeUserId = UserId; List <HisorderDetail> hlist = new List <HisorderDetail>(); Bill bill = CreateBill(h); for (int i = 0; i < details.Count; i++) { hlist.Add(CurorderDetailToHisorderDetail(details[i])); } try { Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始保存本地账单", "结账"); OdbcTransTool tran = new OdbcTransTool(); OdbcCommand cmd; DataTable dtHisorder = EntityTool.EntityToDataTable <Hisorder>(h, out cmd); tran.UpdateDataTableUsingTrans(dtHisorder, cmd); DataTable dtHisorderDetail = EntityTool.EntityListToDataTable(hlist, out cmd); tran.UpdateDataTableUsingTrans(dtHisorderDetail, cmd); DataTable dtBill = EntityTool.EntityToDataTable <Bill>(bill, out cmd); tran.UpdateDataTableUsingTrans(dtBill, cmd); tran.Commit(); Debug.WriteLine(DateTime.Now.ToString() + "\r\n本地账单保存完成", "结账"); try { Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始提交最终结账流水", "结账"); //提交消费流水(最终流水),就算失败也不影响结账流程 MsgArgs msg = (new HttpSubmitConsumeSerial("1")).Request(order, details); if (msg.Code != 1) { MessageBox.Show("结账成功但提交流水失败\n" + msg.ErrMessage, "提示信息"); } Debug.WriteLine(DateTime.Now.ToString() + "\r\n最终结账流水提交完成", "结账"); HmeFlowId_Last = JObject.Parse(msg.Content)["data"].ToString(); } catch (Exception e) { MessageBox.Show("结账成功但提交流水失败\n" + e.Message, "提示信息"); } string sql = "update hisorder set hme_id = ? where hisorder_id = ?"; OdbcTool.ExecuteSql(sql, HmeFlowId_Last, h.HisorderId.Substring(0, 18)); return(true); } catch (Exception e) { throw new Exception("添加客单失败\n" + e.Message); } }