예제 #1
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);
        }
예제 #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);
                }
            }
        }