public IList <Shreet> GetAllShreet(string sql, SqlParameter[] paras) { IList <Shreet> list = null; DataTable table = SQLDBHelper.GetDataTable(sql, paras); if (table != null) { if (table.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table.Rows) { Shreet shreet = new Shreet(); shreet.ShreetId = int.Parse(row["shreetId"].ToString()); shreet.ShreetName = row["shreetName"].ToString(); shreet.DistrictId = int.Parse(row["districtId"].ToString()); if (ds.GetDistrictByID(shreet.DistrictId) != null) { shreet.District = ds.GetDistrictByID(shreet.DistrictId)[0]; } list.Add(shreet); } } } return(list); }
private void listBoxControlStreet_DoubleClick(object sender, EventArgs e) { shreet = this.listBoxControlStreet.SelectedValue as Shreet; if (shreet != null) { this.textEditStreet.Text = shreet.ShreetName; IList <District> dListDistrict = DistrictManager.GetDistrictByID(shreet.DistrictId); if (dListDistrict != null) { this.textEditDistrict.Text = dListDistrict[0].DistrictName; if (dListDistrict[0].City != null) { this.textEditCity.Text = dListDistrict[0].City.CityName; this.textEditAddress.Text = dListDistrict[0].City.CityName + dListDistrict[0].DistrictName + shreet.ShreetName; } else { this.textEditAddress.Text = dListDistrict[0].DistrictName + shreet.ShreetName; } } else { this.textEditAddress.Text = shreet.ShreetName; } } else { this.textEditStreet.Text = ""; this.textEditAddress.Text = ""; } }
private void listBoxControlDistrict_Click(object sender, EventArgs e) { district = this.listBoxControlDistrict.SelectedValue as District; if (district != null) { this.textEditDistrict.Text = district.DistrictName; this.textEditStreet.Text = ""; IList <Shreet> list = null; DataTable table = ShreetManager.GetShreetByDistrictIdTwo(district.DistrictId); if (table != null) { if (table.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table.Rows) { Shreet shreet = new Shreet(); shreet.ShreetId = int.Parse(row["shreetId"].ToString()); shreet.ShreetName = row["shreetName"].ToString(); shreet.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet); } } } this.bindingSourceStreet.DataSource = list; } else { this.textEditStreet.Text = ""; this.textEditDistrict.Text = ""; } }
private void listBoxControlStreet_Click(object sender, EventArgs e) { shreet = this.listBoxControlStreet.SelectedValue as Shreet; if (shreet != null) { this.textEditStreet.Text = shreet.ShreetName; IList <District> dList = DistrictManager.GetDistrictByID(shreet.DistrictId); if (dList != null) { this.textEditDistrict.Text = dList[0].DistrictName; } this.bindingSourceDistrict.DataSource = dList; } else { this.textEditStreet.Text = ""; } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Shreet model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Shreet("); strSql.Append("ShreetName,DistrictId)"); strSql.Append(" values ("); strSql.Append("@ShreetName,@DistrictId)"); SqlParameter[] parameters = { new SqlParameter("@ShreetName", SqlDbType.VarChar, 20), new SqlParameter("@DistrictId", SqlDbType.Int, 4) }; parameters[0].Value = model.ShreetName; parameters[1].Value = model.DistrictId; return(SQLDBHelper.ExcuteSql(strSql.ToString(), parameters)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Shreet model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Shreet set "); strSql.Append("ShreetName=@ShreetName,"); strSql.Append("DistrictId=@DistrictId "); strSql.Append(" where ShreetId=@ShreetId "); SqlParameter[] parameters = { new SqlParameter("@ShreetName", SqlDbType.VarChar, 20), new SqlParameter("@DistrictId", SqlDbType.Int, 4), new SqlParameter("@ShreetId", SqlDbType.Int, 4) }; parameters[0].Value = model.ShreetName; parameters[1].Value = model.DistrictId; parameters[2].Value = model.ShreetId; return(SQLDBHelper.ExcuteSql(strSql.ToString(), parameters)); }
//private void setTag(Control cons) //{ // foreach (Control con in cons.Controls) // { // con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size; // if (con.Controls.Count > 0) // setTag(con); // } //} //private void setControls(float newx, float newy, Control cons) //{ // foreach (Control con in cons.Controls) // { // if (con.Tag != null) // { // string[] mytag = con.Tag.ToString().Split(new char[] { ':' }); // float a = Convert.ToSingle(mytag[0]) * newx; // con.Width = (int)a; // a = Convert.ToSingle(mytag[1]) * newy; // con.Height = (int)(a); // a = Convert.ToSingle(mytag[2]) * newx; // con.Left = (int)(a); // a = Convert.ToSingle(mytag[3]) * newy; // con.Top = (int)(a); // Single currentSize = Convert.ToSingle(mytag[4]) * newy; // //改变字体大小 // con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit); // } // if (con.Controls.Count > 0) // { // setControls(newx, newy, con); // } // } //} //void Form1_Resize(object sender, EventArgs e) //{ // // throw new Exception("The method or operation is not implemented."); // float newx = (this.Width) / X; // // float newy = (this.Height - this.statusStrip1.Height) / (Y - y); // float newy = this.Height / Y; // setControls(newx, newy, this); // //this.Text = this.Width.ToString() + " " + this.Height.ToString(); //} private void Bind() { this.bindingSourceCity.DataSource = CityManager.GetCity(); city = this.listBoxControlCity.SelectedValue as City; district = this.listBoxControlDistrict.SelectedValue as District; if (jjyy == 0) { shreet = this.listBoxControlStreet.SelectedValue as Shreet; } jjyy = 0; //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrict(); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreet(); this.textEditCity.Enabled = false; this.textEditDistrict.Enabled = false; this.textEditStreet.Enabled = false; this.simpleButtonAdd.Enabled = true; this.simpleButtonDelete.Enabled = true; this.simpleButtonUpdate.Enabled = true; this.simpleButtonSave.Enabled = false; }
private void buttonVillage_Click(object sender, EventArgs e) { IList <Shreet> list = null; DataTable table = ShreetManager.GetShreetByKeyNameTooo(this.buttonVillage.Text); if (table != null) { if (table.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table.Rows) { Shreet shreet = new Shreet(); shreet.ShreetId = int.Parse(row["shreetId"].ToString()); shreet.ShreetName = row["shreetName"].ToString(); shreet.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet); } } } this.bindingSourceStreet.DataSource = list; }
public IList <Shreet> GetShreetTx() { string sql = "SELECT * FROM Shreet"; IList <Shreet> list = null; DataTable table = SQLDBHelper.GetDataTable(sql, null); if (table != null) { if (table.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table.Rows) { Shreet shreet = new Shreet(); shreet.ShreetId = int.Parse(row["shreetId"].ToString()); shreet.ShreetName = row["shreetName"].ToString(); shreet.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet); } } } return(list); }
private void simpleButtonSave_Click(object sender, EventArgs e) { if (this.textEditCity.Text == "") { MessageBox.Show("資料不全,無法儲存!"); return; } if (this.textEditDistrict.Text == "") { MessageBox.Show("資料不全,無法儲存!"); return; } if (this.textEditStreet.Text == "") { MessageBox.Show("資料不全,無法儲存!"); return; } if (city == null) { city = new City(); } if (district == null) { district = new District(); } if (shreet == null) { shreet = new Shreet(); } city.CityName = this.textEditCity.Text; district.DistrictName = this.textEditDistrict.Text; shreet.ShreetName = this.textEditStreet.Text; if (flog == 1) { if (CityManager.GetCityByName(city.CityName) == null) { bool i = CityManager.Add(city); if (i == true) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool j = DistrictManager.Add(district); if (j == true) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.CityId); if (table != null) { if (table.Rows.Count > 0) { list1 = new List <District>(); foreach (DataRow row in table.Rows) { District district1 = new District(); district1.DistrictId = int.Parse(row["districtId"].ToString()); district1.DistrictName = row["districtName"].ToString(); district1.CityId = int.Parse(row["cityId"].ToString()); list1.Add(district1); } } } this.bindingSourceDistrict.DataSource = list1; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } } } } else { if (DistrictManager.GetDistrictByName(district.DistrictName) == null) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool i = DistrictManager.Add(district); if (i == true) { shreet.DistrictId = DistrictManager.GetDistrictByName(district.DistrictName)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.CityId); if (table != null) { if (table.Rows.Count > 0) { list1 = new List <District>(); foreach (DataRow row in table.Rows) { District district1 = new District(); district1.DistrictId = int.Parse(row["districtId"].ToString()); district1.DistrictName = row["districtName"].ToString(); district1.CityId = int.Parse(row["cityId"].ToString()); list1.Add(district1); } } } this.bindingSourceDistrict.DataSource = list1; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } } } else { if (DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId) == null) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool i = DistrictManager.Add(district); if (i == true) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.CityId); if (table != null) { if (table.Rows.Count > 0) { list1 = new List <District>(); foreach (DataRow row in table.Rows) { District district1 = new District(); district1.DistrictId = int.Parse(row["districtId"].ToString()); district1.DistrictName = row["districtName"].ToString(); district1.CityId = int.Parse(row["cityId"].ToString()); list1.Add(district1); } } } this.bindingSourceDistrict.DataSource = list1; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } } } else { if (DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].CityId != CityManager.GetCityByName(city.CityName)[0].CityId) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool i = DistrictManager.Add(district); if (i == true) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.CityId); if (table != null) { if (table.Rows.Count > 0) { list1 = new List <District>(); foreach (DataRow row in table.Rows) { District district1 = new District(); district1.DistrictId = int.Parse(row["districtId"].ToString()); district1.DistrictName = row["districtName"].ToString(); district1.CityId = int.Parse(row["cityId"].ToString()); list1.Add(district1); } } } this.bindingSourceDistrict.DataSource = list1; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } } } else { if (ShreetManager.GetShreetByName(shreet.ShreetName) == null) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool i = ShreetManager.Add(shreet); if (i == true) { MessageBox.Show("添加成功!"); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } } else { int iCount = 0; foreach (Shreet ss in ShreetManager.GetShreetByName(shreet.ShreetName)) { if (ss.DistrictId == DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId) { iCount = 1; } } if (iCount == 0) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool i = ShreetManager.Add(shreet); if (i == true) { MessageBox.Show("添加成功!"); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } } else { iCount = 0; jjyy = 1; MessageBox.Show("資料重複,無法新增此筆資料!"); } } } } } } } if (flog == 2) { ShreetManager.Update(shreet); if (DistrictManager.GetDistrictByName(district.DistrictName) == null) { DistrictManager.Update(district); } else { int iCount = 0; foreach (District d in DistrictManager.GetDistrictByName(district.DistrictName)) { if (d.CityId == city.CityId) { iCount = 1; } } if (iCount == 0) { DistrictManager.Update(district); } iCount = 0; } if (CityManager.GetCityByName(city.CityName) == null) { CityManager.Update(city); } MessageBox.Show("修改成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.CityId); if (table != null) { if (table.Rows.Count > 0) { list1 = new List <District>(); foreach (DataRow row in table.Rows) { District district1 = new District(); district1.DistrictId = int.Parse(row["districtId"].ToString()); district1.DistrictName = row["districtName"].ToString(); district1.CityId = int.Parse(row["cityId"].ToString()); list1.Add(district1); } } } this.bindingSourceDistrict.DataSource = list1; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } flog = 0; Bind(); }
private void simpleButtonDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("確定要刪除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { shreet = this.listBoxControlStreet.SelectedValue as Shreet; if (shreet != null) { ShreetManager.Delete(shreet.ShreetId); if (district != null) { //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(district.DistrictId); IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(district.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } shreet = this.listBoxControlStreet.SelectedValue as Shreet; this.textEditStreet.Text = ""; } else { if (district != null) { district = this.listBoxControlDistrict.SelectedValue as District; DistrictManager.Delete(district.DistrictId); if (city != null) { //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(city.CityId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(city.CityId); if (table != null) { if (table.Rows.Count > 0) { list1 = new List <District>(); foreach (DataRow row in table.Rows) { District district1 = new District(); district1.DistrictId = int.Parse(row["districtId"].ToString()); district1.DistrictName = row["districtName"].ToString(); district1.CityId = int.Parse(row["cityId"].ToString()); list1.Add(district1); } } } this.bindingSourceDistrict.DataSource = list1; } district = this.listBoxControlDistrict.SelectedValue as District; this.textEditStreet.Text = ""; this.textEditDistrict.Text = ""; } else { if (city != null) { bool i = CityManager.Delete(city.CityId); this.bindingSourceCity.DataSource = CityManager.GetCity(); } city = this.listBoxControlCity.SelectedValue as City; this.textEditCity.Text = ""; this.textEditDistrict.Text = ""; this.textEditStreet.Text = ""; } } } Bind(); }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(Shreet model) { return(ShreetService.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public static bool Add(Shreet model) { return(ShreetService.Add(model)); }