2025-03-28 09:49:56 +08:00

107 lines
4.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DataUpdate
{
public partial class BarcodeMatch : Form
{
static QualityHelper _QualityHelper = new QualityHelper();
string webserviceURL = "http://" + _QualityHelper.dbip + ":" + _QualityHelper.serviceport + "/Service.asmx";
WaiteFrom _WaitForm;
public BarcodeMatch()
{
InitializeComponent();
if(CommodityUpdate())
{
Environment.Exit(0);
}
}
public void ShowWaiteForm()
{
_WaitForm = WaiteFrom.GetInstance();
//设置WaitForm的父窗体为当前窗体以便在WaitForm中使用父窗体对象
_WaitForm.TopMost = true;
_WaitForm.Owner = this;
_WaitForm.ShowMessage("加载中......");
_WaitForm.Show();
Application.DoEvents();
_WaitForm.Refresh();
}
#region
/// <summary>
/// 未知商品自动校正
/// </summary>
private bool CommodityUpdate()
{
string _Result = "";
QualityHelper qualityHelper = new QualityHelper();
string _selectsql = "select commodity_barcode from t_commodityex where commodity_name like '%未知商品%' ";// and datalength(commodity_barcode) >= 8";
ShowWaiteForm();
_WaitForm.ShowMessage("正在验证商品信息......");
try
{
using (DataTable _DataTable = DBHelper.QueryOdbc(_selectsql).Tables[0])
{
if (_DataTable.Rows.Count > 0)
{
for (int i = 0; i < _DataTable.Rows.Count; i++)
{
_WaitForm.ShowMessage("正在更新商品信息......(" + i + "/" + _DataTable.Rows.Count + ")");
string[] _barcode = { _DataTable.Rows[i]["commodity_barcode"].ToString().Trim() };
try
{
//_Result = WSHelper.InvokeWebService("http://localhost:7080/EShangTechService/Service.asmx", "querypay", _barcode).ToString();
_Result = WSHelper.InvokeWebService("http://" + qualityHelper.dbip + ":" + qualityHelper.serviceport + "/Service.asmx", "BarcodeLibraryQuery", _barcode).ToString();
}
catch (Exception ex)
{
LogHelper.WriteServiceLog("校对商品信息:" + ex.Message);
_Result = "";
}
using (DataTable _ResultTable = JsonHelper.JsonToDataTable(_Result))
{
if (_ResultTable.Rows.Count > 0)
{
for (int j = 0; j < _ResultTable.Rows.Count; j++)
{
string _updatesql = "UPDATE T_COMMODITYEX " +
"SET " +
"COMMODITY_TYPE = '" + _ResultTable.Rows[j]["COMMODITY_TYPE"].ToString() + "'," +
"COMMODITY_NAME = '" + _ResultTable.Rows[j]["COMMODITY_NAME"].ToString() + "', " +
"COMMODITY_RULE = '" + _ResultTable.Rows[j]["COMMODITY_RULE"].ToString() + "', " +
"COMMODITY_UNIT = '" + _ResultTable.Rows[j]["COMMODITY_UNIT"].ToString() + "' , " +
"DOWNLOADDATE = DATETIME('" + DateTime.Now.ToString() + "') " +
"WHERE " +
"COMMODITY_BARCODE = '" + _DataTable.Rows[i]["commodity_barcode"].ToString() + "'";
DBHelper.ExecuteSqlTran(_updatesql);
}
}
}
}
}
for (int i = 5; i > 0; i--)
{
_WaitForm.ShowMessage("商品信息匹配完成,(" + i + ")秒后自动返回收银系统。");
System.Threading.Thread.Sleep(1 * 1000);
}
}
}
catch (Exception ex)
{
LogHelper.WriteServiceLog("校对商品信息:" + ex.Message);
}
_WaitForm.Close();
_WaitForm.Dispose();
return true;
}
#endregion
}
}