/// <summary> /// 得到一个对象实体 /// </summary> public VAN_OA.Model.JXC.CAI_POOrder GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" IsMingYiCaiGou,CAI_POOrder.Id,CAI_POOrder.AppName,loginName,CAI_POOrder.CaiGou,CAI_POOrder.cRemark ,CAI_POOrder.fileName,CAI_POOrder.fileType ,CAI_POOrder.proNo,CAI_POOrder.PONo,BusType,Status,CG_ProNo,"); strSql.Append(" GuestNo,GuestName,AE,INSIDE,POName,PODate,POTotal,POPayStype"); strSql.Append(" from CAI_POOrder left join tb_User on tb_User.id=CAI_POOrder.AppName "); strSql.Append(" where CAI_POOrder.Id=" + id + ""); VAN_OA.Model.JXC.CAI_POOrder 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 VAN_OA.Model.JXC.CAI_POOrder GetModel_File(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" fileName,fileType,fileNo "); strSql.Append(" from CAI_POOrder "); strSql.Append(" where CAI_POOrder.Id=" + id + ""); VAN_OA.Model.JXC.CAI_POOrder 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 = new CAI_POOrder(); object ojb; ojb = dataReader["fileName"]; if (ojb != null && ojb != DBNull.Value) { model.fileName = ojb.ToString(); } ojb = dataReader["fileType"]; if (ojb != null && ojb != DBNull.Value) { model.fileType = ojb.ToString(); } ojb = dataReader["fileNo"]; if (ojb != null && ojb != DBNull.Value) { model.fileNo = (byte[])ojb; } } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(VAN_OA.Model.JXC.CAI_POOrder model, SqlCommand objCommand) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CAI_POOrder set "); //if (model.AppName != null) //{ // strSql.Append("AppName=" + model.AppName + ","); //} if (model.CaiGou != null) { strSql.Append("CaiGou='" + model.CaiGou + "',"); } if (model.cRemark != null) { strSql.Append("cRemark='" + model.cRemark + "',"); } else { strSql.Append("cRemark= null ,"); } if (model.Status != null) { strSql.Append("Status='" + model.Status + "',"); } if (model.Status != null && model.Status != "执行中") { strSql.Append("TrueCaiDate=getdate(),"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where Id=" + model.Id + ""); objCommand.CommandText = strSql.ToString(); objCommand.ExecuteNonQuery(); }
public bool updateTran(VAN_OA.Model.JXC.CAI_POOrder model, VAN_OA.Model.EFrom.tb_EForm eform, tb_EForms forms, List <CAI_POOrders> orders, string IDS, List <CAI_POCai> Cais, string CAI_IDS) { using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; CAI_POOrdersService OrdersSer = new CAI_POOrdersService(); CAI_POCaiService CaiSer = new CAI_POCaiService(); 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); //for (int i = 0; i < orders.Count; i++) //{ // orders[i].Id = model.Id; // //if (orders[i].IfUpdate == true && orders[i].Ids != 0) // //{ // OrdersSer.Update(orders[i], objCommand); // //} // //else if (orders[i].Ids == 0) // //{ // // OrdersSer.Add(orders[i], objCommand); // //} //} //if (IDS != "") //{ // IDS = IDS.Substring(0, IDS.Length - 1); // OrdersSer.DeleteByIds(IDS, objCommand); //} #region 采购 for (int i = 0; i < Cais.Count; i++) { Cais[i].Id = model.Id; if (Cais[i].IfUpdate == true && Cais[i].Ids != 0) { CaiSer.Update(Cais[i], objCommand); } else if (Cais[i].Ids == 0) { CaiSer.Add(Cais[i], objCommand); } } //if (CAI_IDS != "") //{ // CAI_IDS = CAI_IDS.Substring(0, CAI_IDS.Length - 1); // CaiSer.DeleteByIds(CAI_IDS, objCommand); //} #endregion tan.Commit(); } catch (Exception) { tan.Rollback(); return(false); } } return(true); }
/// <summary> /// 对象实体绑定数据 /// </summary> public VAN_OA.Model.JXC.CAI_POOrder ReaderBind(IDataReader dataReader) { VAN_OA.Model.JXC.CAI_POOrder model = new VAN_OA.Model.JXC.CAI_POOrder(); object ojb; model.IsMingYiCaiGou = (bool)dataReader["IsMingYiCaiGou"]; ojb = dataReader["Id"]; if (ojb != null && ojb != DBNull.Value) { model.Id = (int)ojb; } ojb = dataReader["AppName"]; if (ojb != null && ojb != DBNull.Value) { model.AppName = (int)ojb; } ojb = dataReader["loginName"]; if (ojb != null && ojb != DBNull.Value) { model.LoginName = ojb.ToString(); } ojb = dataReader["CaiGou"]; if (ojb != null && ojb != DBNull.Value) { model.CaiGou = ojb.ToString(); } try { model.cRemark = dataReader["cRemark"].ToString(); } catch (Exception) { } ojb = dataReader["fileName"]; if (ojb != null && ojb != DBNull.Value) { model.fileName = ojb.ToString(); } ojb = dataReader["fileType"]; if (ojb != null && ojb != DBNull.Value) { model.fileType = ojb.ToString(); } ojb = dataReader["ProNo"]; if (ojb != null && ojb != DBNull.Value) { model.ProNo = ojb.ToString(); } model.PONo = dataReader["PONo"].ToString(); model.BusType = dataReader["BusType"].ToString(); ojb = dataReader["GuestNo"]; if (ojb != null && ojb != DBNull.Value) { model.GuestNo = ojb.ToString(); } ojb = dataReader["GuestName"]; if (ojb != null && ojb != DBNull.Value) { model.GuestName = ojb.ToString(); } ojb = dataReader["AE"]; if (ojb != null && ojb != DBNull.Value) { model.AE = ojb.ToString(); } ojb = dataReader["INSIDE"]; if (ojb != null && ojb != DBNull.Value) { model.INSIDE = ojb.ToString(); } ojb = dataReader["POName"]; if (ojb != null && ojb != DBNull.Value) { model.POName = ojb.ToString(); } ojb = dataReader["PODate"]; if (ojb != null && ojb != DBNull.Value) { model.PODate = Convert.ToDateTime(ojb); } ojb = dataReader["POTotal"]; if (ojb != null && ojb != DBNull.Value) { model.POTotal = Convert.ToDecimal(ojb); } ojb = dataReader["POPayStype"]; if (ojb != null && ojb != DBNull.Value) { model.POPayStype = ojb.ToString(); } ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = ojb.ToString(); } ojb = dataReader["CG_ProNo"]; if (ojb != null && ojb != DBNull.Value) { model.CG_ProNo = ojb.ToString(); } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(VAN_OA.Model.JXC.CAI_POOrder model, SqlCommand objCommand) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.AppName != null) { strSql1.Append("AppName,"); strSql2.Append("" + model.AppName + ","); } if (model.CaiGou != null) { strSql1.Append("CaiGou,"); strSql2.Append("'" + model.CaiGou + "',"); } if (model.cRemark != null) { strSql1.Append("cRemark,"); strSql2.Append("'" + model.cRemark + "',"); } if (model.fileName != null) { strSql1.Append("fileName,"); strSql2.Append("'" + model.fileName + "',"); } if (model.fileNo != null) { strSql1.Append("fileNo,"); strSql2.Append("@fileNo,"); SqlParameter pp = new System.Data.SqlClient.SqlParameter("@fileNo", System.Data.SqlDbType.Image, model.fileNo.Length); pp.Value = model.fileNo; objCommand.Parameters.Add(pp); } if (model.fileType != null) { strSql1.Append("fileType,"); strSql2.Append("'" + model.fileType + "',"); } if (model.BusType == "1") { //项目编号 string MaxCardNo = ""; string sql = string.Format("select right('0000000000'+(convert(varchar,(convert(int,right(max(PONo),5))+1))),5) FROM CAI_POOrder where PONo like 'KC{0}%'", DateTime.Now.Year); objCommand.CommandText = sql.ToString(); object objMax = objCommand.ExecuteScalar(); if (objMax != null && objMax.ToString() != "") { MaxCardNo = "KC" + DateTime.Now.Year.ToString() + objMax.ToString(); } else { MaxCardNo = "KC" + DateTime.Now.Year.ToString() + "00001"; } strSql1.Append("PONo,"); strSql2.Append("'" + MaxCardNo + "',"); } else { strSql1.Append("PONo,"); strSql2.Append("'" + model.PONo + "',"); } if (model.ProNo != null) { strSql1.Append("ProNo,"); strSql2.Append("'" + model.ProNo + "',"); } if (model.BusType != null) { strSql1.Append("BusType,"); strSql2.Append("'" + model.BusType + "',"); } if (model.POName != null) { strSql1.Append("POName,"); strSql2.Append("'" + model.POName + "',"); } if (model.PODate != null) { strSql1.Append("PODate,"); strSql2.Append("'" + model.PODate + "',"); } if (model.POPayStype != null) { strSql1.Append("POPayStype,"); strSql2.Append("'" + model.POPayStype + "',"); } if (model.POTotal != null) { strSql1.Append("POTotal,"); strSql2.Append("" + model.POTotal + ","); } if (model.GuestName != null) { strSql1.Append("GuestName,"); strSql2.Append("'" + model.GuestName + "',"); } if (model.AE != null) { strSql1.Append("AE,"); strSql2.Append("'" + model.AE + "',"); } if (model.INSIDE != null) { strSql1.Append("INSIDE,"); strSql2.Append("'" + model.INSIDE + "',"); } if (model.GuestNo != null) { strSql1.Append("GuestNo,"); strSql2.Append("'" + model.GuestNo + "',"); } if (model.Status != null) { strSql1.Append("Status,"); strSql2.Append("'" + model.Status + "',"); } if (model.CG_ProNo != null) { strSql1.Append("CG_ProNo,"); strSql2.Append("'" + model.CG_ProNo + "',"); } strSql1.Append("TrueCaiDate,"); strSql2.Append("getdate(),"); strSql1.Append("IsMingYiCaiGou,"); strSql2.AppendFormat("{0},", (model.IsMingYiCaiGou?1:0)); strSql.Append("insert into CAI_POOrder("); 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); }
public int addTran(VAN_OA.Model.JXC.CAI_POOrder model, VAN_OA.Model.EFrom.tb_EForm eform, List <CAI_POOrders> orders, List <CAI_POCai> caiOrders, out int MainId, bool isCopy = false) { CG_POCaiService poCaiSer = new CG_POCaiService(); var caiList = poCaiSer.GetCaiList(model.CG_ProNo); int id = 0; MainId = 0; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; CAI_POOrdersService OrdersSer = new CAI_POOrdersService(); CAI_POCaiService caiSer = new CAI_POCaiService(); try { objCommand.Parameters.Clear(); tb_EFormService eformSer = new tb_EFormService(); string proNo = eformSer.GetAllE_No("CAI_POOrder", 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); if (isCopy == false) { CAI_POCai cai = new CAI_POCai(); cai.GuestName = orders[i].GuestName; cai.Num = orders[i].Num; cai.InvName = orders[i].InvName; cai.Id = id; cai.GoodId = orders[i].GoodId; var pocaiModel = caiList.Find(p => p.GoodId == orders[i].GoodId); if (pocaiModel != null) { cai.FinPrice1 = pocaiModel.FinPrice1; cai.FinPrice2 = pocaiModel.FinPrice2; cai.FinPrice3 = pocaiModel.FinPrice3; cai.SupperPrice = pocaiModel.SupperPrice; cai.SupperPrice1 = pocaiModel.SupperPrice1; cai.SupperPrice2 = pocaiModel.SupperPrice2; cai.Supplier = pocaiModel.Supplier; cai.Supplier1 = pocaiModel.Supplier1; cai.Supplier2 = pocaiModel.Supplier2; } caiSer.Add(cai, objCommand); } else { var pocaiModel = caiOrders.Find(p => p.GoodId == orders[i].GoodId); pocaiModel.GuestName = orders[i].GuestName; pocaiModel.Num = orders[i].Num; pocaiModel.InvName = orders[i].InvName; pocaiModel.Id = id; caiSer.Add(pocaiModel, objCommand); } } tan.Commit(); } catch (Exception) { tan.Rollback(); return(0); } return(id); } }