示例#1
0
文件: Main.cs 项目: taving/BenMAP-CE
        private void mnuModifySetup_Click(object sender, EventArgs e)
        {
            ManageSetup  frm          = new ManageSetup();
            DialogResult dialogResult = frm.ShowDialog();

            if (_currentForm != null)
            {
                BenMAP frmBenMAP = _currentForm as BenMAP;
                if (frmBenMAP != null)
                {
                    frmBenMAP.InitAggregationAndRegionList();
                }
            }


            string commandText = "select SetupID,SetupName from Setups order by SetupID";

            ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
            System.Data.DataSet ds = fb.ExecuteDataset(CommonClass.Connection, CommandType.Text, commandText);

            mnuActiveSetup.DropDownItems.Clear();

            foreach (DataRow drSetup in ds.Tables[0].Rows)
            {
                BenMAPSetup benMAPSetupIn = new BenMAPSetup()
                {
                    SetupID   = Convert.ToInt32(drSetup["SetupID"]),
                    SetupName = drSetup["SetupName"].ToString()
                };
                ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
                toolStripMenuItem.Text   = drSetup["SetupName"].ToString();
                toolStripMenuItem.Tag    = benMAPSetupIn;
                toolStripMenuItem.Click += new EventHandler(toolStripMenuItem_Click);
                mnuActiveSetup.DropDownItems.Add(toolStripMenuItem);
            }
            DataRow[] dr = ds.Tables[0].Select("SETUPNAME ='" + mnuActiveSetup.Text + "'");
            if (dr.Count() <= 0 && ds.Tables[0].Rows.Count > 0)
            {
                mnuActiveSetup.Text = ds.Tables[0].Rows[0]["SetupName"].ToString();
            }

            CommonClass.lstPollutantAll = Grid.GridCommon.getAllPollutant(CommonClass.MainSetup.SetupID);
            DataSourceCommonClass._dicSeasonStaticsAll = null;
            bool isDel = false;

            if (CommonClass.LstPollutant != null && CommonClass.LstPollutant.Count > 0)
            {
                for (int iPollutant = 0; iPollutant < CommonClass.LstPollutant.Count; iPollutant++)
                {
                    try
                    {
                        CommonClass.LstPollutant[iPollutant] = CommonClass.lstPollutantAll.Where(p => p.PollutantID == CommonClass.LstPollutant[iPollutant].PollutantID).First();
                    }
                    catch
                    {
                        isDel = true;
                        break;
                    }
                }
            }
            if (isDel)
            {
                if (_currentForm != null)
                {
                    BenMAP frmBenMAP = _currentForm as BenMAP;
                    if (frmBenMAP != null)
                    {
                        if (CommonClass.LstPollutant != null && CommonClass.LstPollutant.Count > 0 && MessageBox.Show("The selected pollutant no longer exists in the database. Please select other pollutants. Save the current case before switching to another case?", "Question", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                        {
                            mnuSaveAs_Click(sender, e);
                            if (_hasSave)
                            {
                                frmBenMAP.OpenFile();
                                _projFileName = "";
                            }
                        }
                        else
                        {
                            frmBenMAP.OpenFile();
                            _projFileName = "";
                        }
                    }
                }
                return;
            }
            if (CommonClass.LstBaseControlGroup != null && CommonClass.LstBaseControlGroup.Count > 0)
            {
                foreach (BaseControlGroup b in CommonClass.LstBaseControlGroup)
                {
                    b.Pollutant = CommonClass.lstPollutantAll.Where(p => p.PollutantID == b.Pollutant.PollutantID).First();
                    if (b.Base != null && b.Base.Pollutant != null)
                    {
                        b.Base.Pollutant = b.Pollutant;
                    }
                    if (b.Control != null && b.Control.Pollutant != null)
                    {
                        b.Control.Pollutant = b.Pollutant;
                    }
                }
            }
            if (CommonClass.BaseControlCRSelectFunction != null && CommonClass.BaseControlCRSelectFunction.lstCRSelectFunction != null && CommonClass.BaseControlCRSelectFunction.lstCRSelectFunction.Count > 0)
            {
                foreach (CRSelectFunction cr in CommonClass.BaseControlCRSelectFunction.lstCRSelectFunction)
                {
                    List <BenMAPPollutant> lstpollutant = CommonClass.lstPollutantAll.Where(p => p.PollutantID == cr.BenMAPHealthImpactFunction.Pollutant.PollutantID).ToList();
                    if (lstpollutant != null && lstpollutant.Count > 0)
                    {
                        cr.BenMAPHealthImpactFunction.Pollutant = lstpollutant.First();
                    }
                }
            }
        }
示例#2
0
文件: Main.cs 项目: taving/BenMAP-CE
        public Main()
        {
            try
            {
                InitializeComponent();
                CheckFirebirdAndStartFirebird();
                _baseFormTitle = this.Text + Assembly.GetExecutingAssembly().GetName().Version.ToString().Substring(0, Assembly.GetExecutingAssembly().GetName().Version.ToString().Count() - 2); mnuOverview.Text = "Quick-Start Guide"; this.Text = _baseFormTitle;

                string sPicName = "";
                CommonClass.ActiveSetup = "USA";
                string commandText = "select SetupID,SetupName from Setups order by SetupID";
                ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
                System.Data.DataSet ds = fb.ExecuteDataset(CommonClass.Connection, CommandType.Text, commandText);

                string iniPath      = CommonClass.ResultFilePath + @"\BenMAP.ini";
                string defaultSetup = "United States";
                if (System.IO.File.Exists(iniPath))
                {
                    defaultSetup = CommonClass.IniReadValue("appSettings", "DefaultSetup", iniPath);
                }
                else
                {
                    CommonClass.IniWriteValue("appSettings", "IsShowStart", "T", iniPath);
                    CommonClass.IniWriteValue("appSettings", "IsShowExit", "T", iniPath);
                    CommonClass.IniWriteValue("appSettings", "DefaultSetup", "United States", iniPath);
                }
                DataRow[] drs = ds.Tables[0].Select("SetupName='" + defaultSetup + "'");
                DataRow   dr;
                if (drs != null && drs.Count() > 0)
                {
                    dr = drs[0];
                }
                else
                {
                    dr = ds.Tables[0].Rows[0];
                    CommonClass.IniWriteValue("appSettings", "DefaultSetup", dr["SetupName"].ToString(), iniPath);
                }
                BenMAPSetup benMAPSetup = new BenMAPSetup()
                {
                    SetupID   = Convert.ToInt32(dr["SetupID"]),
                    SetupName = dr["SetupName"].ToString()
                };
                mnuActiveSetup.DropDownItems.Clear();

                foreach (DataRow drSetup in ds.Tables[0].Rows)
                {
                    BenMAPSetup benMAPSetupIn = new BenMAPSetup()
                    {
                        SetupID   = Convert.ToInt32(drSetup["SetupID"]),
                        SetupName = drSetup["SetupName"].ToString()
                    };
                    ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
                    toolStripMenuItem.Text   = drSetup["SetupName"].ToString();
                    toolStripMenuItem.Tag    = benMAPSetupIn;
                    toolStripMenuItem.Click += new EventHandler(toolStripMenuItem_Click);
                    mnuActiveSetup.DropDownItems.Add(toolStripMenuItem);
                }
                if (mnuActiveSetup.DropDownItems.Count > 0)
                {
                    mnuActiveSetup.Text = dr["SetupName"].ToString();
                }
                CommonClass.MainSetup   = benMAPSetup;
                CommonClass.ManageSetup = benMAPSetup;

                CommonClass.lstPollutantAll = Grid.GridCommon.getAllPollutant(CommonClass.MainSetup.SetupID);
                if (CommonClass.InputParams == null || CommonClass.InputParams.Length == 0)
                {
                    StartPage startFrm = new StartPage();
                    startFrm.ShowDialog();
                }
                else if (CommonClass.InputParams[0].ToLower().Contains(".ctlx"))
                {
                    this.Hide();
                    this.ShowInTaskbar = false;
                    this.WindowState   = FormWindowState.Minimized;
                    return;
                }
                LoadForm(new BenMAP(sPicName));
                InitRecentFile();



                CommonClass.FormChangedStat -= SetCurrentStat;
                CommonClass.FormChangedStat += SetCurrentStat;

                CommonClass.FormChangedSetup -= SetCurrentSetup;
                CommonClass.FormChangedSetup += SetCurrentSetup;



                if (_currentForm != null)
                {
                    BenMAP frm = _currentForm as BenMAP;
                    if (frm != null)
                    {
                        frm.OpenFile();
                        frm.loadInputParamProject();
                    }
                    frm.mainFrm = this;
                }
                this.Status    = "Current Setup: " + CommonClass.MainSetup.SetupName;
                lblStatus.Text = this.Status;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }