/// <summary>
        /// Tìm kiếm file theo đường dẫn programlist
        /// </summary>
        /// <param name="programListPath"></param>
        /// <returns></returns>
        private FileInfoDs FindByProgramList(string programListPath)
        {
            ExcelApp.Application excelApp   = new ExcelApp.Application();
            FileInfoDs           fileInfoDs = new FileInfoDs();

            try
            {
                ExcelApp.Workbook   excelBook  = excelApp.Workbooks.Open(programListPath);
                ExcelApp._Worksheet excelSheet = excelBook.Sheets[1];
                ExcelApp.Range      excelRange = excelSheet.UsedRange;

                int rows = excelRange.Rows.Count;

                for (int i = 4; i < rows; i++)
                {
                    FileInfoDs.FileInfoRow row = fileInfoDs.FileInfo.NewFileInfoRow();
                    row.FileUrl  = excelRange.Cells[i, 5].Value2.ToString();
                    row.FileName = excelRange.Cells[i, 6].Value2.ToString();
                    row.status   = excelRange.Cells[i, 8].Value2.ToString();

                    // ghép đường dẫn tương đối
                    string relativePath = Path.Combine(row.FileUrl, row.FileName);

                    // ghép full đương dẫn file(đường dẫn tương đối có \\ đằng trước nên ko combine được)
                    string absolutePath = string.Format("{0}{1}", txtSourcePath.Text, relativePath);

                    row.checkexist = File.Exists(absolutePath) ? ApConst.ExistStatus : ApConst.NotExistStatus;

                    fileInfoDs.FileInfo.AddFileInfoRow(row);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Check File Data Again!");
                return(null);
            }
            finally
            {
                excelApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
            }
            return(fileInfoDs);
        }
        /// <summary>
        /// Find By PathSource
        /// </summary>
        /// <returns></returns>
        private FileInfoDs FindBySource()
        {
            FileInfoDs fileInfoDs = new FileInfoDs();
            string     repoDir    = this.txtSourcePath.Text;

            List <string> lstFileKey = new List <string>(File.ReadAllLines(extSettingPath));

            using (var repo = new Repository(repoDir))
            {
                #region Get Files Un Commit

                foreach (var item in repo.RetrieveStatus())
                {
                    if (lstFileKey.Contains(Path.GetExtension(item.FilePath).Trim()))
                    {
                        if (item.State == FileStatus.NewInWorkdir ||
                            item.State == FileStatus.ModifiedInWorkdir ||
                            item.State == FileStatus.NewInIndex ||
                            item.State == FileStatus.ModifiedInIndex)
                        {
                            string gitFolderPath     = item.FilePath.ToString();
                            string displayFolderPath = gitFolderPath.Contains(forwardSlashChar) ? @"\" +
                                                       gitFolderPath.Substring(0, gitFolderPath.LastIndexOf(forwardSlashChar)).Replace(@"/", @"\") : @"\";
                            if (CheckInvalidFiles(displayFolderPath))
                            {
                                continue;
                            }

                            string strFileName = gitFolderPath.Contains(forwardSlashChar) ? gitFolderPath.Substring(gitFolderPath.LastIndexOf(forwardSlashChar) + 1) : gitFolderPath;
                            if (CheckInvalidFiles(strFileName))
                            {
                                continue;
                            }

                            string status = string.Empty;
                            if (item.State == FileStatus.NewInWorkdir || item.State == FileStatus.NewInIndex)
                            {
                                status = ApConst.AddStatus;
                            }
                            else if (item.State == FileStatus.ModifiedInWorkdir || item.State == FileStatus.ModifiedInIndex)
                            {
                                status = ApConst.UpdateStatus;
                            }

                            FileInfoDs.FileInfoRow unCommitRow = fileInfoDs.FileInfo.NewFileInfoRow();

                            unCommitRow.FileUrl    = displayFolderPath;
                            unCommitRow.FileName   = strFileName;
                            unCommitRow.status     = status;
                            unCommitRow.checkexist = ApConst.NotcommitStatus;
                            fileInfoDs.FileInfo.AddFileInfoRow(unCommitRow);
                            unCommitRow.AcceptChanges();
                        }
                    }
                }

                #endregion

                #region Get Files Commit

                var test = repo.Commits.Where(x => x.Committer.When >= DateTimeGetChangeControl.Value.Date).OrderBy(x => x.Committer.When);

                foreach (Commit commit in repo.Commits.Where(x => x.Committer.When >= DateTimeGetChangeControl.Value.Date).OrderBy(x => x.Committer.When))
                {
                    string commiter = commit.Committer.Name;

                    foreach (var parent in commit.Parents)
                    {
                        foreach (TreeEntryChanges change in repo.Diff.Compare <TreeChanges>(parent.Tree, commit.Tree))
                        {
                            FileInfoDs.FileInfoRow fileInfoRow = fileInfoDs.FileInfo.NewFileInfoRow();

                            string gitFolderPath = change.OldPath.ToString();
                            if (CheckInvalidFiles(gitFolderPath))
                            {
                                continue;
                            }

                            string displayFolderPath = gitFolderPath.Contains(forwardSlashChar) ? @"\" +
                                                       gitFolderPath.Substring(0, gitFolderPath.LastIndexOf(forwardSlashChar)).Replace(@"/", @"\") : @"\";
                            if (CheckInvalidFiles(displayFolderPath))
                            {
                                continue;
                            }

                            string strFileName = gitFolderPath.Contains(forwardSlashChar) ?
                                                 gitFolderPath.Substring(gitFolderPath.LastIndexOf(forwardSlashChar) + 1) : gitFolderPath;
                            if (CheckInvalidFiles(strFileName))
                            {
                                continue;
                            }

                            string gitFolderNewPath     = string.Empty;
                            string displayFolderNewPath = string.Empty;
                            string strNewFileName       = string.Empty;

                            if (change.OldPath.ToString() != change.Path.ToString())
                            {
                                gitFolderNewPath     = change.Path.ToString();
                                displayFolderNewPath = gitFolderNewPath.Contains(forwardSlashChar) ? @"\" +
                                                       gitFolderNewPath.Substring(0, gitFolderNewPath.LastIndexOf(forwardSlashChar)).Replace(@"/", @"\") : @"\";

                                strNewFileName = gitFolderNewPath.Contains(forwardSlashChar) ?
                                                 gitFolderNewPath.Substring(gitFolderNewPath.LastIndexOf(forwardSlashChar) + 1) : gitFolderNewPath;
                            }

                            string status = this.GetStatusToGit(change.Status);

                            if (lstFileKey.Contains(Path.GetExtension(gitFolderPath).Trim()))
                            {
                                // kiểm tra file đã tồn tại trên grid hay chưa
                                FileInfoDs.FileInfoRow rowFileExist = fileInfoDs.FileInfo.Where(x => x.FileUrl == displayFolderPath &&
                                                                                                x.FileName == strFileName).FirstOrDefault();

                                if (rowFileExist == null)
                                {
                                    fileInfoRow.FileUrl  = displayFolderPath;
                                    fileInfoRow.FileName = strFileName;
                                    fileInfoRow.status   = status;
                                    fileInfoRow.Commiter = commiter;
                                    fileInfoDs.FileInfo.AddFileInfoRow(fileInfoRow);
                                    fileInfoRow.AcceptChanges();
                                }
                                else
                                {
                                    if (status == ApConst.DeleteStatus)
                                    {
                                        fileInfoDs.FileInfo.Rows.Remove(rowFileExist);
                                    }
                                    else if (status == ApConst.RenameStatus)
                                    {
                                        rowFileExist.BeginEdit();
                                        rowFileExist.FileUrl  = displayFolderNewPath;
                                        rowFileExist.FileName = strNewFileName;
                                        rowFileExist.Commiter = commiter;
                                        rowFileExist.EndEdit();
                                        fileInfoDs.FileInfo.AcceptChanges();
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion

                return(fileInfoDs);
            }
        }
        /// <summary>
        ///  Even Button Find click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFind_Click(object sender, EventArgs e)
        {
            this.ClearErr();
            this.ResetControl();
            try
            {
                // Get file code in source
                List <string> lstFile = new List <string>();

                string path      = this.txtSourcePath.Text;
                int    lengtpath = path.Length;

                FileInfoDs fileInfoDs = new FileInfoDs();

                // Get file name in program list
                int rowCnt = 0;

                this.dtGrvProgramList.Rows.Clear();
                if (this.radChkByPrgList.Checked == true)
                {
                    fileInfoDs = this.FindByProgramList(txtProgramLstPath.Text);

                    FileInfoDs fileInfoDsSource = new FileInfoDs();

                    fileInfoDsSource = this.FindBySource();

                    foreach (FileInfoDs.FileInfoRow dataSourceRow in fileInfoDsSource.FileInfo.Rows)
                    {
                        var isFileExcelExistInSource = fileInfoDs.FileInfo.Where(x => x.FileName == dataSourceRow.FileName).FirstOrDefault();
                        if (isFileExcelExistInSource == null)
                        {
                            dataSourceRow.checkexist = ApConst.NotExistInExcel;
                            fileInfoDs.FileInfo.ImportRow(dataSourceRow);
                        }
                    }
                }
                else if (this.radChkBySource.Checked == true)
                {
                    fileInfoDs = this.FindBySource();
                }

                if (fileInfoDs.FileInfo.Rows.Count <= 0)
                {
                    return;
                }

                foreach (FileInfoDs.FileInfoRow rows in fileInfoDs.FileInfo.Rows)
                {
                    string commiter = (rows["Commiter"] == DBNull.Value ? string.Empty : rows.Commiter);
                    // Add data in new Row
                    dtGrvProgramList.Rows.Add(rowCnt + 1, rows.FileUrl, rows.FileName, rows.status, rows.checkexist, commiter);
                    if (rows.checkexist == ApConst.NotExistStatus ||
                        rows.checkexist == ApConst.NotExistInExcel)
                    {
                        this.dtGrvProgramList.Rows[rowCnt].DefaultCellStyle.BackColor = Color.Red;
                    }
                    if (rows.checkexist == ApConst.NotcommitStatus)
                    {
                        this.dtGrvProgramList.Rows[rowCnt].DefaultCellStyle.ForeColor = Color.Red;
                        this.dtGrvProgramList.Rows[rowCnt].DefaultCellStyle.BackColor = Color.Yellow;
                    }
                    if (rows.checkexist == ApConst.NotExistStatus)
                    {
                        (this.dtGrvProgramList.Rows[rowCnt].Cells[GrvColumnName.DRV_CHKBOX_SELECT]).ReadOnly = true;
                    }
                    rowCnt++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                FileInfoDs ds = new FileInfoDs();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "FileInfoDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }