前几天,搬房子时又拿起《重构----改善既有代码的设计》这本书来随便翻来看下,重构在开发时,是时常也经常会使用得到。
开发(ASP.NET程序)把写代码写至最有面向对象味道


她确实教我们怎样把写程序写简洁,清楚 好明白,好理解,好维护......

今天为博客写点重构相关。以网友实际的例子,在论坛上看到的:

开发(ASP.NET程序)把写代码写至最有面向对象味道
开发(ASP.NET程序)把写代码写至最有面向对象味道
public void show2(string day)
    {
        string[] str = new string[] { "09:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00" };
        for (int i = 0; i < str.Length; i++)
        {
            string sql1 = "select position from cwsz where day='" + day + "' and sjd='" + str[i] + "'";
            var dt1 = db.ExecuteQuery(sql1);
            if (dt1.Rows.Count > 0)
            {
                if (dt1.Rows[0]["position"] != null)
                {
                    if (str[i] == "09:00")
                    {
                        if (dt1.Rows[0]["position"].ToString() == "3")
                            dropnine.SelectedIndex = 1;
                        else if (dt1.Rows[0]["position"].ToString() == "4")
                            dropnine.SelectedIndex = 2;
                        else if (dt1.Rows[0]["position"].ToString() == "5")
                            dropnine.SelectedIndex = 3;
                        else
                            dropnine.SelectedIndex = 4;

                    }
                    if (str[i] == "10:00")
                    {
                        if (dt1.Rows[0]["position"].ToString() == "3")
                            dropten.SelectedIndex = 1;
                        else if (dt1.Rows[0]["position"].ToString() == "4")
                            dropten.SelectedIndex = 2;
                        else if (dt1.Rows[0]["position"].ToString() == "5")
                            dropten.SelectedIndex = 3;
                        else
                            dropten.SelectedIndex = 4;
                    }
                    if (str[i] == "11:00")
                    {
                        if (dt1.Rows[0]["position"].ToString() == "3")
                            dropele.SelectedIndex = 1;
                        else if (dt1.Rows[0]["position"].ToString() == "4")
                            dropele.SelectedIndex = 2;
                        else if (dt1.Rows[0]["position"].ToString() == "5")
                            dropele.SelectedIndex = 3;
                        else
                            dropele.SelectedIndex = 4;
                    }
                    if (str[i] == "12:00")
                    {
                        if (dt1.Rows[0]["position"].ToString() == "3")
                            droptw.SelectedIndex = 1;
                        else if (dt1.Rows[0]["position"].ToString() == "4")
                            droptw.SelectedIndex = 2;
                        else if (dt1.Rows[0]["position"].ToString() == "5")
                            droptw.SelectedIndex = 3;
                        else
                            droptw.SelectedIndex = 4;
                    }
                    if (str[i] == "13:00")
                    {
                        if (dt1.Rows[0]["position"].ToString() == "3")
                            tropthir.SelectedIndex = 1;
                        else if (dt1.Rows[0]["position"].ToString() == "4")
                            tropthir.SelectedIndex = 2;
                        else if (dt1.Rows[0]["position"].ToString() == "5")
                            tropthir.SelectedIndex = 3;
                        else
                            tropthir.SelectedIndex = 4;
                    }
                    if (str[i] == "14:00")
                    {
                        if (dt1.Rows[0]["position"].ToString() == "3")
                            dropfour.SelectedIndex = 1;
                        else if (dt1.Rows[0]["position"].ToString() == "4")
                            dropfour.SelectedIndex = 2;
                        else if (dt1.Rows[0]["position"].ToString() == "5")
                            dropfour.SelectedIndex = 3;
                        else
                            dropfour.SelectedIndex = 4;
                    }
                }
            }
        }
    }
开发(ASP.NET程序)把写代码写至最有面向对象味道

相关文章:

  • 2021-08-16
  • 2021-09-18
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2021-08-02
  • 2021-09-07
  • 2021-12-04
  • 2021-10-25
  • 2021-09-14
相关资源
相似解决方案