Exemple #1
0
 public AddProbe(int sampleId)
 {
     InitializeComponent();
     InitPermissionsControl();
     tempPath          = System.IO.Path.GetTempPath();
     UserTmpPathString = System.IO.Path.Combine(tempPath, "ReportsArctic");
     System.IO.Directory.CreateDirectory(UserTmpPathString);
     if (sampleId == -1)
     {
         maskedTextBox1.Text = DateTime.Today.ToShortDateString();
     }
     else
     {
         this.Text      = "Исследование #" + sampleId;
         selectedSample = sampleService.getSampleBySampleId(sampleId);
         if (selectedSample == null)
         {
             this.Dispose();
             return;
         }
         else
         {
             initComponentsBySample();
         }
     }
 }
Exemple #2
0
 public void addMetaBySample(SamplePojo samplePojo)
 {
     foreach (MetaObject metaItem in samplePojo.metaList)
     {
         metaItem.SampleId = samplePojo.id;
         SQLiteCommand addMetaForObject = new SQLiteCommand(INSERT_META, Program.conn);
         addMetaForObject.Parameters.Add(new SQLiteParameter("@id", null));
         addMetaForObject.Parameters.Add(new SQLiteParameter("@value", metaItem.Value));
         addMetaForObject.Parameters.Add(new SQLiteParameter("@Type", metaItem.type));
         addMetaForObject.Parameters.Add(new SQLiteParameter("@SampeId", metaItem.SampleId));
         try
         {
             addMetaForObject.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             logger.Error(ex);
             if (ex.Message.Contains("FOREIGN"))
             {
                 MessageBox.Show("Данную запись нельзя добавить.",
                                 "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             throw new Exception(ex.Message);
         }
     }
 }
Exemple #3
0
        public List <SamplePojo> getAllSamples()
        {
            SQLiteCommand     cmd            = new SQLiteCommand(Program.conn);
            List <SamplePojo> samplePojoList = new List <SamplePojo>();

            cmd.CommandText = SELECT_ALL;
            try
            {
                SQLiteDataReader r          = cmd.ExecuteReader();
                SamplePojo       samplePojo = null;
                while (r.Read())
                {
                    samplePojo = new SamplePojo(Int32.Parse(r["id"].ToString()), r["Name"].ToString(), r["Date"].ToString());
                    samplePojoList.Add(samplePojo);
                    logger.Debug("r.Read(): " + samplePojo);
                }
                r.Close();
            }
            catch (SQLiteException ex)
            {
                logger.Error(ex);
            }

            foreach (SamplePojo sample in samplePojoList)
            {
                List <MetaObject> metaList = getMetaBySampleId(sample.id, -1);
                sample.metaList = metaList;
            }

            return(samplePojoList);
        }
Exemple #4
0
        public SamplePojo addSample(SamplePojo samplePojo)
        {
            SQLiteTransaction transact = Program.conn.BeginTransaction();

            SQLiteCommand addObjects = new SQLiteCommand(INSERT, Program.conn, transact);

            addObjects.Parameters.Add(new SQLiteParameter("@id", null));
            addObjects.Parameters.Add(new SQLiteParameter("@Name", samplePojo.name));
            addObjects.Parameters.Add(new SQLiteParameter("@Date", samplePojo.Date));

            try
            {
                addObjects.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                transact.Rollback();
                if (ex.Message.Contains("FOREIGN"))
                {
                    MessageBox.Show("Ошибка добавления",
                                    "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(null);
                }
                throw new Exception(ex.Message);
            }
            samplePojo.id = SQLLiteUtil.getLastRowId();

            foreach (MetaObject metaItem in samplePojo.metaList)
            {
                metaItem.SampleId = samplePojo.id;
                SQLiteCommand addMetaForObject = new SQLiteCommand(INSERT_META, Program.conn, transact);
                addMetaForObject.Parameters.Add(new SQLiteParameter("@id", null));
                addMetaForObject.Parameters.Add(new SQLiteParameter("@value", metaItem.Value));
                addMetaForObject.Parameters.Add(new SQLiteParameter("@Type", metaItem.type));
                addMetaForObject.Parameters.Add(new SQLiteParameter("@SampeId", metaItem.SampleId));
                try
                {
                    addMetaForObject.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                    transact.Rollback();
                    if (ex.Message.Contains("FOREIGN"))
                    {
                        MessageBox.Show("Данную запись нельзя добавить.",
                                        "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(null);
                    }
                    throw new Exception(ex.Message);
                }
            }

            transact.Commit();

            return(samplePojo);
        }
Exemple #5
0
        private void Save_Click(object sender, EventArgs e)
        {
            SamplePojo sample = new SamplePojo();

            sample.name = NameTextBox.Text;
            DateTime date;

            sample.Date = maskedTextBox1.Text.ToString();
            if (sample.name == null || sample.name.Equals(""))
            {
                MessageBox.Show("Исследование нельзя сохранить без имени",
                                "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (!DateTime.TryParse(sample.Date, out date) || date.CompareTo(new DateTime(1911, 01, 01, 01, 00, 0)) < 0 || date.CompareTo(new DateTime(2050, 01, 01, 01, 00, 0)) > 0)
            {
                MessageBox.Show("Введите корректную дату",
                                "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }


            List <MetaObject> metaObjests = new List <MetaObject>();
            ArrayList         filesList   = new ArrayList();

            foreach (ListViewItem item in this.listView1.Items)
            {
                MetaObject key = new MetaObject(0, item.SubItems[0].Text);
                metaObjests.Add(key);
            }
            foreach (ListViewItem item in this.listView2.Items)
            {
                MetaObject key = new MetaObject(1, item.SubItems[0].Text + "-->" + item.SubItems[1].Text);
                metaObjests.Add(key);
                filesList.Add(item.SubItems[1].Text);//storageNames
            }
            sample.metaList = metaObjests;
            if (selectedSample != null)//EditSample case
            {
                sampleService.removeMetaBySample(selectedSample.id);
                sample.id = selectedSample.id;
                sampleService.updateSample(sample);
                sampleService.addMetaBySample(sample);
                copyFilesToAppDir(filesList);
            }
            else//SaveNewSample case
            {
                sampleService.addSample(sample);
                copyFilesToAppDir(filesList);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemple #6
0
        public List <SamplePojo> getSamplesByKeywords(string[] keywords)
        {
            if (keywords == null)
            {
                return(null);
            }
            SQLiteCommand     cmd            = new SQLiteCommand(Program.conn);
            List <SamplePojo> samplePojoList = new List <SamplePojo>();
            StringBuilder     query          = new StringBuilder(SELECT_SAMPLES_BY_KEYWORD);

            if (keywords != null && keywords.Length > 0 && !(keywords.Length == 1 && keywords[0].Equals("")))
            {
                query.Append(" WHERE SampeMeta.value like");
                for (int i = 0; i < keywords.Length; i++)
                {
                    String word = keywords[i];
                    query.Append(" \"%" + word + "%\"");
                    if (i != keywords.Length - 1)
                    {
                        query.Append(" OR SampeMeta.value like");
                    }
                }
            }
            cmd.CommandText = query.ToString();
            try
            {
                SQLiteDataReader r          = cmd.ExecuteReader();
                SamplePojo       samplePojo = null;
                while (r.Read())
                {
                    samplePojo = new SamplePojo(Int32.Parse(r["id"].ToString()), r["Name"].ToString(), r["Date"].ToString());
                    samplePojoList.Add(samplePojo);
                    logger.Debug("r.Read(): " + samplePojo);
                }
                r.Close();
            }
            catch (SQLiteException ex)
            {
                logger.Error(ex);
            }

            foreach (SamplePojo sample in samplePojoList)
            {
                List <MetaObject> metaList = getMetaBySampleId(sample.id, -1);
                sample.metaList = metaList;
            }

            return(samplePojoList);
        }
Exemple #7
0
        public void updateSample(SamplePojo samplePojo)
        {
            SQLiteCommand insertSQL = new SQLiteCommand(UPDATE, Program.conn);

            insertSQL.Parameters.Add(new SQLiteParameter("@Name", samplePojo.name));
            insertSQL.Parameters.Add(new SQLiteParameter("@Date", samplePojo.Date));
            insertSQL.Parameters.Add(new SQLiteParameter("@id", samplePojo.id));
            try
            {
                insertSQL.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw new Exception(ex.Message);
            }
        }
Exemple #8
0
        public SamplePojo getSampleBySampleId(int samplePojoId)
        {
            SQLiteCommand     cmd            = new SQLiteCommand(Program.conn);
            List <SamplePojo> samplePojoList = new List <SamplePojo>();
            List <MetaObject> metaList       = new List <MetaObject>();
            SamplePojo        samplePojo     = null;

            cmd.CommandText = SELECT_SAMPLE_BY_ID;
            cmd.Parameters.Add(new SQLiteParameter("@SampleId", samplePojoId));
            try
            {
                SQLiteDataReader r = cmd.ExecuteReader();
                while (r.Read())
                {
                    if (samplePojo == null)
                    {
                        samplePojo          = new SamplePojo(Int32.Parse(r["SampeId"].ToString()), r["Name"].ToString(), r["Date"].ToString());
                        samplePojo.metaList = metaList;
                        logger.Debug("r.Read(): " + samplePojo);
                    }
                    //Check if there is MetaData
                    String MetaItemId = r["id"].ToString();
                    if (!MetaItemId.Equals(""))
                    {
                        MetaObject metaObj = new MetaObject(Int32.Parse(MetaItemId), Int32.Parse(r["Type"].ToString()), r["value"].ToString(), samplePojo.id);
                        metaObj.SampleId = samplePojo.id;
                        metaList.Add(metaObj);
                    }
                }
                r.Close();
            }
            catch (SQLiteException ex)
            {
                logger.Error(ex);
                MessageBox.Show("Не получилось достать образец из Базы данных - " + ex.Message,
                                "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(null);
            }

            return(samplePojo);
        }