/// <summary> /// 销售 /// </summary> /// <param name="order"></param> /// <returns></returns> private bool InsertLSXHD(QT_GoodsInfo order) { bool result = false; string KHDM = order.store_id.ToString(); string sql2 = "select top 1 KHDM,QDDM,CKDM,ZK,JGSD from kehu where khdm='" + KHDM + "'"; DataTable dataTable = BusinessDbUtil.GetDataTable(sql2); string CKDM = dataTable.Rows[0]["CKDM"].ToString(); string text = dataTable.Rows[0]["JGSD"].ToString(); string QDDM = dataTable.Rows[0]["QDDM"].ToString(); string SL = order.amount.ToString(); var DJBH = InvoicesManage.GetNewDJBH("LSXHD", QDDM, CKDM, ""); string arg = "SELECT djbh,ydjh,qddm,dm1,dm2,dm2_1,rq,sl,je,bz,zdr,rq_4,shr,sh,shrq,ygdm,byzd1,ll,byzd12,je_1,isonline FROM LSXHD"; DataTable table = BusinessDbUtil.GetDataTable(string.Format("{0} WHERE djbh='{1}'", arg, order.store_id)); table.TableName = "LSXHD"; table.PrimaryKey = new DataColumn[] { table.Columns["djbh"] }; //取商品信息 包括价格 string sql = string.Format(@"IF EXISTS (select 1 from TMDZB inner join sg_gatherings on TMDZB.SPDM = sg_gatherings.vstyle and TMDZB.gg1dm=sg_gatherings.vcolor and TMDZB.gg2dm =sg_gatherings.vsize where TMDZB.SPDM ='{0}' and TMDZB.SPTM='{1}' and sg_gatherings.vmbillid='{2}' ) BEGIN select TMDZB.SPDM,TMDZB.GG1DM,TMDZB.GG2DM,sg_gatherings.frealprice as BZSJ from TMDZB inner join sg_gatherings on TMDZB.SPDM = sg_gatherings.vstyle and TMDZB.gg1dm=sg_gatherings.vcolor and TMDZB.gg2dm =sg_gatherings.vsize where TMDZB.SPDM ='{0}' and TMDZB.SPTM='{1}' and sg_gatherings.vmbillid='{2}' END ELSE BEGIN select distinct TMDZB.SPDM,TMDZB.GG1DM,TMDZB.GG2DM,SHANGPIN.BZSJ from TMDZB inner join SHANGPIN on TMDZB.SPDM=SHANGPIN.SPDM where TMDZB.SPDM='{0}' and TMDZB.SPTM='{1}' END" , order.item_id, order.sku_id, order.order_id); DataTable dt_SP = InvoicesManage.ExecuteQuery(sql); LogUtil.WriteInfo(this, "查询商品价格信息", "查询价格sql" + sql + "数据结果:" + JsonParser.ToJson(dt_SP)); BusinessDbUtil.DoAction(delegate(DirectDbManger dbManager) { try { if (table.Rows.Count < 1) { if (ValidDJUtil.IsExistKHDM(this, order.order_id, order.store_id)) { string columns = SqlUtil.GetColumns(table); DataRow dataRow = table.NewRow(); dataRow["djbh"] = DJBH; dataRow["ydjh"] = order.order_id; dataRow["qddm"] = QDDM; dataRow["dm1"] = order.store_id; dataRow["dm2"] = CKDM; dataRow["dm2_1"] = "000"; dataRow["rq"] = DateTime.Now.ToShortDateString(); dataRow["bz"] = "蜻蜓平台同步"; dataRow["sl"] = SL; //商品价格信息需要取自单据创建的时候小票的价格信息 dataRow["je"] = Convert.ToDecimal(dt_SP.Rows[0]["BZSJ"]) * Convert.ToDecimal(order.amount); dataRow["zdr"] = "QT"; dataRow["rq_4"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); dataRow["ygdm"] = "000"; dataRow["byzd1"] = ValidDJUtil.GetJGXD(this, KHDM, "JGSD"); dataRow["ll"] = "1"; dataRow["byzd12"] = "1"; dataRow["isonline"] = "1"; dataRow["je_1"] = Convert.ToDecimal(dt_SP.Rows[0]["BZSJ"]) * Convert.ToDecimal(order.amount); table.Rows.Add(dataRow); string text2 = SqlUtil.ConvertInsert(table, columns, dataRow); DataTable dataTable2 = BusinessDbUtil.GetDataTable(string.Format("SELECT djbh,mibh,spdm,gg1dm,gg2dm,ckj,dj,sl,zk,bzje,je FROM LSXHDMX WHERE 1=0", new object[0])); dataTable2.TableName = "LSXHDMX"; dataTable2.PrimaryKey = new DataColumn[] { dataTable2.Columns["djbh"], dataTable2.Columns["mibh"] }; bool flag = true; string columns2 = SqlUtil.GetColumns(dataTable2); DataRow dataRow3 = dataTable2.NewRow(); dataRow3["djbh"] = DJBH; dataRow3["mibh"] = 0; dataRow3["spdm"] = order.item_id; dataRow3["gg1dm"] = dt_SP.Rows[0]["GG1DM"]; dataRow3["gg2dm"] = dt_SP.Rows[0]["GG2DM"]; dataRow3["dj"] = Convert.ToDecimal(dt_SP.Rows[0]["BZSJ"]); dataRow3["ckj"] = Convert.ToDecimal(dt_SP.Rows[0]["BZSJ"]); dataRow3["sl"] = order.amount; dataRow3["zk"] = "1"; dataRow3["je"] = Convert.ToDecimal(dt_SP.Rows[0]["BZSJ"]) * Convert.ToDecimal(order.amount); dataRow3["bzje"] = Convert.ToDecimal(dt_SP.Rows[0]["BZSJ"]) * Convert.ToDecimal(order.amount); dataTable2.Rows.Add(dataRow3); if (flag) { DataTable dataTable3 = BusinessDbUtil.GetDataTable(string.Format("SELECT DJBH,mibh,JSFS,JE FROM LSXHDJS WHERE 1=0", new object[0])); dataTable3.TableName = "LSXHDJS"; dataTable3.PrimaryKey = new DataColumn[] { dataTable3.Columns["DJBH"], dataTable3.Columns["mibh"] }; DataRow dataRow4 = dataTable3.NewRow(); dataRow4["DJBH"] = DJBH; dataRow4["mibh"] = 1; dataRow4["JSFS"] = "999"; dataRow4["JE"] = Convert.ToDecimal(dt_SP.Rows[0]["BZSJ"]) * Convert.ToDecimal(order.amount); dataTable3.Rows.Add(dataRow4); IEnumerable <string> enumerable = SqlUtil.Convert(dataTable2); IEnumerable <string> enumerable2 = SqlUtil.Convert(dataTable3); bool flag2 = false; try { sql = dbManager.ExecuteBatchQuery(out flag2, text2, enumerable, enumerable2); InvoicesManage.UpdateBillPrice(DJBH, "LSXHD"); DataTable procedureParameter = dbManager.GetProcedureParameter("P_LSXHDFLAGPROCESS"); dbManager.SetProcedureParameter(procedureParameter, "DJBH", DJBH); dbManager.SetProcedureParameter(procedureParameter, "USER", "QT"); dbManager.SetProcedureParameter(procedureParameter, "Flag", "1"); dbManager.SetProcedureParameter(procedureParameter, "OpDate", DateTime.Now.ToShortDateString()); DataTable dataTable4 = dbManager.ExecProcedure("P_LSXHDFLAGPROCESS", procedureParameter); DataTable procedureParameter2 = dbManager.GetProcedureParameter("P_UPDATEPTKC_1"); dbManager.SetProcedureParameter(procedureParameter2, "ckdm", CKDM); dbManager.SetProcedureParameter(procedureParameter2, "kwdm", "000"); dbManager.SetProcedureParameter(procedureParameter2, "tblName", "LSXHDMP"); dbManager.SetProcedureParameter(procedureParameter2, "djbh", DJBH); dbManager.SetProcedureParameter(procedureParameter2, "intSlLx", -1); DataTable dataTable5 = dbManager.ExecProcedure("P_UPDATEPTKC_1", procedureParameter2); //更新小票日结状态 var lsxhCounts = "select sum(lsxhdmx.sl) as sl from lsxhdmx left join lsxhd on lsxhd.djbh = lsxhdmx.djbh where lsxhd.ydjh='" + order.order_id + "'"; DataTable lsxhCounts_Table = BusinessDbUtil.GetDataTable(lsxhCounts); var sg_Counts = "select sum(fquantity) as sl from sg_gatherings where vmbillid='" + order.order_id + "'"; DataTable sg_Counts_Table = BusinessDbUtil.GetDataTable(lsxhCounts); if (sg_Counts_Table != null && sg_Counts_Table.Rows.Count > 0 && lsxhCounts_Table.Rows[0]["sl"] == sg_Counts_Table.Rows[0]["sl"]) { //小票明细数量和 BusinessDbUtil.GetDataTable("update sg_gathering set btotal= '1' where vmbillid ='" + order.order_id + "'"); } if (flag2 && dataTable4 != null && dataTable4.Rows.Count > 0 && dataTable5 != null && dataTable5.Rows.Count > 0) { LogUtil.WriteInfo(this, "", "单据保存成功,对应单据编号为:" + DJBH); result = true; } else { LogUtil.WriteInfo(this, "", string.Concat(new object[] { "单据保存失败,对应sql语句为:", text2, enumerable, enumerable2 })); } } catch (System.Exception ex) { LogUtil.WriteError(this, "", "单据保存成功,对应单据编号为:" + order.order_id); } } } } else { LogUtil.WriteInfo(this, "", "单据已存在,对应单据编号为:" + order.order_id); } } catch (Exception ex) { LogUtil.WriteError(this, sql, ex, ""); result = false; } }); this.UpdatesetAmountChangedState(order); return(result); }