/// <summary> /// 删除数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Delete(PolicyReceiver entity) { string sql = "DELETE FROM tb_policy_receiver WHERE policy_sequence=@policy_sequence and receiver=@receiver and type=@type"; using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) { mycn.Open(); MySqlCommand command = new MySqlCommand(sql, mycn); command.Parameters.AddWithValue("@policy_sequence", entity.policySequence); command.Parameters.AddWithValue("@receiver", entity.receiver); command.Parameters.AddWithValue("@type", entity.type); 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(PolicyReceiver entity) { string sql = "INSERT INTO tb_policy_receiver (policy_sequence,receiver,type) VALUE (@policy_sequence,@receiver,@type)"; using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) { mycn.Open(); MySqlCommand command = new MySqlCommand(sql, mycn); command.Parameters.AddWithValue("@policy_sequence", entity.policySequence); command.Parameters.AddWithValue("@receiver", entity.receiver); command.Parameters.AddWithValue("@type", entity.type); int i = command.ExecuteNonQuery(); mycn.Close(); mycn.Dispose(); return i; } }
/// <summary> /// 修改数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Update(PolicyReceiver entity) { string sql = "UPDATE tb_policy_receiver SET policy_sequence=@policy_sequence,receiver=@receiver where policy_sequence=@policy_sequence and type=@type"; //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("@policy_sequence", entity.policySequence); command.Parameters.AddWithValue("@receiver", entity.receiver); command.Parameters.AddWithValue("@type", entity.type); int i = command.ExecuteNonQuery(); mycn.Close(); mycn.Dispose(); return i; } }
private void btnSave_Click(object sender, EventArgs e) { //MessageBox.Show(this.lstAgentType.CheckedItems.Count.ToString()); //return; if (String.IsNullOrEmpty(this.cbType.Text.Trim())) { MessageBox.Show("请选择类型!"); this.txtSubject.Focus(); return; } if (String.IsNullOrEmpty(this.txtSubject.Text.Trim())) { MessageBox.Show("请输入名称!"); this.txtSubject.Focus(); return; } if (String.IsNullOrEmpty(this.txtContent.Text.Trim())) { MessageBox.Show("请输入内容!"); this.txtContent.Focus(); return; } if (this.dtEndDate.Value.CompareTo(this.dtStartDate.Value) <= 0) { MessageBox.Show("有效期结束时间必须大于开始时间"); return; } this.Cursor = Cursors.WaitCursor; Policy policy = new Policy(); policy.sequence = this.txtSequence.Text.Trim(); policy.type = this.cbType.Text; policy.subject = this.txtSubject.Text.Trim(); policy.content = this.txtContent.Text.Trim(); policy.sender = this.loginUser.name; policy.validateStartTime = this.dtStartDate.Value.ToString("yyyy-MM-dd"); policy.validateEndTime = this.dtEndDate.Value.ToString("yyyy-MM-dd"); policy.creatTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); policy.isDelete = "N"; policy.isValidate = "Y"; policy.agentType = ""; foreach (object item in this.chkAgentType.CheckedItems) { policy.agentType = policy.agentType + item.ToString()+";"; } // policy.agentType = this.cboAgentType.Text; if (this.lstAgentType.CheckedItems.Contains("所有渠道")) { policy.toAll = "Y"; } else { policy.toAll = "N"; } byte[] b = new byte[0]; String fullpath = this.txtAttachmentLocation.Text; if (!String.IsNullOrEmpty(fullpath)) { FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read); byte[] attachmentBytes = new byte[fs.Length]; fs.Read(attachmentBytes, 0, System.Convert.ToInt32(fs.Length)); // BinaryReader br = new BinaryReader(fs); // attachmentBytes = br.ReadBytes(Convert.ToInt32(fs.Length)); fs.Close(); // br.Close(); if (attachmentBytes.Length > 0) { policy.attachmentName = this.txtAttachmentName.Text; policy.attachment = attachmentBytes; } } else { if (!String.IsNullOrEmpty(policy.sequence)) { Policy tempPolicy = this.policyDao.Get(Int32.Parse(policy.sequence)); policy.attachment = tempPolicy.attachment; policy.attachmentName = tempPolicy.attachmentName; } } if (!String.IsNullOrEmpty(policy.sequence)) { this.policyDao.Update(policy); } else { policyDao.Add(policy); policy = policyDao.GetBySubject(policy.subject); } policyReceiverDao.Delete(policy.sequence); for (int i = 0; i < lstAgentType.Items.Count; i++) { if (lstAgentType.GetItemChecked(i)) { PolicyReceiver policyReceiver = new PolicyReceiver(); policyReceiver.policySequence = policy.sequence; policyReceiver.receiver = lstAgentType.Items[i].ToString(); policyReceiver.type = "渠道类型"; policyReceiverDao.Add(policyReceiver); } } for (int i = 0; i < lstGroup.Items.Count; i++) { if (lstGroup.GetItemChecked(i)) { PolicyReceiver policyReceiver = new PolicyReceiver(); policyReceiver.policySequence = policy.sequence; policyReceiver.receiver = lstGroup.Items[i].ToString(); policyReceiver.type = "自定义组"; policyReceiverDao.Add(policyReceiver); } } this.prepareGrid(this.txtSearchCondition.Text); MessageBox.Show("操作完成"); this.Cursor = Cursors.Default; }
/// <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<PolicyReceiver> GetList(String policySequence) { string sql = "SELECT policy_sequence,receiver,type FROM tb_policy_receiver where policy_Sequence=@policy_Sequence"; using (MySqlConnection mycn = new MySqlConnection(mysqlConnection)) { mycn.Open(); MySqlCommand command = new MySqlCommand(sql, mycn); command.Parameters.AddWithValue("@policy_Sequence", policySequence); MySqlDataReader reader = command.ExecuteReader(); IList<PolicyReceiver> list = new List<PolicyReceiver>(); PolicyReceiver policyReceiver = null; while (reader.Read()) { policyReceiver = new PolicyReceiver(); policyReceiver.policySequence = reader["policy_sequence"] == DBNull.Value ? null : reader["policy_sequence"].ToString(); policyReceiver.receiver = reader["receiver"] == DBNull.Value ? null : reader["receiver"].ToString(); policyReceiver.type = reader["type"] == DBNull.Value ? null : reader["type"].ToString(); list.Add(policyReceiver); } mycn.Close(); return list; } }