示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tb_name.Text.Trim()))
            {
                MessageBox.Show("网页名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            scs       = new ScSystem();
            scs.Deflt = cb_deflt.Checked ? "Y" : "N";
            if (cb_deflt.Checked)
            {
                foreach (ScSystem ss in conf.SysList)
                {
                    ss.Deflt = "N";
                }
            }
            scs.Name = tb_name.Text.Trim();
            scs.Url  = tb_address.Text.Trim();
            List <ScSystem> ssList = new List <ScSystem>();

            if (cmb_updir.SelectedIndex == 0)
            {
                scs.Id  = Convert.ToString(conf.SysList.Count + 1);
                scs.Pid = "0";
                conf.SysList.Add(scs);
                ssList = conf.SysList;
            }
            else
            {
                string selPid   = (cmb_updir.SelectedItem as ScSystem).Id;
                bool   sFlag    = false;
                int    sysIndex = 1;

                for (int i = 0; i < conf.SysList.Count;)
                {
                    if (conf.SysList[i].Id == selPid)
                    {
                        sFlag = true;
                        conf.SysList[i].Id = Convert.ToString(sysIndex++);
                        ssList.Add(conf.SysList[i]);
                        if (i == conf.SysList.Count - 1)
                        {
                            scs.Id  = Convert.ToString(sysIndex++);
                            scs.Pid = ssList[ssList.Count - 1].Id;
                            ssList.Add(scs);
                        }
                    }
                    else if (sFlag && ((i + 1) >= conf.SysList.Count ? "-1" : conf.SysList[i + 1].Id) != selPid)
                    {
                        scs.Id  = Convert.ToString(sysIndex++);
                        scs.Pid = ssList[ssList.Count - 1].Id;
                        ssList.Add(scs);
                        conf.SysList[i].Id = Convert.ToString(sysIndex++);
                        ssList.Add(conf.SysList[i]);
                        sFlag = false;
                    }
                    else
                    {
                        conf.SysList[i].Id = Convert.ToString(sysIndex++);
                        ssList.Add(conf.SysList[i]);
                    }
                    i++;
                }
            }
            //重置ID

            ConfigureHelper.SaveWebapp(ssList);
            MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.DialogResult = DialogResult.OK;
        }