Beispiel #1
0
        /// <summary>
        /// 导出单日销售明细数据,并上传服务器
        /// </summary>
        public static bool UploadSalesDay(ref string message, string date = "")
        {
            bool ret = true;

            int    result   = 0;
            string filePath = "";

            if (date != "")
            {
                int year;
                int month;
                int day;

                year  = Convert.ToInt32(date.Substring(0, 4));
                month = Convert.ToInt32(date.Substring(4, 2));
                day   = Convert.ToInt32(date.Substring(6, 2));

                GlobalParams.DayDesignate = new DateTime(year, month, day);

                filePath = GlobalParams.xbDesignateLocalPath;

                //复制原始文件到单次销售明细 dbf 文件本地保存路径(覆盖)
                //dbf文件无法真正删除老数据,每次上传前先使用比较小的原始文件
                File.Copy(GlobalParams.xsxbIniPath, filePath, true);

                //导出 指定日期 单日销售明细数据到本地 DBF 文件
                result = new DataOperator().SalesDayDesignatetoDBF(date);
            }
            else
            {
                filePath = GlobalParams.xbLocalPath;

                //复制原始文件到单次销售明细 dbf 文件本地保存路径(覆盖)
                //dbf文件无法真正删除老数据,每次上传前先使用比较小的原始文件
                File.Copy(GlobalParams.xsxbIniPath, filePath, true);

                //导出单日销售明细数据到本地 DBF 文件
                result = new DataOperator().SalesDaytoDBF();
            }

            if (result > 0)
            {
                if (File.Exists(filePath))
                {
                    try
                    {
                        if (date != "")
                        {
                            File.Copy(filePath, GlobalParams.xbDesignateServerPath, true);
                        }
                        else
                        {
                            File.Copy(filePath, GlobalParams.xbServerPath, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteErrorLog(ex.Message, ex.Source, "上传单日销售明细数据");
                        message = ex.Message;
                        ret     = false;
                    }
                }
                else
                {
                    ret     = false;
                    message = "本地文件不存在";
                    Log.WriteErrorLog("上传单日销售明细数据,本地文件不存在");
                }
            }
            else
            {
                ret = false;

                //删除之前复制的文件
                File.Delete(filePath);

                switch (result)
                {
                case 0:
                    message = "暂无数据";
                    break;

                case -1:
                    message = "DBF 文件不存在或路径出错";
                    break;

                case -2:
                    message = "ODBC 连接 DBF 文件出错";
                    break;
                }
            }

            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// 重新上传状态(文件夹有 xsxb.dbf 或者 error.tab),更新本地 xsxb.dbf
        /// </summary>
        /// <returns></returns>
        public static int ReUploadOperation(string source)
        {
            int  ret   = 0;
            bool error = false;

            if (new SalesBLL().SelectSalesBackups() == 0 && new SalesBLL().SelectSalesUnsure() == 0)
            {
                error = true;
                Log.WriteNormalLog("本地没有历史数据无法重新上传,出现数据丢失,后台请核对", "ReUploadOperation()", source);
                MessageBox.Show("可能出现数据丢失,请前往后台回收数据,然后核对");
            }

            //将新数据追加到 backups 里
            int r = new SalesBLL().TimeToBackups();

            if (r > 0)
            {
                ret = 7;
                Log.WriteNormalLog("新数据追加到 backups 表", "ReUploadOperation()", source);
            }
            else if (r < 0)
            {
                Log.WriteErrorLog("新数据追加到 backups 表", source, "ReUploadOperation()");
            }
            else
            {
                ret = 8;//没有新数据
            }
            if (error)
            {
                ret = 6;
            }

            //将 unsure 表数据追加到 backups 里
            if (new SalesBLL().UnsureToBackups() > 0)
            {
                //如果 unsure 表里有数据,追加后就清空
                new SalesBLL().DeleteSalesUnsure();

                ret = 5;
                Log.WriteNormalLog("unsure 表数据追加到 backups 表,然后清空 unsure 表", "ReUploadOperation()", source);
            }



            //复制原始文件到单次销售明细 dbf 文件本地保存路径(覆盖)
            //dbf文件无法真正删除老数据,每次上传前先使用比较小的原始文件
            File.Copy(GlobalParams.xsxbIniPath, GlobalParams.xsxbPath, true);

            try
            {
                //导出单次销售明细数据到本地 DBF 文件
                r = new DataOperator().SalesBackupstoDBF();

                if (r > 0)
                {
                    Log.WriteNormalLog("导出数据到本地 DBF 文件", "ReUploadOperation()", source);
                }
            }
            catch (Exception ex)
            {
                ret = -2;
                Log.WriteErrorLog(ex.Message, ex.Source, "ReUploadOperation()");
            }

            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// 前后台交互,上传销售明细数据
        /// </summary>
        /// <param name="flag">是否是 forSure 的交互</param>
        /// <returns></returns>
        public static int Upload(string source)
        {
            //1 不能访问
            //2 有 control.tab
            //3 有 error.tab
            //4 后台未回收数据
            //5 正常状态
            //A:1,2; B:3,4; C:5
            int state = 0;

            //-1 A 查询 unsure 表数据出错
            //-2 B 导出数据到本地 DBF 文件出错
            //-3 C 查询 unsure 表数据出错
            //-4 C 导出数据到本地 DBF 文件出错
            //-5 C backups 表没有数据, 停止导出
            //1 A 新数据追加到 backups 表
            //2 A 没有新数据可追加
            //3 A 将 backups 数据存入 unsure 表
            //4 A 将新数据存入 unsure 表
            //5 B unsure 表数据追加到 backups 表,然后清空 unsure 表
            //6 B 本地没有历史数据无法重新上传,出现数据丢失,后台请核对
            //7 B 新数据追加到 backups 表
            //8 B 没有新数据
            //9 C 清空 unsure 表,新数据追加到 backups 表
            //10 C 没有新数据可追加
            //11 C 新数据覆盖 backups 表
            //12 C 没有新数据可覆盖
            int ret = 0;

            #region 开始交互
            //服务端文件夹是否可以访问
            DirectoryInfo dataDirectory = new DirectoryInfo(GlobalParams.ServerPath);

            //不能访问-不确定状态
            if (!dataDirectory.Exists)
            {
                state = 1;
                Log.WriteNormalLog(string.Format("无法连接服务端文件夹:{0},停止与后台交互",
                                                 GlobalParams.ServerPath), "Upload()", source);

                //不确定状态下的操作
                ret = DataOperator.UnsureOperation(source);
            }
            //可以访问
            else
            {
                FileInfo[]    files     = dataDirectory.GetFiles();
                List <string> filesName = new List <string>();

                foreach (FileInfo f in files)
                {
                    filesName.Add(f.Name);
                }

                //有 control.tab - 不确定状态
                if (filesName.Contains("control.tab"))
                {
                    state = 2;
                    Log.WriteNormalLog(string.Format("后台正在操作服务端文件夹:{0},停止与后台交互",
                                                     GlobalParams.ServerPath), "Upload()", source);

                    //不确定状态下的操作
                    ret = DataOperator.UnsureOperation(source);
                }
                //有 xsxb.dbf 或者 error.tab - 重新上传状态
                else if (filesName.Contains("xsxb.dbf") || filesName.Contains("error.tab"))
                {
                    if (filesName.Contains("error.tab"))
                    {
                        state = 3;
                        Log.WriteNormalLog("出现 error.tab,准备重新上传数据", "Upload()", source);
                    }
                    else
                    {
                        state = 4;
                        Log.WriteNormalLog("后台未回收数据,准备重新上传数据", "Upload()", source);
                    }

                    PutPosTab("Upload()", source);

                    //重新上传状态下的操作
                    ret = DataOperator.ReUploadOperation(source);

                    if (ret > 0)
                    {
                        try
                        {
                            //上传文件
                            File.Copy(GlobalParams.xsxbPath, GlobalParams.xsxbServerPath, true);
                            Log.WriteNormalLog("上传销售明细数据完毕", "Upload()", source);
                        }
                        catch (Exception ex)
                        {
                            Log.WriteErrorLog(ex.Message, ex.Source, "上传本地 DBF 文件到服务端");
                        }

                        if (filesName.Contains("error.tab"))
                        {
                            File.Delete(GlobalParams.ServerPath + "error.tab");
                            Log.WriteNormalLog("删除 error.tab", "Upload()", source);
                        }
                    }

                    DeletePosTab("Upload()", source);
                }
                //没有 control.tab 、xsxb.dbf、error.tab -正常状态
                else
                {
                    state = 5;
                    Log.WriteNormalLog("准备上传新数据", "Upload()", source);

                    PutPosTab("Upload()", source);

                    //正常状态下的操作
                    ret = DataOperator.EmptyOperation(source);

                    if (ret > 0)
                    {
                        try
                        {
                            //上传文件
                            File.Copy(GlobalParams.xsxbPath, GlobalParams.xsxbServerPath, true);
                        }
                        catch (Exception ex)
                        {
                            Log.WriteErrorLog(ex.Message, ex.Source, "上传本地 DBF 文件到服务端");
                        }

                        Log.WriteNormalLog("上传新数据完毕", "Upload()", source);
                    }

                    DeletePosTab("Upload()", source);
                }
            }
            #endregion 结束交互

            return(ret);
        }
Beispiel #4
0
        /// <summary>
        /// 正常状态(文件夹没有
        /// , control.tab, error.tab),更新本地 xsxb.dbf
        /// </summary>
        /// <returns></returns>
        public static int EmptyOperation(string source)
        {
            int ret = 0;
            int r   = 0;

            int unsureDataNumber = new SalesBLL().SelectSalesUnsure();

            if (unsureDataNumber < 0)
            {
                ret = -3;
                Log.WriteErrorLog("查询 unsure 表数据出错", source, "EmptyOperation()");
            }
            else
            {
                //unsure 表有数据,说明 backups 里是延迟上传的数据
                if (unsureDataNumber > 0)
                {
                    //文件夹 empty 说明 unsure 表保存的数据已经成功回收,要清空
                    if (new SalesBLL().DeleteSalesUnsure() > 0)
                    {
                        Log.WriteNormalLog("清空 unsure 表", "EmptyOperation()", source);
                    }
                    else
                    {
                        Log.WriteErrorLog("清空 unsure 表", source, "EmptyOperation()");
                    }


                    //将新数据追加到 backups 里
                    r = new SalesBLL().TimeToBackups();
                    if (r > 0)
                    {
                        ret = 9;
                        Log.WriteNormalLog("新数据追加到 backups 表", "EmptyOperation()", source);
                    }
                    else if (r < 0)
                    {
                        Log.WriteErrorLog("新数据追加到 backups 表", source, "EmptyOperation()");
                    }
                    else
                    {
                        ret = 10;//没有新数据可追加
                    }
                }
                //unsure 表没有数据,说明 backups 里是已上传的数据,已被成功回收
                else
                {
                    //覆盖新数据到 backups 表
                    r = new SalesBLL().TimeCoverBackups();
                    if (r > 0)
                    {
                        ret = 11;
                        Log.WriteNormalLog("新数据覆盖 backups 表", "EmptyOperation()", source);
                    }
                    else if (r < 0)
                    {
                        Log.WriteErrorLog("新数据覆盖 backups 表", source, "EmptyOperation()");
                    }
                    else
                    {
                        ret = 12;//没有新数据可覆盖
                    }
                }

                //复制原始文件到单次销售明细 dbf 文件本地保存路径(覆盖)
                //dbf文件无法真正删除老数据,每次上传前先使用比较小的原始文件
                File.Copy(GlobalParams.xsxbIniPath, GlobalParams.xsxbPath, true);

                try
                {
                    //导出单次销售明细数据到本地 DBF 文件
                    r = new DataOperator().SalesBackupstoDBF();
                    if (r > 0)
                    {
                        Log.WriteNormalLog("导出数据到本地 DBF 文件", "EmptyOperation()", source);
                    }
                    else if (r == -3)
                    {
                        ret = -5;
                        Log.WriteNormalLog("backups 表没有数据, 停止导出", "EmptyOperation()", source);
                    }
                }
                catch (Exception ex)
                {
                    ret = -4;
                    Log.WriteErrorLog(ex.Message, ex.Source, "EmptyOperation()");
                }
            }

            return(ret);
        }