コード例 #1
0
        private void CreateShapeFile(BaseControlGroup b, string state, string filePath)
        {
            string msg = string.Empty;

            ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
            ModelDataLine modelDataLine          = new ModelDataLine(); try

            {
                modelDataLine.DatabaseFilePath = filePath;
                System.Data.DataTable dtModel = CommonClass.ExcelToDataTable(filePath);
                DataSourceCommonClass.UpdateModelDataLineFromDataSet(b.Pollutant, modelDataLine, dtModel);

                switch (state)
                {
                case "baseline":
                    b.Base = null;
                    b.Base = modelDataLine;
                    break;

                case "control":
                    b.Control = null;
                    b.Control = modelDataLine;
                    break;
                }
                if (modelDataLine.ModelAttributes.Count == 0)
                {
                    msg = "Error reading files.";
                    return;
                }
                int           threadId = -1;
                AsyncDelegate asyncD   = new AsyncDelegate(AsyncCreateFile);
                IAsyncResult  ar       = asyncD.BeginInvoke(b, modelDataLine, state, out threadId, null, null);
                return;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                return;
            }
            finally
            {
                if (msg != string.Empty)
                {
                    MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
コード例 #2
0
ファイル: ModelData.cs プロジェクト: taving/BenMAP-CE
        private bool CreateShapeFile(BaseControlGroup b)
        {
            string msg = string.Empty;

            System.Data.DataSet ds;
            string currentStat = string.Empty;

            try
            {
                currentStat = _currentStat;

                ModelDataLine modelDataLine = new ModelDataLine(); if (tabControl1.SelectedIndex == 0)
                {
                    WaitShow("Loading model data file.");

                    modelDataLine.DatabaseFilePath = txtModelDatabase.Text;
                    System.Data.DataTable dtModel = CommonClass.ExcelToDataTable(txtModelDatabase.Text);
                    DataSourceCommonClass.UpdateModelDataLineFromDataSet(b.Pollutant, modelDataLine, dtModel);
                }
                else
                {
                    StreamReader sr = new StreamReader(txtModelFile.Text);
                    string       csvDataLine;

                    csvDataLine = "";

                    string fileDataLine;

                    fileDataLine = sr.ReadLine();

                    string[] sMatchArray = fileDataLine.Split(new char[] { ',' });
                    if (!(sMatchArray[0].Replace("\"", "") == b.Pollutant.PollutantName && sMatchArray[1] == b.GridType.GridDefinitionName && sMatchArray[2].Replace("\"", "") == "Model"))
                    {
                        MessageBox.Show("The pollutant or grid definition do not match.");
                        return(false);
                    }
                    WaitShow("Loading model data file...");
                    string strLine = "";
                    ds = new System.Data.DataSet();
                    DataTable dt = new DataTable();
                    DataRow   dr = null;
                    string[]  strArray;
                    strLine = sr.ReadLine();
                    if (strLine != null && strLine.Length > 0)
                    {
                        strArray = strLine.Split(',');
                        for (int i = 0; i < strArray.Count(); i++)
                        {
                            dt.Columns.Add(strArray[i]);
                        }
                    }
                    while (strLine != null)
                    {
                        strLine = sr.ReadLine();
                        if (strLine != null && strLine.Length > 0)
                        {
                            dr       = dt.NewRow();
                            strArray = strLine.Split(',');
                            for (int i = 0; i < strArray.Count(); i++)
                            {
                                dr[i] = strArray[i];
                            }
                            dt.Rows.Add(dr);
                        }
                    }
                    ds.Tables.Add(dt);
                    modelDataLine.DatabaseFilePath = txtModelFile.Text;
                    DataSourceCommonClass.UpdateModelDataLineFromDataSetNewFormat(b.Pollutant, ref modelDataLine, ds);
                    sr.Close();
                    switch (currentStat)
                    {
                    case "baseline":
                        b.Base          = null;
                        b.Base          = modelDataLine;
                        b.Base.GridType = b.GridType;
                        break;

                    case "control":
                        b.Control          = null;
                        b.Control          = modelDataLine;
                        b.Control.GridType = b.GridType;
                        break;
                    }
                }
                System.Threading.Thread.Sleep(100); WaitClose();
                switch (currentStat)
                {
                case "baseline":
                    b.Base = null;
                    b.Base = modelDataLine;
                    break;

                case "control":
                    b.Control = null;
                    b.Control = modelDataLine;
                    break;
                }
                if (modelDataLine.ModelAttributes.Count == 0 && modelDataLine.ModelResultAttributes.Count == 0)
                {
                    msg = "Error reading files.";
                    return(false);
                }
                int           threadId = -1;
                AsyncDelegate asyncD   = new AsyncDelegate(AsyncCreateFile);
                IAsyncResult  ar       = asyncD.BeginInvoke(b, modelDataLine, currentStat, out threadId, null, null);
                return(true);
            }
            catch (Exception ex)
            {
                WaitClose();
                Logger.LogError(ex);
                return(false);
            }
            finally
            {
                if (msg != string.Empty)
                {
                    MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }