/// <summary> /// 得到一个对象实体 /// </summary> public ECommerce.Admin.Model.SWCompany DataRowToModel(DataRow row) { ECommerce.Admin.Model.SWCompany model = new ECommerce.Admin.Model.SWCompany(); if (row != null) { if (row["SWOrgId"] != null && row["SWOrgId"].ToString() != "") { model.SWOrgId = Convert.ToInt32(row["SWOrgId"].ToString()); } if (row["COrgId"] != null && row["COrgId"].ToString() != "") { model.COrgId = Convert.ToInt32(row["COrgId"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public ECommerce.Admin.Model.SWCompany DataRowToModel(DataRow row) { ECommerce.Admin.Model.SWCompany model = new ECommerce.Admin.Model.SWCompany(); if (row != null) { if (row["SWOrgId"] != null && row["SWOrgId"].ToString() != "") { model.SWOrgId = Convert.ToInt32(row["SWOrgId"].ToString()); } if (row["COrgId"] != null && row["COrgId"].ToString() != "") { model.COrgId = Convert.ToInt32(row["COrgId"].ToString()); } } return model; }
/// <summary> /// 对象实体绑定数据 /// </summary> public ECommerce.Admin.Model.SWCompany ReaderBind(IDataReader dataReader) { ECommerce.Admin.Model.SWCompany model = new ECommerce.Admin.Model.SWCompany(); object ojb; ojb = dataReader["SWOrgId"]; if (ojb != null && ojb != DBNull.Value) { model.SWOrgId = Convert.ToInt32(ojb); } ojb = dataReader["COrgId"]; if (ojb != null && ojb != DBNull.Value) { model.COrgId = Convert.ToInt32(ojb); } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public ECommerce.Admin.Model.SWCompany GetModelBySWOrgId(string orgId) { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select SWOrgId,COrgId from SWCompany "); strSql.Append(" where SWOrgId=" + orgId + ""); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); ECommerce.Admin.Model.SWCompany model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ECommerce.Admin.Model.SWCompany model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SWCompany("); strSql.Append("SWOrgId,COrgId)"); strSql.Append(" values ("); strSql.Append("@SWOrgId,@COrgId)"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "SWOrgId", DbType.Int32, model.SWOrgId); db.AddInParameter(dbCommand, "COrgId", DbType.Int32, model.COrgId); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(false); } return(true); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ECommerce.Admin.Model.SWCompany model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SWCompany set "); strSql.Append("SWOrgId=@SWOrgId,"); strSql.Append("COrgId=@COrgId"); strSql.Append(" where "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "SWOrgId", DbType.Int32, model.SWOrgId); db.AddInParameter(dbCommand, "COrgId", DbType.Int32, model.COrgId); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 对象实体绑定数据 /// </summary> public ECommerce.Admin.Model.SWCompany ReaderBind(IDataReader dataReader) { ECommerce.Admin.Model.SWCompany model = new ECommerce.Admin.Model.SWCompany(); object ojb; ojb = dataReader["SWOrgId"]; if (ojb != null && ojb != DBNull.Value) { model.SWOrgId = Convert.ToInt32(ojb); } ojb = dataReader["COrgId"]; if (ojb != null && ojb != DBNull.Value) { model.COrgId = Convert.ToInt32(ojb); } return model; }
/// <summary> /// 更新工作站事务方法 /// </summary> /// <param name="dt">dataTable</param> /// <returns></returns> public bool UpDateOrgWorStaTran(DataTable dt, string orgId) { StringBuilder strSql = new StringBuilder(); strSql.Append("update OrgOrganize set "); strSql.Append("OrgName=@OrgName,"); strSql.Append("OrgAddress=@OrgAddress,"); strSql.Append("OrgPhone=@OrgPhone,"); strSql.Append("OrgFax=@OrgFax,"); strSql.Append("OrgType=@OrgType,"); strSql.Append("OrgParentId=@OrgParentId "); strSql.Append(" where OrgId=@OrgId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "OrgId", DbType.Int64, dt.Rows[0]["OrgId"]); db.AddInParameter(dbCommand, "OrgName", DbType.String, dt.Rows[0]["OrgName"]); db.AddInParameter(dbCommand, "OrgAddress", DbType.String, dt.Rows[0]["OrgAddress"]); db.AddInParameter(dbCommand, "OrgPhone", DbType.AnsiString, dt.Rows[0]["OrgPhone"]); db.AddInParameter(dbCommand, "OrgFax", DbType.AnsiString, dt.Rows[0]["OrgFax"]); db.AddInParameter(dbCommand, "OrgType", DbType.Byte, dt.Rows[0]["OrgType"]); db.AddInParameter(dbCommand, "OrgParentId", DbType.Int64, dt.Rows[0]["OrgParentId"]); bool result = false; using (DbConnection conn = db.CreateConnection()) { conn.Open(); DbTransaction trans = conn.BeginTransaction(); try { db.ExecuteNonQuery(dbCommand, trans); StringBuilder strSql2 = new StringBuilder(); strSql2.Append("update OrgWorkStation set "); strSql2.Append("Size=@Size,"); strSql2.Append("Area=@Area,"); strSql2.Append("Manager=@Manager,"); strSql2.Append("ManagerPhone=@ManagerPhone"); strSql2.Append(" where OrgId=@OrgId "); DbCommand dbCommand2 = db.GetSqlStringCommand(strSql2.ToString()); db.AddInParameter(dbCommand2, "OrgId", DbType.Int64, dt.Rows[0]["OrgId"]); db.AddInParameter(dbCommand2, "Size", DbType.String, dt.Rows[0]["Size"]); db.AddInParameter(dbCommand2, "Area", DbType.String, dt.Rows[0]["Area"]); db.AddInParameter(dbCommand2, "Manager", DbType.String, dt.Rows[0]["Manager"]); db.AddInParameter(dbCommand2, "ManagerPhone", DbType.AnsiString, dt.Rows[0]["ManagerPhone"]); db.ExecuteNonQuery(dbCommand2, trans); ECommerce.Admin.DAL.SWCompany swcDal = new SWCompany(); ECommerce.Admin.Model.SWCompany swcInfo = swcDal.GetModelBySWOrgId(dt.Rows[0]["OrgId"].ToString()); StringBuilder strSql3 = new StringBuilder(); if (swcInfo != null) { strSql3.Append("Update SWCompany set COrgId=@COrgId where SWOrgId=@SWOrgId"); DbCommand dbCommand3 = db.GetSqlStringCommand(strSql3.ToString()); db.AddInParameter(dbCommand3, "SWOrgId", DbType.Int32, dt.Rows[0]["OrgId"]); db.AddInParameter(dbCommand3, "COrgId", DbType.Int32, orgId); db.ExecuteScalar(dbCommand3, trans); } else { strSql3.Append("insert into SWCompany("); strSql3.Append("SWOrgId,COrgId)"); strSql3.Append(" values ("); strSql3.Append("@SWOrgId,@COrgId)"); DbCommand dbCommand3 = db.GetSqlStringCommand(strSql3.ToString()); db.AddInParameter(dbCommand3, "SWOrgId", DbType.Int32, dt.Rows[0]["OrgId"]); db.AddInParameter(dbCommand3, "COrgId", DbType.Int32, orgId); db.ExecuteScalar(dbCommand3, trans); } trans.Commit(); result = true; } catch { trans.Rollback(); } conn.Close(); return(result); } }