Example #1
0
        private void Matches(ProgressBarForm progressBarForm)
        {
            DataTable      dt        = (DataTable)myDataGridView1.DataSource;
            string         cInvStd   = dictparam["cInvStd"];
            string         cInvName  = dictparam["cInvName"];
            List <DataRow> rowlist   = new List <DataRow>();
            List <int>     indexlist = new List <int>();
            DataTable      dtData    = new DataTable();

            foreach (DataColumn col in dt.Columns)
            {
                dtData.Columns.Add(col.ColumnName);
            }
            try
            {
                for (int index = 0; index < dt.Rows.Count; index++)
                {
                    if (progressBarForm.Stop == true)
                    {
                        return;
                    }
                    progressBarForm.Value = index + 1;
                    //progressBarForm.AddProgress(index);
                    //Console.WriteLine(index);
                    DataRow row  = dt.Rows[index];
                    string  str1 = row[cInvName].ToString().Trim();
                    string  str2 = row[cInvStd].ToString().Trim();

                    DataRow newRow = null;
                    if (str1 != "" || str2 != "")
                    {
                        DataTable data = sqlProcessor.AccurateQuery_AND_Like(str1, "cInvName", str2, "cInvStd");
                        if (data != null)
                        {
                            if (data.Rows.Count == 0)
                            {
                                data = sqlProcessor.AccurateQuery_AND(str1, "cInvName", str2, "cInvStd");
                                if (data != null)
                                {
                                    if (data.Rows.Count == 0)
                                    {
                                        data = sqlProcessor.AccurateQuery_OR(str1, "cInvName", str2, "cInvStd");
                                        if (data != null)
                                        {
                                            if (data.Rows.Count > 0)
                                            {
                                                dtData.Clear();
                                                dtData.Rows.Add(dt.Rows[index].ItemArray);

                                                DataForm form2 = new DataForm(sqlProcessor, data, dtData);
                                                if (form2.ShowDialog() == DialogResult.OK)
                                                {
                                                    DataRow rowf = form2._row;
                                                    newRow = rowf;
                                                    rowlist.Add(rowf);
                                                    indexlist.Add(index);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        dtData.Clear();
                                        dtData.Rows.Add(dt.Rows[index].ItemArray);

                                        DataForm form2 = new DataForm(sqlProcessor, data, dtData);
                                        if (form2.ShowDialog() == DialogResult.OK)
                                        {
                                            DataRow rowf = form2._row;
                                            newRow = rowf;
                                            rowlist.Add(rowf);
                                            indexlist.Add(index);
                                        }
                                    }
                                }
                            }
                            else if (data.Rows.Count == 1)
                            {
                                newRow = data.Rows[0];
                                rowlist.Add(data.Rows[0]);
                                indexlist.Add(index);
                            }
                        }
                    }
                    row.BeginEdit();
                    //progressBarForm.AddProgress(40);
                    if (newRow != null)
                    {
                        foreach (var map in param.Maps)
                        {
                            if (row.Table.Columns.Contains(map.Value) && newRow.Table.Columns.Contains(map.Name))
                            {
                                row[map.Value] = newRow[map.Name].ToString();
                            }
                            else if (row.Table.Columns.Contains(map.Value) && newRow.Table.Columns.Contains(map.Value))
                            {
                                row[map.Value] = newRow[map.Value].ToString();
                            }
                        }
                    }
                    row.EndEdit();
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
            dt.AcceptChanges();
        }