У меня есть один XML-файл.Файл содержит название продукта, цену продукта.
Я обновляю цену продукта для всех продуктов. Но я хочу отображать счетчик после каждой обновленной записи.
как если у меня есть 10 продуктов в файле XMLтогда будет отображаться
, затем
инаконец, будет показано 10 обновленных из 10.
Я показываю индикатор выполнения, но я хочу также отображать количество записей во время обновления.
Ниже приведен код C #.
Здесь я загружаю xml-файл, затем он читает узел productcode
и обновляет цену, указав то, что мы ввели в текстовом поле.
После обновления цены каждого продукта я хочу отобразить количество записей.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using APIReaderLib;
using APIReaderLib.DataObjects;
namespace VAPIReader
{
public partial class UpdateProducts : Form
{
public UpdateProducts()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
XmlDocument m_xmld = null;
XmlNodeList m_nodelist = null;
XmlNode m_node = null;
XMLPostManager manager = new XMLPostManager();
m_xmld = new XmlDocument();
m_xmld.Load("C:\\Users\\pooja.b.EDREAMZ\\Desktop\\s&p\\Final1.xml");
m_nodelist = m_xmld.SelectNodes("/xmldata/Products");
foreach (XmlNode m_node_loopVariable in m_nodelist)
{
m_node = m_node_loopVariable;
string Productcode = m_node.ChildNodes.Item(0).InnerText;
string productprice = m_node.ChildNodes.Item(1).InnerText;
Console.Write(" Product Code: " + Productcode + "Product Price:" + productprice);
decimal strprice =Convert.ToDecimal( productprice);
decimal strtextprice = Convert.ToDecimal(textBox1.Text);
decimal test = strprice + (strprice * strtextprice/100);
string updatedprice = test.ToString();
UpdateProduct(updatedprice, Productcode);
XmlDocument readDoc = new XmlDocument();
readDoc.Load("C:\\Users\\pooja.b.EDREAMZ\\Desktop\\s&p\\Final1.xml");
int count = readDoc.SelectNodes("/xmldata/Products").Count;
progressBar1.Minimum = 1;
// Set Maximum to the total number of Users created.
progressBar1.Maximum = count;
// Set the initial value of the ProgressBar.
progressBar1.Step = 1;
progressBar1.PerformStep();
// Updates the label to show that a file was read.
label2.Text = Convert.ToString(progressBar1.Value) + "updated of " + count;
}
}
catch (Exception ex)
{
MessageBox.Show("Error updating product " + ex.Message);
}
this.Close();
System.Windows.Forms.MessageBox.Show("Complete!");
}
private void UpdateProduct(string price, string Productcode)
{
xmldata1 data = new xmldata1();
data.Items = new xmldataProducts[1];
data.Items[0] = new xmldataProducts();
data.Items[0].ProductPrice = price;
data.Items[0].ProductCode = Productcode;
string productXML = Utils.GetProductXML(data);
string APIURL = Utils.GetAPIPostURL(ImportMode.Update);
XMLPostManager manager = new XMLPostManager();
string response = manager.SendXMLToURL(APIURL, productXML);
}
}
}
Пожалуйста, сообщите.