Exemplo n.º 1
0
        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 = "";
            }
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 private void buttonAll_Click(object sender, EventArgs e)
 {
     this.bindingSourceStreet.DataSource = ShreetManager.GetShreetTx();;
 }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
 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();
 }