コード例 #1
0
        /* Обновляем уже существующие ключи, которые лежат в dgv_Target */
        private void UpdateExistingKeywordsInDB()
        {
            bool          error     = false; //признак того, что при обновлении ключей возникла ошибка(-и)
            List <string> errorKeys = new List <string> {
            };                               //список ключей, которые не были обновлены

            progressBar1.Maximum = dgv_NewKeys.RowCount + dgv_Target.RowCount;
            progressBar1.Visible = true;

            for (int i = 0; i < dgv_Target.RowCount; i++)
            {
                if (scController.UpdateExistingKeywordBySemCoreId(int.Parse(dgv_Target.Rows[i].Cells[0].Value.ToString()), int.Parse(dgv_Target.Rows[i].Cells[1].Value.ToString()), dgv_Target.Rows[i].Cells[2].Value.ToString(), int.Parse(dgv_Target.Rows[i].Cells[3].Value.ToString()), DateTime.Now, int.Parse(dgv_Target.Rows[i].Cells[5].Value.ToString())) == 1)
                {
                    //progressBar1.Value++;
                }
                else
                {
                    error = true;
                    errorKeys.Add(dgv_Target.Rows[i].Cells[2].Value.ToString());
                }
            }

            if (error)
            {
                string tmp = "\n";
                for (int k = 0; k < errorKeys.Count; k++)
                {
                    tmp += errorKeys[k] + "\n";
                }
                MessageBox.Show("Возникла какая-то ошибка и не все ключи были обновлены. Ниже приведены не обновленные ключи:" + tmp, "Ошибка");
            }

            //теперь записываем "новые" ключи
            CreateNewKeywordsInDB();
        }
コード例 #2
0
        /* Обновляем уже существующие ключи, которые лежат в dgv_Target */
        private void UpdateExistingKeywordsInDB(int _newKeysCount, List <SemCoreModel> _scAddedList)
        {
            bool error                = false; //признак того, что при обновлении ключей возникла ошибка(-и)
            int  newKyesCount         = _newKeysCount;
            int  editedKeysCount      = 0;
            int  editedWrongKeysCount = 0;

            List <string[, ]> errorKeys = new List <string[, ]> {
            };                                                            //список ключей, которые не были обновлены

            scExistingFromDBList = new List <SemCoreModel> {
            };
            IDataRecord dr;

            string wrongProdType = "";
            string wrongCategory = "";

            for (int i = 0; i < scUpdateList.Count; i++)
            {
                dr = scController.GetSemCoreByKeyword(scUpdateList[i].Keyword);

                if (dr != null)
                {
                    scExistingFromDBList.Add(new SemCoreModel());

                    scExistingFromDBList[scExistingFromDBList.Count - 1].ProductTypeId = int.Parse(dr[0].ToString());
                    scExistingFromDBList[scExistingFromDBList.Count - 1].CategoryId    = int.Parse(dr[1].ToString());
                    scExistingFromDBList[scExistingFromDBList.Count - 1].Keyword       = dr[2].ToString();
                    scExistingFromDBList[scExistingFromDBList.Count - 1].Value         = scUpdateList[i].Value;
                    scExistingFromDBList[scExistingFromDBList.Count - 1].LastUpdated   = scUpdateList[i].LastUpdated;
                    scExistingFromDBList[scExistingFromDBList.Count - 1].SemCoreId     = int.Parse(dr[5].ToString());
                }
            }



            for (int i = 0; i < scExistingFromDBList.Count; i++)
            {
                if (scController.UpdateExistingKeywordBySemCoreId(scExistingFromDBList[i].ProductTypeId, scExistingFromDBList[i].CategoryId, scExistingFromDBList[i].Keyword, scExistingFromDBList[i].Value, DateTime.Now, scExistingFromDBList[i].SemCoreId) != 1)
                {
                    //some error
                }
                else
                {
                    editedKeysCount++;
                    if (scExistingFromDBList[i].ProductTypeId != GetSelectedProductTypeId())
                    {
                        wrongProdType += scExistingFromDBList[i].Keyword + "\n";
                        error          = true;
                        editedWrongKeysCount++;
                        errorKeys.Add(new string[1, 2]);
                        errorKeys[errorKeys.Count - 1].SetValue(scExistingFromDBList[i].Keyword, 0, 0);
                        errorKeys[errorKeys.Count - 1].SetValue(scExistingFromDBList[i].Value.ToString(), 0, 1);
                    }
                    else if (scExistingFromDBList[i].CategoryId != GetSelectedCategoryId())
                    {
                        wrongCategory += scExistingFromDBList[i].Keyword + "\n";
                        error          = true;
                        editedWrongKeysCount++;
                        errorKeys.Add(new string[1, 2]);
                        errorKeys[errorKeys.Count - 1].SetValue(scExistingFromDBList[i].Keyword, 0, 0);
                        errorKeys[errorKeys.Count - 1].SetValue(scExistingFromDBList[i].Value.ToString(), 0, 1);
                    }

                    //сюда для АРХИВА - обновляем
                    scaController.UpdateExistingKeywordBySemCoreId(scExistingFromDBList[i].ProductTypeId, scExistingFromDBList[i].CategoryId, scExistingFromDBList[i].Keyword, scExistingFromDBList[i].Value, DateTime.Now, scExistingFromDBList[i].SemCoreId);
                }
            }

            if (error)
            {
                MessageBox.Show("Добавлено новых ключей: " + newKyesCount + "\nОбновлено ключей: " + editedKeysCount + "\nИз них - " + editedWrongKeysCount + " - находятся не в заданной категории ключей/виде товаров. Эти ключи были помещены в таблицу \"Обновленные ключи\"");
                dgv_Source.Rows.Clear();
                dgv_Target.Rows.Clear();
                Fill_dgv_Source_ByExistingKeys(errorKeys);
                Fill_dgv_Source_ByAddedKeys(_scAddedList);
            }
            else
            {
                MessageBox.Show("Добавлено новых ключей: " + newKyesCount + "\nОбновлено ключей: " + editedKeysCount);
                dgv_Source.Rows.Clear();
                dgv_Target.Rows.Clear();
                Fill_dgv_Source_ByExistingKeys(errorKeys);
                Fill_dgv_Source_ByAddedKeys(_scAddedList);
            }
        }