public bool updateTran(VAN_OA.Model.EFrom.Tb_ProjectInv model, VAN_OA.Model.EFrom.tb_EForm eform, tb_EForms forms, List <Tb_ProjectInvs> proInvs, string IDS)
        {
            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;


                Tb_ProjectInvsService prosInvsSer = new Tb_ProjectInvsService();
                try
                {
                    objCommand.Parameters.Clear();
                    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 < proInvs.Count; i++)
                    {
                        proInvs[i].PId = model.Id;

                        if (proInvs[i].IfUpdate == true && proInvs[i].Id != 0)
                        {
                            prosInvsSer.Update(proInvs[i], objCommand);
                        }
                        else if (proInvs[i].Id == 0)
                        {
                            prosInvsSer.Add(proInvs[i], objCommand);
                        }
                    }
                    if (IDS != "")
                    {
                        IDS = IDS.Substring(0, IDS.Length - 1);
                        prosInvsSer.DeleteByIds(IDS, objCommand);
                    }

                    tan.Commit();
                }
                catch (Exception)
                {
                    tan.Rollback();
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public VAN_OA.Model.EFrom.Tb_ProjectInv ReaderBind(IDataReader dataReader)
        {
            VAN_OA.Model.EFrom.Tb_ProjectInv model = new VAN_OA.Model.EFrom.Tb_ProjectInv();
            object ojb;

            ojb = dataReader["Id"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Id = (int)ojb;
            }
            ojb = dataReader["UserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserId = (int)ojb;
            }
            ojb = dataReader["CreateTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateTime = (DateTime)ojb;
            }
            model.ProNo   = dataReader["ProNo"].ToString();
            model.ProName = dataReader["ProName"].ToString();

            ojb = dataReader["loginName"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LoginName = ojb.ToString();
            }
            ojb = dataReader["State"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.State = ojb.ToString();
            }

            ojb = dataReader["GuestId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.GuestId = Convert.ToInt32(ojb);
            }

            return(model);
        }
        public int addTran(VAN_OA.Model.EFrom.Tb_ProjectInv model, VAN_OA.Model.EFrom.tb_EForm eform, List <Tb_ProjectInvs> proInvs)
        {
            int id     = 0;
            int MainId = 0;

            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;
                Tb_ProjectInvsService proInvsSer = new Tb_ProjectInvsService();
                try
                {
                    tb_EFormService eformSer = new tb_EFormService();
                    objCommand.Parameters.Clear();
                    string proNo = eformSer.GetAllE_No("Tb_ProjectInv", objCommand);
                    model.ProNo = proNo;
                    eform.E_No  = proNo;

                    id     = Add(model, objCommand);
                    MainId = id;

                    eform.allE_id = id;
                    eformSer.Add(eform, objCommand);
                    for (int i = 0; i < proInvs.Count; i++)
                    {
                        proInvs[i].PId = id;
                        proInvsSer.Add(proInvs[i], objCommand);
                    }
                    tan.Commit();
                }
                catch (Exception)
                {
                    tan.Rollback();
                    return(0);
                }
                return(id);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public VAN_OA.Model.EFrom.Tb_ProjectInv GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select   ");
            strSql.Append(" Tb_ProjectInv.Id,UserId,CreateTime,ProNo,ProName,loginName,State,GuestId ");
            strSql.Append(" from Tb_ProjectInv left join tb_User on tb_User.id=Tb_ProjectInv.UserId");
            strSql.Append(" where Tb_ProjectInv.Id=" + id + "");

            VAN_OA.Model.EFrom.Tb_ProjectInv 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 void Update(VAN_OA.Model.EFrom.Tb_ProjectInv model, SqlCommand objCommand)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tb_ProjectInv set ");

            if (model.CreateTime != null)
            {
                strSql.Append("CreateTime='" + model.CreateTime + "',");
            }
            else
            {
                strSql.Append("CreateTime= null ,");
            }

            if (model.ProName != null)
            {
                strSql.Append("ProName='" + model.ProName + "',");
            }
            else
            {
                strSql.Append("ProName= null ,");
            }

            strSql.Append("State='" + model.State + "',");
            strSql.Append("GuestId=" + model.GuestId + ",");

            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where Id=" + model.Id + "");


            objCommand.CommandText = strSql.ToString();
            objCommand.ExecuteNonQuery();
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(VAN_OA.Model.EFrom.Tb_ProjectInv model, SqlCommand objCommand)
        {
            //string MaxCardNo = "";
            //string sql = "select  right('0000000000'+(convert(varchar,(convert(int,right(max(ProNo),4))+1))),4) FROM  Tb_ProjectInv;";
            //objCommand.CommandText = sql.ToString();
            //object objMax = objCommand.ExecuteScalar();
            //if (objMax != null && objMax.ToString() != "")
            //{
            //    MaxCardNo = DateTime.Now.Year.ToString() + objMax.ToString();
            //}
            //else
            //{
            //    MaxCardNo = DateTime.Now.Year.ToString() + "0001";
            //}


            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.UserId != null)
            {
                strSql1.Append("UserId,");
                strSql2.Append("" + model.UserId + ",");
            }

            if (model.CreateTime != null)
            {
                strSql1.Append("CreateTime,");
                strSql2.Append("'" + model.CreateTime + "',");
            }
            if (model.ProNo != "")
            {
                strSql1.Append("ProNo,");
                strSql2.Append("'" + model.ProNo + "',");
            }
            if (model.ProName != null)
            {
                strSql1.Append("ProName,");
                strSql2.Append("'" + model.ProName + "',");
            }

            strSql1.Append("State,");
            strSql2.Append("'" + model.State + "',");

            strSql1.Append("GuestId,");
            strSql2.Append("" + model.GuestId + ",");


            strSql.Append("insert into Tb_ProjectInv(");
            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);
        }