在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例常用C#方法 → 实现PC和手机端产品、订单等数据同步

实现PC和手机端产品、订单等数据同步

常用C#方法

下载此实例
  • 开发语言:C#
  • 实例大小:10.90M
  • 下载次数:60
  • 浏览次数:544
  • 发布时间:2019-01-22
  • 实例类别:常用C#方法
  • 发 布 人:fishloving
  • 文件格式:.rar
  • 所需积分:20
 相关标签: c 手机 数据 同步

实例介绍

【实例简介】实现PC和手机端产品、订单等数据同步

【实例截图】

from clipboard


【核心代码】
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();
        }
    }
}

标签: c 手机 数据 同步

实例下载地址

实现PC和手机端产品、订单等数据同步

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警