Пример #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(LPWeb.Model.ContactBranches model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ContactBranches set ");
            //strSql.Append("ContactBranchId=@ContactBranchId,");
            strSql.Append("ContactCompanyId=@ContactCompanyId,");
            strSql.Append("Name=@Name,");
            strSql.Append("Enabled=@Enabled,");
            strSql.Append("Address=@Address,");
            strSql.Append("City=@City,");
            strSql.Append("State=@State,");
            strSql.Append("Zip=@Zip,");
            strSql.Append("Phone=@Phone,");
            strSql.Append("Fax=@Fax,");
            strSql.Append("PrimaryContact=@PrimaryContact,");
            strSql.Append("Modified=@Modified,");
            strSql.Append("ModifiedBy=@ModifiedBy");
            strSql.Append(" where ContactBranchId=@ContactBranchId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ContactBranchId",  SqlDbType.Int,         4),
                new SqlParameter("@ContactCompanyId", SqlDbType.Int,         4),
                new SqlParameter("@Name",             SqlDbType.NVarChar,  255),
                new SqlParameter("@Enabled",          SqlDbType.Bit,         1),
                new SqlParameter("@Address",          SqlDbType.NVarChar,  255),
                new SqlParameter("@City",             SqlDbType.NVarChar,   50),
                new SqlParameter("@State",            SqlDbType.NVarChar,    2),
                new SqlParameter("@Zip",              SqlDbType.NVarChar,   12),
                new SqlParameter("@Phone",            SqlDbType.NVarChar,   20),
                new SqlParameter("@Fax",              SqlDbType.NVarChar,   20),
                new SqlParameter("@PrimaryContact",   SqlDbType.Int,         4),
                new SqlParameter("@Modified",         SqlDbType.DateTime),
                new SqlParameter("@ModifiedBy",       SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.ContactBranchId;
            parameters[1].Value  = model.ContactCompanyId;
            parameters[2].Value  = model.Name;
            parameters[3].Value  = model.Enabled;
            parameters[4].Value  = model.Address;
            parameters[5].Value  = model.City;
            parameters[6].Value  = model.State;
            parameters[7].Value  = model.Zip;
            parameters[8].Value  = model.Phone;
            parameters[9].Value  = model.Fax;
            parameters[10].Value = model.PrimaryContact;
            parameters[11].Value = model.Modified;
            parameters[12].Value = model.ModifiedBy;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LPWeb.Model.ContactBranches model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ContactBranches(");
            strSql.Append("ContactCompanyId,Name,Enabled,Address,City,State,Zip,Phone,Fax,PrimaryContact,Modified,ModifiedBy)");
            strSql.Append(" values (");
            strSql.Append("@ContactCompanyId,@Name,@Enabled,@Address,@City,@State,@Zip,@Phone,@Fax,@PrimaryContact,@Modified,@ModifiedBy)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ContactCompanyId", SqlDbType.Int,         4),
                new SqlParameter("@Name",             SqlDbType.NVarChar,  255),
                new SqlParameter("@Enabled",          SqlDbType.Bit,         1),
                new SqlParameter("@Address",          SqlDbType.NVarChar,  255),
                new SqlParameter("@City",             SqlDbType.NVarChar,   50),
                new SqlParameter("@State",            SqlDbType.NVarChar,    2),
                new SqlParameter("@Zip",              SqlDbType.NVarChar,   12),
                new SqlParameter("@Phone",            SqlDbType.NVarChar,   20),
                new SqlParameter("@Fax",              SqlDbType.NVarChar,   20),
                new SqlParameter("@PrimaryContact",   SqlDbType.Int,         4),
                new SqlParameter("@Modified",         SqlDbType.DateTime),
                new SqlParameter("@ModifiedBy",       SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.ContactCompanyId;
            parameters[1].Value  = model.Name;
            parameters[2].Value  = model.Enabled;
            parameters[3].Value  = model.Address;
            parameters[4].Value  = model.City;
            parameters[5].Value  = model.State;
            parameters[6].Value  = model.Zip;
            parameters[7].Value  = model.Phone;
            parameters[8].Value  = model.Fax;
            parameters[9].Value  = model.PrimaryContact;
            parameters[10].Value = model.Modified;
            parameters[11].Value = model.ModifiedBy;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LPWeb.Model.ContactBranches GetModel(int ContactBranchId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ContactBranchId,ContactCompanyId,Name,Enabled,Address,City,State,Zip,Phone,Fax,PrimaryContact,Modified,ModifiedBy from ContactBranches ");
            strSql.Append(" where ContactBranchId=@ContactBranchId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ContactBranchId", SqlDbType.Int, 4)
            };
            parameters[0].Value = ContactBranchId;

            LPWeb.Model.ContactBranches model = new LPWeb.Model.ContactBranches();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ContactBranchId"].ToString() != "")
                {
                    model.ContactBranchId = int.Parse(ds.Tables[0].Rows[0]["ContactBranchId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ContactCompanyId"].ToString() != "")
                {
                    model.ContactCompanyId = int.Parse(ds.Tables[0].Rows[0]["ContactCompanyId"].ToString());
                }
                model.Name = ds.Tables[0].Rows[0]["Name"].ToString();
                if (ds.Tables[0].Rows[0]["Enabled"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Enabled"].ToString() == "1") || (ds.Tables[0].Rows[0]["Enabled"].ToString().ToLower() == "true"))
                    {
                        model.Enabled = true;
                    }
                    else
                    {
                        model.Enabled = false;
                    }
                }
                model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                model.City    = ds.Tables[0].Rows[0]["City"].ToString();
                model.State   = ds.Tables[0].Rows[0]["State"].ToString();
                model.Zip     = ds.Tables[0].Rows[0]["Zip"].ToString();
                model.Phone   = ds.Tables[0].Rows[0]["Phone"].ToString();
                model.Fax     = ds.Tables[0].Rows[0]["Fax"].ToString();
                if (ds.Tables[0].Rows[0]["PrimaryContact"].ToString() != "")
                {
                    model.PrimaryContact = int.Parse(ds.Tables[0].Rows[0]["PrimaryContact"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Modified"].ToString() != "")
                {
                    model.Modified = DateTime.Parse(ds.Tables[0].Rows[0]["Modified"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ModifiedBy"].ToString() != "")
                {
                    model.ModifiedBy = int.Parse(ds.Tables[0].Rows[0]["ModifiedBy"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }