Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }