基本信息
源码名称:实现PC和手机端产品、订单等数据同步
源码大小:10.90M
文件格式:.rar
开发语言:C#
更新时间:2019-01-22
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 20 元×
微信扫码支付:20 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
实现PC和手机端产品、订单等数据同步
实现PC和手机端产品、订单等数据同步
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 Newtonsoft.Json;
using System.Threading;
using System.Reflection;
using Newtonsoft.Json.Converters;
namespace CCS2012
{
public partial class FrmEccsCustRelate : CCS2012.formBaseDefault
{
//定义Ccs客户数据集
DataSet lsv_CcsCust = new DataSet();
//定义Eccs客户数据集
DataSet lsv_EccsCust = new DataSet();
//定义上传客户代号数据集
DataSet lsv_dsUploadCust = new DataSet();
//定义表单英文名称
string lcv_cFrmEname = "FrmEccsCustRelate";
//定义关联按钮
private Button CorrelationBtn = new Button();
//定义取消关联按钮
private Button CancelBtn = new Button();
//定义查询数组
DataRow[] lrv_RowArry = null;
string[] tArryFilter = null;
/// <summary>
/// 界面初始化
/// </summary>
public FrmEccsCustRelate()
{
InitializeComponent();
LogInfor lov_LogInfor = new LogInfor();
lov_LogInfor.CcsUserCode = Pubvar.pUserId;
lov_LogInfor.CcsUserPass = Pubvar.pUserPass;
lov_LogInfor.BrandMakerCode = Pubvar.BusinessCode;
string tPramJson = JsonConvert.SerializeObject(lov_LogInfor);
//上传用户身份验证,关联Eccs账号:
if (!Pubvar.accWeb.EccsUserLog(tPramJson))
{
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
}
/// <summary>
/// 下载数据
/// </summary>
private void FrmEccsCustRelate_Load(object sender, EventArgs e)
{
try
{
//绑定数据
this.holyesDataGridView1.initDataGrid("temp");
this.loadState1.optMode = 1;
this.loadState1.start();
}
catch (Exception ex)
{
//处理表0异常
Pubvar.MyMsgbox(ex.Message);
}
}
/// <summary>
/// 关闭按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolButtonExit1_Click(object sender, EventArgs e)
{
this.Exit();
}
/// <summary>
/// 无论在主线程和其它线程,只要执行了这句,都可以把程序结束干净
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmEccsCustRelate_FormClosing(object sender, FormClosingEventArgs e)
{
this.Exit();
}
/// <summary>
/// 关联客户
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolButtonTongbu_Click(object sender, EventArgs e)
{
try
{
toolButtonTongbu.Enabled = false;
loadState1.optMode = 2;
loadState1.start();
}
catch (Exception ex)
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(ex.Message.ToString().Trim());
return;
}
}
/// <summary>
/// 取消客户关联
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolButtonOutPut1_Click(object sender, EventArgs e)
{
try
{
if (holyesDataGridView1.Rows.Count <= 0)
{
Pubvar.MyMsgbox("Eccs客户列表没有数据,请先用手机端邀请客户!");
return;
}
toolButtonOutPut1.Enabled = false;
loadState1.optMode = 3;
loadState1.start();
}
catch (Exception ex)
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(ex.Message);
}
}
/// <summary>
/// 程序托管函数,自动加载数据
/// </summary>
private void loadState1_GetServerDatas()
{
try
{
switch (loadState1.optMode)
{
case 1:
//加载Eccs用户数据集
lsv_EccsCust.Tables.Clear();
if (!Pubvar.accWeb.EccsDownLoadDatasForFilter(AccessWeb.AccessWeb.ModeName.BASE, "GetEccsCustRelate", loadState1, ref lsv_EccsCust))
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
//添加客户名称列ccsCustName
lsv_EccsCust.Tables[0].Columns.Add("ccsCustName");
//添加原客户代号列OldCcsCustId
lsv_EccsCust.Tables[0].Columns.Add("OldCcsCustId");
//已关联用户下载CCS客户数据集
lsv_CcsCust.Tables.Clear();
if (!Pubvar.accWeb.DownLoadDatasForArry(AccessWeb.AccessWeb.ModeName.BASE, "FrmEccsCustRelate", tArryFilter, this.loadState1, ref lsv_CcsCust))
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
break;
case 2://关联客户
//定义临时表ldv_dtCompany:保存ECCS用户代号\CCS系统客户代号\CCS系统客户代号
DataTable ldv_dtCompany = new DataTable();
ldv_dtCompany.Columns.Add("UserId"); //添加列名 :ECCS用户代号
ldv_dtCompany.Columns.Add("NewCcsCustId"); //添加列名 :CCS系统客户代号
ldv_dtCompany.Columns.Add("OldCcsCustId"); //添加列名 :CCS系统客户代号
//加载Eccs用户、Ccs客户选择视框
FrmCCSCustChooseFilerter frm = new FrmCCSCustChooseFilerter();
frm.IsMemory = false;//不缓存数据
frm.setArryCondition = new string[] { "" };
frm.ShowDialog();
if (frm.getState)
{
DataRow lrv_drNewRow = ldv_dtCompany.NewRow(); //新增行
DataRow lov_drRecno2 = frm.getChooseValue2[0]; //Eccs用户
DataRow lov_drRecno = frm.getChooseValue[0]; //Ccs客户
//已关联判断
string cRecnoCondition = "";
for (int nI = 0; nI < lsv_EccsCust.Tables[0].Rows.Count; nI )
{
cRecnoCondition = "UserId" "='" lov_drRecno2["UserId"].ToString().Trim() "'" " and " "ccsCustId" "='" lov_drRecno["AgentId"].ToString().Trim() "'";
if (lsv_EccsCust.Tables[0].Select(cRecnoCondition).Length > 0)
{
Pubvar.MyMsgbox("当前的Eccs用户:" lov_drRecno2["UserName"] ",已有与之关联相同的CCS客户:" lov_drRecno["AgentName"] ",请重新关联!");
return ;
}
}
if (frm.getChooseValue2.Length > 0)
{
lrv_drNewRow["UserId"] = lov_drRecno2["UserId"].ToString().Trim();
}
if (frm.getChooseValue.Length > 0)
{
lrv_drNewRow["NewCcsCustId"] = lov_drRecno["AgentId"].ToString().Trim();
lrv_drNewRow["OldCcsCustId"] = "";
}
ldv_dtCompany.Rows.Add(lrv_drNewRow);
}
//将临时表ldv_dtCompany转换为lsv_dsUploadCust
DataSet lsv_dsUploadCust = new DataSet();
lsv_dsUploadCust.Tables.Add(ldv_dtCompany);
//没选中判断
if (lsv_dsUploadCust.Tables[0].Rows.Count == 0)
{
Pubvar.MyMsgbox("客户列表没有选中数据!请您选择!");
return;
}
//网格客户数据集同步至ECCS
if (!Pubvar.accWeb.EccsUpLoadDatas(AccessWeb.AccessWeb.ModeName.BASE, "FrmEccsCustRelate", lsv_dsUploadCust, this.loadState1))
{
loadState1.optMode = -1;
//服务器关联失败:返回失败原因,
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
//服务器关联成功无返回,添加成功提示
//Pubvar.MyMsgbox(Pubvar.accWeb.RightMsg);
Pubvar.MyMsgbox("关联客户成功");
//重新加载客户数据集--重写逻辑
lsv_EccsCust.Tables.Clear();
if (!Pubvar.accWeb.EccsDownLoadDatasForFilter(AccessWeb.AccessWeb.ModeName.BASE, "GetEccsCustRelate", loadState1, ref lsv_EccsCust))
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
//添加客户名称列ccsCustName
lsv_EccsCust.Tables[0].Columns.Add("ccsCustName");
//添加原客户代号列OldCcsCustId
lsv_EccsCust.Tables[0].Columns.Add("OldCcsCustId");
//已关联用户下载CCS客户数据集
lsv_CcsCust.Tables.Clear();
if (!Pubvar.accWeb.DownLoadDatasForArry(AccessWeb.AccessWeb.ModeName.BASE, "FrmEccsCustRelate", tArryFilter, this.loadState1, ref lsv_CcsCust))
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
break;
case 3://取消客户关联
//定义当前选中行
int lrv_drGetSelectedRows = this.holyesDataGridView1.CurrentRow.Index;
//删前提示
if (this.holyesDataGridView1.Rows.Count == 0)
{
Pubvar.MyMsgbox("当前客户列表没有数据,无法取消关联!");
return;
}
else
{
DialogResult result;
result = MessageBox.Show("确定要取消关联当前选择的CCS客户吗?", "消息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.No)
{
return;
}
}
//定义临时表ldv_dtCompany:保存ECCS用户代号\CCS系统客户代号\CCS系统客户代号
DataTable ldv_dtCompanys = new DataTable();
ldv_dtCompanys.Columns.Add("UserId"); //添加列名 :ECCS用户代号
ldv_dtCompanys.Columns.Add("NewCcsCustId"); //添加列名 :CCS系统客户代号
ldv_dtCompanys.Columns.Add("OldCcsCustId"); //添加列名 :CCS系统客户代号
DataRow lrv_drNewRows = ldv_dtCompanys.NewRow();
//因为CCS客户界面没有为空选项,不管选择的客户为何值,取消关联时,传空值
lrv_drNewRows["NewCcsCustId"] = "";
lrv_drNewRows["UserId"] = lsv_EccsCust.Tables[0].Rows[lrv_drGetSelectedRows]["UserId"];
lrv_drNewRows["OldCcsCustId"] = lsv_EccsCust.Tables[0].Rows[lrv_drGetSelectedRows]["OldCcsCustId"];
ldv_dtCompanys.Rows.Add(lrv_drNewRows);
lsv_EccsCust.Tables[0].Rows[lrv_drGetSelectedRows].Delete();
//将临时表ldv_dtCompany转换为lsv_dsUploadCust
DataSet lsv_dsUploadCusts = new DataSet();
lsv_dsUploadCusts.Tables.Add(ldv_dtCompanys);
//没选中判断
if (lsv_dsUploadCusts.Tables[0].Rows.Count == 0)
{
Pubvar.MyMsgbox("客户列表没有Eccs用户数据!请您从新拉取!");
}
//取消关联
if (!Pubvar.accWeb.EccsUpLoadDatas(AccessWeb.AccessWeb.ModeName.BASE, "FrmEccsCustRelate", lsv_dsUploadCusts, this.loadState1))
{
loadState1.optMode = -1;
//服务器返回失败提示,这里Pubvar.accWeb.ErrMsg无返回
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
//服务器返回:取消关联成功,实际这里Pubvar.accWeb.RightMsg无返回,增加返回
//Pubvar.MyMsgbox(Pubvar.accWeb.RightMsg);
Pubvar.MyMsgbox("取消关联成功");
//重新加载客户数据集--重写逻辑
lsv_EccsCust.Tables.Clear();
if (!Pubvar.accWeb.EccsDownLoadDatasForFilter(AccessWeb.AccessWeb.ModeName.BASE, "GetEccsCustRelate", loadState1, ref lsv_EccsCust))
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
//添加客户名称列ccsCustName
lsv_EccsCust.Tables[0].Columns.Add("ccsCustName");
//添加原客户代号列OldCcsCustId
lsv_EccsCust.Tables[0].Columns.Add("OldCcsCustId");
//已关联用户下载CCS客户数据集
lsv_CcsCust.Tables.Clear();
if (!Pubvar.accWeb.DownLoadDatasForArry(AccessWeb.AccessWeb.ModeName.BASE, "FrmEccsCustRelate", tArryFilter, this.loadState1, ref lsv_CcsCust))
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(Pubvar.accWeb.ErrMsg);
return;
}
break;
default:
break;
}
}
catch (Exception ex)
{
holyesDataGridView1.Enabled = true;
this.loadState1.optMode = -1;//-1,表示获取服务端数据发生过错误,这个很重要。
Pubvar.MyMsgbox(ex.Message);
}
}
/// <summary>
/// 重新加载
/// </summary>
private void loadState1_DisplayDatas()
{
try
{
switch(loadState1.optMode)
{
case 1://绑定网格,成功无提示
for (int nI = 0; nI <= lsv_EccsCust.Tables[0].Rows.Count - 1; nI )
{
//一对多选择判断
if (lsv_CcsCust.Tables[0].Select("AgentId" "='" lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"] "'").Length > 0)
{
DataTable ldv_dtCompany = lsv_CcsCust.Tables[0];
DataRow[] lrv_dataRow = ldv_dtCompany.Select("AgentId" "='" lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"] "'");
DataTable ldv_dtNew = ldv_dtCompany.Clone();
for (int nJ = 0; nJ < lrv_dataRow.Length; nJ )
{
ldv_dtNew.ImportRow(lrv_dataRow[nJ]);
}
//已关联加载客户名
lsv_EccsCust.Tables[0].Rows[nI]["ccsCustName"] = ldv_dtNew.Rows[0]["AgentName"];
}
//保存原客户代号
lsv_EccsCust.Tables[0].Rows[nI]["OldCcsCustId"] = lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"];
//未关联不显示
if (lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"].ToString().Trim() == "")
{
//未关联赋初值
lsv_EccsCust.Tables[0].Rows[nI].Delete();
}
}
//绑定网格:
this.BindingContext[lsv_EccsCust, lsv_EccsCust.Tables[0].TableName.Trim()].Position = lsv_EccsCust.Tables[0].Rows.Count - 1;
this.holyesDataGridView1.CreatDataGrid(lsv_EccsCust.Tables[0].TableName.Trim(), lsv_EccsCust);
//网格按钮控件
this.holyesDataGridView1.Columns["OldCcsCustId"].Visible = false;
break;
case 2:
//系统返回关联客户成功 无提示
for (int nI = 0; nI <= lsv_EccsCust.Tables[0].Rows.Count - 1; nI )
{
//一对多选择判断
if (lsv_CcsCust.Tables[0].Select("AgentId" "='" lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"] "'").Length > 0)
{
DataTable ldv_dtCompany = lsv_CcsCust.Tables[0];
DataRow[] lrv_dataRow = ldv_dtCompany.Select("AgentId" "='" lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"] "'");
DataTable ldv_dtNew = ldv_dtCompany.Clone();
for (int nJ = 0; nJ < lrv_dataRow.Length; nJ )
{
ldv_dtNew.ImportRow(lrv_dataRow[nJ]);
}
//已关联加载客户名
lsv_EccsCust.Tables[0].Rows[nI]["ccsCustName"] = ldv_dtNew.Rows[0]["AgentName"];
}
//保存原客户代号
lsv_EccsCust.Tables[0].Rows[nI]["OldCcsCustId"] = lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"];
//未关联不显示
if (lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"].ToString().Trim() == "")
{
//未关联赋初值
lsv_EccsCust.Tables[0].Rows[nI].Delete();
}
}
//绑定网格:
this.BindingContext[lsv_EccsCust, lsv_EccsCust.Tables[0].TableName.Trim()].Position = lsv_EccsCust.Tables[0].Rows.Count - 1;
this.holyesDataGridView1.CreatDataGrid(lsv_EccsCust.Tables[0].TableName.Trim(), lsv_EccsCust);
//网格按钮控件
this.holyesDataGridView1.Columns["OldCcsCustId"].Visible = false;
toolButtonTongbu.Enabled = true;
CorrelationBtn.Visible = false;
break;
case 3:
for (int nI = 0; nI <= lsv_EccsCust.Tables[0].Rows.Count - 1; nI )
{
//一对多选择判断
if (lsv_CcsCust.Tables[0].Select("AgentId" "='" lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"] "'").Length > 0)
{
DataTable ldv_dtCompany = lsv_CcsCust.Tables[0];
DataRow[] lrv_dataRow = ldv_dtCompany.Select("AgentId" "='" lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"] "'");
DataTable ldv_dtNew = ldv_dtCompany.Clone();
for (int nJ = 0; nJ < lrv_dataRow.Length; nJ )
{
ldv_dtNew.ImportRow(lrv_dataRow[nJ]);
}
//已关联加载客户名
lsv_EccsCust.Tables[0].Rows[nI]["ccsCustName"] = ldv_dtNew.Rows[0]["AgentName"];
}
//保存原客户代号
lsv_EccsCust.Tables[0].Rows[nI]["OldCcsCustId"] = lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"];
//未关联不显示
if (lsv_EccsCust.Tables[0].Rows[nI]["ccsCustId"].ToString().Trim() == "")
{
//未关联赋初值
lsv_EccsCust.Tables[0].Rows[nI].Delete();
}
}
//绑定网格:
this.BindingContext[lsv_EccsCust, lsv_EccsCust.Tables[0].TableName.Trim()].Position = lsv_EccsCust.Tables[0].Rows.Count - 1;
this.holyesDataGridView1.CreatDataGrid(lsv_EccsCust.Tables[0].TableName.Trim(), lsv_EccsCust);
//网格按钮控件
this.holyesDataGridView1.Columns["OldCcsCustId"].Visible = false;
toolButtonOutPut1.Enabled = true;
break;
case -1:
toolButtonTongbu.Enabled = true;
toolButtonOutPut1.Enabled = true;
break;
default :
break;
}
holyesDataGridView1.Focus();
holyesDataGridView1.Refresh();
}
catch (Exception ex)
{
loadState1.optMode = -1;
Pubvar.MyMsgbox(ex.Message);
return;
}
}
/// <summary>
/// 查找按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolButtonFind1_Click(object sender, EventArgs e)
{
if (holyesDataGridView1.Rows.Count == 0)
{
Pubvar.MyMsgbox("无数据查找!");
return;
}
FindRecno(this, this.holyesDataGridView1);
}
/// <summary>
/// 导出功能按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolButtonFind2_Click(object sender, EventArgs e)
{
if (holyesDataGridView1.Rows.Count == 0)
{
Pubvar.MyMsgbox("无数据导出!");
return;
}
ToExcel(Pubvar.pCompanyType, Pubvar.pCompanyId, this.holyesDataGridView1, this.Text);
}
/// <summary>
/// 关闭退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolButtonExit1_Click_1(object sender, EventArgs e)
{
this.Exit();
}
}
}