/// <summary> /// 更新一条数据 /// </summary> public void Update(VAN_OA.Model.JXC.Sell_OrderOutHouseBack model, SqlCommand objCommand) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Sell_OrderOutHouseBack set "); if (model.Remark != null) { strSql.Append("Remark='" + model.Remark + "',"); } else { strSql.Append("Remark= null ,"); } if (model.Status != null) { strSql.Append("Status='" + model.Status + "',"); } strSql.Append("BackTime='" + model.BackTime + "',"); strSql.Append("SellProNo='" + model.SellProNo + "',"); strSql.Append("BackType=" + model.BackType + ","); strSql.Append("SellTotal=" + model.SellTotal + ","); int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where Id=" + model.Id + ""); objCommand.CommandText = strSql.ToString(); objCommand.ExecuteNonQuery(); }
/// <summary> /// 对象实体绑定数据 /// </summary> public VAN_OA.Model.JXC.Sell_OrderOutHouseBack ReaderBind(IDataReader dataReader) { VAN_OA.Model.JXC.Sell_OrderOutHouseBack model = new VAN_OA.Model.JXC.Sell_OrderOutHouseBack(); object ojb; ojb = dataReader["Id"]; if (ojb != null && ojb != DBNull.Value) { model.Id = (int)ojb; } ojb = dataReader["CreateUserId"]; if (ojb != null && ojb != DBNull.Value) { model.CreateUserId = (int)ojb; } ojb = dataReader["CreateTime"]; if (ojb != null && ojb != DBNull.Value) { model.CreateTime = (DateTime)ojb; } ojb = dataReader["BackTime"]; if (ojb != null && ojb != DBNull.Value) { model.BackTime = (DateTime)ojb; } model.GuestName = dataReader["GuestName"].ToString(); model.BackType = Convert.ToInt32(dataReader["BackType"]); model.SellProNo = dataReader["SellProNo"].ToString(); model.ProNo = dataReader["ProNo"].ToString(); model.PONo = dataReader["PONo"].ToString(); model.POName = dataReader["POName"].ToString(); model.Remark = dataReader["Remark"].ToString(); ojb = dataReader["CreateName"]; if (ojb != null && ojb != DBNull.Value) { model.CreateName = ojb.ToString(); } ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = ojb.ToString(); } ojb = dataReader["SellTotal"]; if (ojb != null && ojb != DBNull.Value) { model.SellTotal = Convert.ToDecimal(ojb); } return(model); }
public bool updateTran(VAN_OA.Model.JXC.Sell_OrderOutHouseBack model, VAN_OA.Model.EFrom.tb_EForm eform, tb_EForms forms, List <Sell_OrderOutHouseBacks> orders, string IDS) { decimal total = 0; for (int i = 0; i < orders.Count; i++) { total += orders[i].GoodSellPriceTotal; } model.SellTotal = total; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; Sell_OrderOutHouseBacksService OrdersSer = new Sell_OrderOutHouseBacksService(); try { objCommand.Parameters.Clear(); model.Status = eform.state; Update(model, objCommand); tb_EFormService eformSer = new tb_EFormService(); eformSer.Update(eform, objCommand); tb_EFormsService eformsSer = new tb_EFormsService(); eformsSer.Add(forms, objCommand); //====删除所有子单据 string delete = "delete from Sell_OrderOutHouseBacks where id=" + model.Id; objCommand.CommandText = delete; objCommand.ExecuteNonQuery(); //==== for (int i = 0; i < orders.Count; i++) { orders[i].id = model.Id; OrdersSer.Add(orders[i], objCommand); } tan.Commit(); } catch (Exception) { tan.Rollback(); return(false); } } return(true); }
public int addTran(VAN_OA.Model.JXC.Sell_OrderOutHouseBack model, VAN_OA.Model.EFrom.tb_EForm eform, List <Sell_OrderOutHouseBacks> orders, out int MainId) { decimal total = 0; for (int i = 0; i < orders.Count; i++) { total += orders[i].GoodSellPriceTotal; } model.SellTotal = total; int id = 0; MainId = 0; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; Sell_OrderOutHouseBacksService OrdersSer = new Sell_OrderOutHouseBacksService(); TB_HouseGoodsService houseGoodsSer = new TB_HouseGoodsService(); try { objCommand.Parameters.Clear(); tb_EFormService eformSer = new tb_EFormService(); string proNo = eformSer.GetAllE_No("Sell_OrderOutHouseBack", objCommand); model.ProNo = proNo; eform.E_No = proNo; model.Status = eform.state; id = Add(model, objCommand); MainId = id; eform.allE_id = id; eformSer.Add(eform, objCommand); for (int i = 0; i < orders.Count; i++) { orders[i].id = id; OrdersSer.Add(orders[i], objCommand); } tan.Commit(); } catch (Exception) { tan.Rollback(); return(0); } return(id); } }
/// <summary> /// 得到一个对象实体 /// </summary> public VAN_OA.Model.JXC.Sell_OrderOutHouseBack GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" Sell_OrderOutHouseBack.Id,CreateUserId,CreateTime,BackTime,GuestName,BackType,SellProNo,ProNo,PONo,POName,Remark ,tb_User.loginName as CreateName,Status,SellTotal"); strSql.Append(" from Sell_OrderOutHouseBack left join tb_User on tb_User.id=CreateUserId "); strSql.Append(" where Sell_OrderOutHouseBack.Id=" + id + ""); VAN_OA.Model.JXC.Sell_OrderOutHouseBack model = null; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlCommand objCommand = new SqlCommand(strSql.ToString(), conn); using (SqlDataReader dataReader = objCommand.ExecuteReader()) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(VAN_OA.Model.JXC.Sell_OrderOutHouseBack model, SqlCommand objCommand) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.CreateUserId != null) { strSql1.Append("CreateUserId,"); strSql2.Append("" + model.CreateUserId + ","); } strSql1.Append("CreateTime,"); strSql2.Append("getdate(),"); if (model.BackTime != null) { strSql1.Append("BackTime,"); strSql2.Append("'" + model.BackTime + "',"); } if (model.GuestName != null) { strSql1.Append("GuestName,"); strSql2.Append("'" + model.GuestName + "',"); } if (model.BackType != null) { strSql1.Append("BackType,"); strSql2.Append("" + model.BackType + ","); } if (model.SellProNo != null) { strSql1.Append("SellProNo,"); strSql2.Append("'" + model.SellProNo + "',"); } if (model.ProNo != null) { strSql1.Append("ProNo,"); strSql2.Append("'" + model.ProNo + "',"); } if (model.PONo != null) { strSql1.Append("PONo,"); strSql2.Append("'" + model.PONo + "',"); } if (model.POName != null) { strSql1.Append("POName,"); strSql2.Append("'" + model.POName + "',"); } if (model.Remark != null) { strSql1.Append("Remark,"); strSql2.Append("'" + model.Remark + "',"); } if (model.Status != null) { strSql1.Append("Status,"); strSql2.Append("'" + model.Status + "',"); } if (model.SellTotal != null) { strSql1.Append("SellTotal,"); strSql2.Append("" + model.SellTotal + ","); } strSql.Append("insert into Sell_OrderOutHouseBack("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); int result; objCommand.CommandText = strSql.ToString(); object obj = objCommand.ExecuteScalar(); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }