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; }
public void Update(Sp_url ud) { MySqlConnection mycon = new MySqlConnection(); mycon.ConnectionString = url; string sql2 = string.Format("update sp_url set StartIndex='" + ud.StartIndex + "',StopIndex='" + ud.StopIndex + "',Step='" + ud.Step + "',BaseUrl='" + ud.BaseUrl + "',ShortUrl='" + ud.ShortUrl + "',LoopType='" + ud.LoopType + "',Name='" + ud.Name + "',Alias='" + ud.Alias + "',Sheet='" + ud.Sheet + "',ConfigId='" + ud.ConfigId + "',Enable=" + ud.Enable + ",Classfic='" + ud.Classfic + "' where Id =" + ud.Id + ""); MySqlCommand comm = new MySqlCommand(sql2, mycon); mycon.Open(); int result = comm.ExecuteNonQuery(); mycon.Close(); if (result > 0) { } }
public void Insert(Sp_url ud) { MySqlConnection mycon = new MySqlConnection(); mycon.ConnectionString = url; string sql2 = string.Format("INSERT into sp_url(StartIndex,StopIndex,Step,BaseUrl,ShortUrl,LoopType,Name,Alias,Sheet,ConfigId,Code,Enable,Classfic)values('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')", new object[] { ud.Id, ud.StartIndex, ud.StopIndex, ud.Step, ud.BaseUrl, ud.ShortUrl, ud.LoopType, ud.Name, ud.Alias, ud.Sheet, ud.ConfigId, ud.Code, ud.Enable, ud.Classfic }); MySqlCommand comm = new MySqlCommand(sql2, mycon); mycon.Open(); int result = comm.ExecuteNonQuery(); mycon.Close(); if (result > 0) { } }
public Sp_url[] GetAllData(string Code) { MySql.Data.MySqlClient.MySqlConnection mycon = new MySqlConnection(); mycon.ConnectionString = url; string sql2 = "select * from sp_url where ConfigId = '" + Code + "'"; MySqlDataAdapter mda = new MySqlDataAdapter(sql2, mycon); DataSet ds = new DataSet(); mda.Fill(ds, "table1"); DataTable dt = ds.Tables[0]; mycon.Close(); Sp_url[] operators = new Sp_url[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { operators[i] = ToSp_url(dt.Rows[i]); } return(operators); }
private Sp_url ToSp_url(DataRow row) { Sp_url op = new Sp_url(); op.Id = Convert.ToInt32(row["Id"]); op.StartIndex = (int)row["StartIndex"]; op.StopIndex = (int)row["StopIndex"]; op.Step = (int)row["Step"]; op.BaseUrl = (string)row["BaseUrl"]; op.ShortUrl = (string)row["ShortUrl"]; op.LoopType = (int)row["LoopType"]; op.Name = (string)row["Name"]; op.Alias = (string)row["Alias"]; op.Sheet = (string)row["Sheet"]; op.ConfigId = (string)row["ConfigId"]; op.Code = (string)row["Code"]; op.Enable = (int)row["Enable"]; op.Classfic = (string)row["Classfic"]; return(op); }
private void cbUrl_SelectedIndexChanged(object sender, EventArgs e) { Sp_url url = (Sp_url)cbUrl.SelectedItem; if (url == null) { return; } Sp_url_attr[] spUrl = new Sp_url_attrDAL().GetAllData(url.Code); tvAttr.Nodes.Clear(); for (int i = 0; i < spUrl.Length; i++) { TreeNode node = new TreeNode(spUrl[i].ToString()); node.Tag = spUrl[i]; tvAttr.Nodes.Add(node); } }
private void btnAddUrl_Click(object sender, EventArgs e) { if (txtStartIndex.Text.Trim() == "" || txtStopIndex.Text.Trim() == "" || txtStep.Text.Trim() == "" || txtBaseUrl.Text.Trim() == "" || txtName.Text.Trim() == "" || txtAlias.Text.Trim() == "" || txtSheet.Text.Trim() == "" || txtClassfic.Text.Trim() == "") { MessageBox.Show("索引步长等信息为必填项!"); return; } Sp_url spUrl = new Sp_url(); //Sp_url[] spUrlAll = new Sp_urlDAL().GetAllData(); //spUrl.Id = spUrlAll.Length + 1; spUrl.StartIndex = Convert.ToInt32(txtStartIndex.Text.Trim()); spUrl.StopIndex = Convert.ToInt32(txtStopIndex.Text.Trim()); spUrl.Step = Convert.ToInt32(txtStep.Text.Trim()); spUrl.BaseUrl = txtBaseUrl.Text.Trim(); spUrl.ShortUrl = txtShortUrl.Text.Trim(); if (cBoxLoopType.Text == "静态模式") { spUrl.LoopType = 1; } else { spUrl.LoopType = 0; } spUrl.Name = txtName.Text.Trim(); spUrl.Alias = txtAlias.Text.Trim(); spUrl.Sheet = txtSheet.Text.Trim(); spUrl.ConfigId = txtConfigId.Text.Trim(); spUrl.Code = txtCode.Text.Trim(); if (cBoxEnable.Text == "是") { spUrl.Enable = 1; } else { spUrl.Enable = 0; } spUrl.Classfic = txtClassfic.Text.Trim(); if (btnAddUrl.Text == "新 增") { try { new Sp_urlDAL().Insert(spUrl); MessageBox.Show("添加成功"); ShowDGV(); txtConfigId.Text = Code; txtCode.Text = "SU_" + GetTimeStamp() + new Random().Next(10000, 99999); txtStartIndex.Text = ""; txtStopIndex.Text = ""; txtStep.Text = ""; txtBaseUrl.Text = ""; txtShortUrl.Text = ""; txtName.Text = ""; txtAlias.Text = ""; txtSheet.Text = ""; txtClassfic.Text = ""; } catch (Exception ex) { MessageBox.Show("添加失败,错误代码为:" + ex.ToString()); } } else { try { spUrl.Id = Convert.ToInt32(dgvShowUrl.SelectedRows[0].Cells["Id"].Value); new Sp_urlDAL().Update(spUrl); MessageBox.Show("修改成功"); btnAddUrl.Text = "新 增"; ShowDGV(); txtConfigId.Text = Code; txtCode.Text = "SU_" + GetTimeStamp() + new Random().Next(10000, 99999); txtStartIndex.Text = ""; txtStopIndex.Text = ""; txtStep.Text = ""; txtBaseUrl.Text = ""; txtShortUrl.Text = ""; txtName.Text = ""; txtAlias.Text = ""; txtSheet.Text = ""; txtClassfic.Text = ""; } catch (Exception ex) { MessageBox.Show("修改失败,错误代码为:" + ex.ToString()); } } }