private void cbConfig_SelectedIndexChanged(object sender, EventArgs e) { Sp_config cfg = (Sp_config)cbConfig.SelectedItem; if (cfg == null) { return; } Sp_url[] spUrl = new Sp_urlDAL().GetAllData(cfg.Code); double[] arr = new double[50]; List <Sp_url> list = spUrl.ToList();//把数组转换成泛型类 for (int index = 0; index < list.Count; index++) { Sp_url oneUrl = list[index]; if (oneUrl.Code == UrlCode) { list.RemoveAt(index); break; } } //double[] newarr = list.ToArray();//再由泛型类转换成数组 cbUrl.DataSource = list; }
private void ShowDGV() { dgvShow.Rows.Clear(); Sp_config[] sp = new Sp_configDAL().GetAllData(); GlobalShare.SystemConfigs = sp.ToList <Sp_config>(); for (int i = 0; i < GlobalShare.SystemConfigs.Count; i++) { Sp_config config = GlobalShare.SystemConfigs[i]; addOneRow(config); } }
private Sp_config ToSp_config(DataRow row) { Sp_config op = new Sp_config(); op.Id = Convert.ToInt32(row["Id"]); op.TimeType = (string)row["TimeType"]; op.TimeSep = (string)row["TimeSep"]; op.EMail = (string)row["EMail"]; op.Mobile = (string)row["Mobile"]; op.Code = (string)row["Code"]; op.Name = (string)row["Name"]; op.Enable = (int)row["Enable"]; op.JobClassName = (string)row["JobClassName"]; return(op); }
public void Update(Sp_config ud) { MySqlConnection mycon = new MySqlConnection(); mycon.ConnectionString = url; string sql2 = string.Format("update sp_config set TimeType='" + ud.TimeType + "',TimeSep='" + ud.TimeSep + "',EMail='" + ud.EMail + "',Mobile='" + ud.Mobile + "',Code='" + ud.Code + "',Name='" + ud.Name + "',Enable='" + ud.Enable + "',JobClassName='" + ud.JobClassName + "' where Code ='" + ud.Code + "'"); MySqlCommand comm = new MySqlCommand(sql2, mycon); mycon.Open(); int result = comm.ExecuteNonQuery(); mycon.Close(); if (result > 0) { } }
public void Insert(Sp_config ud) { MySqlConnection mycon = new MySqlConnection(); mycon.ConnectionString = url; string sql2 = string.Format("INSERT into sp_config(TimeType,TimeSep,EMail,Mobile,Code,Name,Enable,JobClassName)values('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", new object[] { ud.Id, ud.TimeType, ud.TimeSep, ud.EMail, ud.Mobile, ud.Code, ud.Name, ud.Enable, ud.JobClassName }); MySqlCommand comm = new MySqlCommand(sql2, mycon); mycon.Open(); int result = comm.ExecuteNonQuery(); mycon.Close(); if (result > 0) { } }
public Sp_config[] GetAllData(string Code) { MySql.Data.MySqlClient.MySqlConnection mycon = new MySqlConnection(); mycon.ConnectionString = url; string sql2 = "select * from sp_config where Code = '" + Code + "'"; MySqlDataAdapter mda = new MySqlDataAdapter(sql2, mycon); DataSet ds = new DataSet(); mda.Fill(ds, "table1"); DataTable dt = ds.Tables[0]; mycon.Close(); Sp_config[] operators = new Sp_config[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { operators[i] = ToSp_config(dt.Rows[i]); } return(operators); }
private void updateRow(DataGridViewRow dataGridViewRow, Sp_config config) { //dataGridViewRow.Cells["编号"].Value = d; dataGridViewRow.Cells["时间方案"].Value = config.TimeType; dataGridViewRow.Cells["时间段"].Value = config.TimeSep; dataGridViewRow.Cells["邮箱"].Value = config.EMail; dataGridViewRow.Cells["手机号"].Value = config.Mobile; dataGridViewRow.Cells["唯一编码"].Value = config.Code; dataGridViewRow.Cells["配置名称"].Value = config.Name; if (config.Enable == 1) { dataGridViewRow.Cells["是否生效"].Value = "是"; } else { dataGridViewRow.Cells["是否生效"].Value = "否"; } dataGridViewRow.Cells["工作类名字"].Value = config.JobClassName; dataGridViewRow.Cells["Id"].Value = config.Id; }
private void addOneRow(Sp_config config) { int d = dgvShow.Rows.Add(); dgvShow.Rows[d].Cells["编号"].Value = d; dgvShow.Rows[d].Cells["时间方案"].Value = config.TimeType; dgvShow.Rows[d].Cells["时间段"].Value = config.TimeSep; dgvShow.Rows[d].Cells["邮箱"].Value = config.EMail; dgvShow.Rows[d].Cells["手机号"].Value = config.Mobile; dgvShow.Rows[d].Cells["唯一编码"].Value = config.Code; dgvShow.Rows[d].Cells["配置名称"].Value = config.Name; if (config.Enable == 1) { dgvShow.Rows[d].Cells["是否生效"].Value = "是"; } else { dgvShow.Rows[d].Cells["是否生效"].Value = "否"; } dgvShow.Rows[d].Cells["工作类名字"].Value = config.JobClassName; dgvShow.Rows[d].Cells["Id"].Value = config.Id; }
private void btnAdd_Click(object sender, EventArgs e) { if (cBoxTimeType.Text == "定时") { if (txtTimeOne.Text.Trim() == "" || txtTimeTwo.Text.Trim() == "") { MessageBox.Show("时间段为必填项!"); return; } } else { if (!cBoxOne.Checked && !cBoxTwo.Checked && !cBoxThree.Checked && !cBoxFour.Checked && !cBoxFive.Checked && !cBoxSix.Checked && !cBoxSeven.Checked) { MessageBox.Show("请至少选择一天!"); return; } if (txtTimeThree.Text.Trim() == "" || txtTimeFour.Text.Trim() == "") { MessageBox.Show("时间段为必填项!"); return; } } if (txtEMail.Text.Trim() == "" || txtMobile.Text.Trim() == "" || txtName.Text.Trim() == "" || txtJobClassName.Text.Trim() == "") { MessageBox.Show("邮箱电话等信息为必填项!"); return; } Sp_config sp = new Sp_config(); //Sp_config[] spAll = new Sp_configDAL().GetAllData(); //sp.Id = spAll.Length + 1; if (cBoxTimeType.Text == "定时") { sp.TimeType = "0000000"; sp.TimeSep = txtTimeOne.Text.Trim() + "~" + txtTimeTwo.Text.Trim(); } else { string[] txt = new string[7] { "0", "0", "0", "0", "0", "0", "0" }; #region MyRegion if (cBoxOne.Checked) { txt[0] = "1"; } if (cBoxTwo.Checked) { txt[1] = "1"; } if (cBoxThree.Checked) { txt[2] = "1"; } if (cBoxFour.Checked) { txt[3] = "1"; } if (cBoxFive.Checked) { txt[4] = "1"; } if (cBoxSix.Checked) { txt[5] = "1"; } if (cBoxSeven.Checked) { txt[6] = "1"; } #endregion sp.TimeType = txt[0] + txt[1] + txt[2] + txt[3] + txt[4] + txt[5] + txt[6]; sp.TimeSep = txtTimeThree.Text.Trim() + "~" + txtTimeFour.Text.Trim(); } sp.EMail = txtEMail.Text.Trim(); sp.Mobile = txtMobile.Text.Trim(); sp.Code = txtCode.Text.Trim(); sp.Name = txtName.Text.Trim(); if (cBoxEnable.Text == "是") { sp.Enable = 1; } else { sp.Enable = 0; } sp.JobClassName = txtJobClassName.Text.Trim(); try { if (btnAdd.Text == "新 增") { this.Cursor = Cursors.WaitCursor; new Sp_configDAL().Insert(sp); this.Cursor = Cursors.Arrow; MessageBox.Show("添加成功"); txtCode.Text = "SC_" + GetTimeStamp() + new Random().Next(10000, 99999); addOneRow(sp); GlobalShare.SystemConfigs.Add(sp); } else { //sp.Id = Convert.ToInt32(dgvShow.SelectedRows[0].Cells["Id"].Value); new Sp_configDAL().Update(sp); MessageBox.Show("修改成功"); txtCode.Text = "SC_" + GetTimeStamp() + new Random().Next(10000, 99999); btnAdd.Text = "新 增"; updateRow(dgvShow.SelectedRows[0], sp); updateGlobalBuffer(dgvShow.SelectedRows[0].Index, sp); //ShowDGV(); } txtEMail.Text = ""; txtMobile.Text = ""; txtName.Text = ""; txtJobClassName.Text = ""; txtCode.Text = "SC_" + GetTimeStamp() + new Random().Next(10000, 99999); //ShowDGV(); } catch (Exception ex) { if (btnAdd.Text == "新 增") { MessageBox.Show("添加失败!错误代码为:" + ex.ToString()); } else { MessageBox.Show("修改失败!错误代码为:" + ex.ToString()); } } }
private void updateGlobalBuffer(int p, Sp_config sp) { GlobalShare.SystemConfigs.RemoveAt(p); GlobalShare.SystemConfigs.Insert(p, sp); }