Exemple #1
0
        static void Main(string[] args)
        {
            //PersonLogic pLogic = new PersonLogic(Utilities.DataFolder, Utilities.PersonsJsonFile, Utilities.ErrorFolder);
            //LoadPersons(pLogic);

            //Console.WriteLine("\n List after insert");
            //CreatePerson(pLogic);
            //LoadPersons(pLogic);

            //
            Init      init  = new Init(Utilities.DataFolder, Utilities.ErrorFolder);
            ToolLogic logic = new ToolLogic(Utilities.ToolJsonFileName);

            Console.WriteLine("\n Initial List of Records:");
            LoadRecords(logic);
            Console.WriteLine("\n Get a record:");
            ShowRecord(logic, 0);

            //Console.WriteLine("\n List after insert");
            //CreateRecord(logic); //Tested Good
            //UpdateRecord(logic, 2); //Tested Good
            //DeleteRecord(logic, 0); //Tested Good
            //LoadRecords(logic);

            Console.Write("\n\n Press any key to exit: ");
            Console.ReadKey();
        }
Exemple #2
0
        static void LoadRecords(ToolLogic logic)
        {
            List <Tool> ls = logic.Records;

            foreach (Tool t in ls)
            {
                Console.WriteLine("ID:{0} Name:{1} Created:{2} Updated:{3}", t.m_id, t.m_name, t.m_created, t.m_updated);
            }
        }
Exemple #3
0
        static void ShowRecord(ToolLogic logic, int id)
        {
            var rec = logic.Records.FirstOrDefault(x => x.m_id == id).m_created;

            if (rec != null)
            {
                Console.WriteLine(" id:{0} Created:{1}", id, rec);
            }
            else
            {
                Console.WriteLine(" No data was returned!");
            }
        }
        private void Reset()
        {
            //Set
            Init init = new Init(Utilities.ToolsFolder, Utilities.ErrorFolder);

            logic   = new ToolLogic(Utilities.ToolsDataFileName);
            lsTools = logic.Records;

            imagepath = Utilities.DefaultPicture;

            ResetToolFields();

            ShowTools();
        }
Exemple #5
0
        static void CreateRecord(ToolLogic logic)
        {
            Tool t = new Tool()
            {
                m_name    = "Johan",
                m_url     = "http://ayitech.com",
                m_notes   = "This is a test...",
                m_picture = @"C:\Users\charl\Pictures\resources-1400x642.jpg",
                m_created = DateTime.Now.ToString(),
                m_updated = DateTime.Now.ToString()
            };

            logic.CreateRecord(t);
        }
Exemple #6
0
        static void UpdateRecord(ToolLogic logic, int id)
        {
            //get created date by id
            var    rec     = logic.Records.FirstOrDefault(x => x.m_id == id).m_created;
            string created = DateTime.Now.ToString();

            if (rec != null)
            {
                created = rec;
            }

            Tool t = new Tool()
            {
                m_id      = id,
                m_name    = "Sample Name",
                m_url     = "http://ayitech.com",
                m_notes   = "This is a test...",
                m_picture = @"C:\Users\charl\Pictures\resources-1400x642.jpg",
                m_created = created,
                m_updated = DateTime.Now.ToString()
            };

            logic.UpdateRecord(t, id.ToString());
        }
        private void DeleteTool(ToolLogic logic, int id)
        {
            logic.DeleteRecord(id.ToString());

            Reset();
        }
        private void SaveRecord(ToolLogic logic)
        {
            if (!valSave())
            {
                return;
            }
            else
            {
                DirectoryInfo dirData = new DirectoryInfo(Utilities.ToolsFolder);
                if (!dirData.Exists)
                {
                    dirData.Create();
                }

                DirectoryInfo dirImages = new DirectoryInfo(Utilities.ToolsImagesFolder);
                if (!dirImages.Exists)
                {
                    dirImages.Create();
                }

                Tool tool = new Tool();
                try
                {
                    tool.m_id      = tool_id;
                    tool.m_name    = txtName.Text.Trim();
                    tool.m_url     = txtUrl.Text.Trim();
                    tool.m_notes   = txtNotes.Text.Trim();
                    tool.m_updated = DateTime.Now.ToString();

                    //Set Picture
                    string picnewname = "";
                    tempimagepath = "";
                    FileInfo flePicture = new FileInfo(imagepath);
                    if (tempimagepath.Length > 0)
                    {
                        if (tempimagepath == imagepath)
                        {
                            picnewname = tempimagepath;
                        }
                        else
                        {
                            picnewname = @"" + Utilities.ToolsImagesFolder + "\\" + txtName.Text + Utilities.RandomNumber(1, 100) + flePicture.Extension;
                            flePicture.CopyTo(picnewname);
                        }
                    }
                    else
                    {
                        picnewname = @"" + Utilities.ToolsImagesFolder + "\\" + txtName.Text + flePicture.Extension;
                        //if picture exist don't copy
                        if (!File.Exists(picnewname))
                        {
                            flePicture.CopyTo(picnewname);
                        }
                        else
                        {
                            picnewname = imagepath;
                        }
                    }

                    tool.m_picture = picnewname;
                    //tool.m_id = id.ToString();

                    //If already exist do update else Insert
                    var record = lsTools.FirstOrDefault(x => x.m_id == tool_id);
                    if (record != null)
                    {
                        //Update
                        //Validate Duplicate

                        tool.m_created = created;
                        logic.UpdateRecord(tool, tool_id.ToString());
                    }
                    else
                    {
                        //Insert
                        //Validate Duplicate
                        tool.m_created = DateTime.Now.ToString();
                        logic.CreateRecord(tool);
                    }

                    ExportToExcel();

                    Reset();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + " \n" + ex.InnerException, Utilities.MsgBoxHead);
                }
            }
        }
Exemple #9
0
 static void DeleteRecord(ToolLogic logic, int id)
 {
     logic.DeleteRecord(id.ToString());
 }