/// <summary> /// 删除数据 /// </summary> /// <param name="primaryKey"></param> /// <returns></returns> public int Delete(AgentTypeComment entity) { string sql = "DELETE FROM agent_type_comment WHERE agentType=@agentType and agentFeeMonth=@agentFeeMonth"; using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) { mycn.Open(); MySqlCommand command = new MySqlCommand(sql, mycn); command.Parameters.AddWithValue("@agentType", entity.agentType); command.Parameters.AddWithValue("@agentFeeMonth", entity.agentFeeMonth); int i = command.ExecuteNonQuery(); mycn.Close(); mycn.Dispose(); return i; } }
/// <summary> /// 修改数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Update(AgentTypeComment entity) { string sql = "UPDATE agent_type_comment SET agentTypeComment=@agentTypeComment,agentType=@agentType, agentFeeMonth=@agentFeeMonth where agentType=@agentType and agentFeeMonth=@agentFeeMonth "; //string sql = "UPDATE cimuser SET userNickName=@userNickName WHERE userid=@userid"; using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) { mycn.Open(); MySqlCommand command = new MySqlCommand(sql, mycn); command.Parameters.AddWithValue("@agentTypeComment", entity.agentTypeComment); command.Parameters.AddWithValue("@agentType", entity.agentType); command.Parameters.AddWithValue("@agentFeeMonth", entity.agentFeeMonth); int i = command.ExecuteNonQuery(); mycn.Close(); mycn.Dispose(); return i; } }
public const string mysqlConnection = DBConstant.mysqlConnection;//"User Id=root;Host=115.29.229.134;Database=chinaunion;password=c513324665;charset=utf8"; /// <summary> /// 添加数据 /// </summary> /// <returns></returns> public int Add(AgentTypeComment entity) { string sql = "INSERT INTO agent_type_comment (agentTypeComment,agentType,agentFeeMonth) VALUE (@agentTypeComment,@agentType,@agentFeeMonth)"; using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) { mycn.Open(); MySqlCommand command = new MySqlCommand(sql, mycn); command.Parameters.AddWithValue("@agentType", entity.agentType); command.Parameters.AddWithValue("@agentTypeComment", entity.agentTypeComment); command.Parameters.AddWithValue("@agentFeeMonth", entity.agentFeeMonth); int i = command.ExecuteNonQuery(); mycn.Close(); mycn.Dispose(); return i; } }
/// <summary> /// 根据主键查询 /// </summary> /// <param name="primaryKey"></param> /// <returns></returns> //public Agent Get(int primaryKey) //{ // string sql = "SELECT userid,userNickName FROM cimuser where userid=@userid"; // using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) // { // mycn.Open(); // MySqlCommand command = new MySqlCommand(sql, mycn); // command.Parameters.AddWithValue("@userid", primaryKey); // MySqlDataReader reader = command.ExecuteReader(); // Agent userBase = null; // if (reader.Read()) // { // userBase = new Agent(); // userBase.UserId = Convert.ToInt32(reader["userid"]); // userBase.UserNickName = reader["userNickName"] == DBNull.Value ? null : reader["userNickName"].ToString(); // } // return userBase; // } //} /// <summary> /// 查询集合 /// </summary> /// <returns></returns> public IList<AgentTypeComment> GetList(String agentFeeMonth) { string sql = "SELECT agentTypeComment,agentType,agentFeeMonth FROM agent_type_comment where agentFeeMonth=@agentFeeMonth"; using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) { mycn.Open(); MySqlCommand command = new MySqlCommand(sql, mycn); command.Parameters.AddWithValue("@agentFeeMonth", agentFeeMonth); MySqlDataReader reader = command.ExecuteReader(); IList<AgentTypeComment> list = new List<AgentTypeComment>(); AgentTypeComment agentTypeComment = null; while (reader.Read()) { agentTypeComment = new AgentTypeComment(); agentTypeComment.agentTypeComment = reader["agentTypeComment"] == DBNull.Value ? null : reader["agentTypeComment"].ToString(); agentTypeComment.agentType = reader["agentType"] == DBNull.Value ? null : reader["agentType"].ToString(); agentTypeComment.agentFeeMonth = reader["agentFeeMonth"] == DBNull.Value ? null : reader["agentFeeMonth"].ToString(); list.Add(agentTypeComment); } mycn.Close(); return list; } }
/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(5, "开始导入代理商类型...\r\n"); //导入代理商类型 AgentTypeDao agentTypeDao = new AgentTypeDao(); for (int i = 0; i < dgAgentType.RowCount; i++) { AgentType agentType = new AgentType(); agentType.agentNo = dgAgentType[0, i].Value.ToString(); agentType.agentType = dgAgentType[1, i].Value.ToString(); agentType.agentFeeMonth = this.dtFeeMonth.Value.ToString("yyyy-MM"); agentTypeDao.Delete(agentType); agentTypeDao.Add(agentType); } worker.ReportProgress(6, "导入代理商类型完成...\r\n"); worker.ReportProgress(7, "开始导入代理商类型说明...\r\n"); //导入代理商类型说明 AgentTypeCommentDao agentTypeCommentDao = new AgentTypeCommentDao(); for (int i = 0; i < dgAgentTypeComment.RowCount; i++) { AgentTypeComment agentTypeComment = new AgentTypeComment(); agentTypeComment.agentType = dgAgentTypeComment[0, i].Value.ToString(); agentTypeComment.agentTypeComment = dgAgentTypeComment[1, i].Value.ToString(); agentTypeComment.agentFeeMonth = this.dtFeeMonth.Value.ToString("yyyy-MM"); agentTypeCommentDao.Delete(agentTypeComment); agentTypeCommentDao.Add(agentTypeComment); } ImportLog importLog = new ChinaUnion_BO.ImportLog(); importLog.type="Agent"; importLog.import_month = this.dtFeeMonth.Value.ToString("yyyy-MM"); ImportLogDao importLogDao = new ChinaUnion_DataAccess.ImportLogDao(); importLogDao.Delete(importLog); importLogDao.Add(importLog); worker.ReportProgress(8, "导入代理商类型完成...\r\n"); //MessageBox.Show("数据上传完毕"); }