Esempio n. 1
0
        public SyncResult SyncFromMain(SyncToDepartmentObject syncToDept)
        {
            SyncResult result = new SyncResult();

            SyncCommonInformation(syncToDept);
            SyncStockOut(syncToDept);
            return result;
        }
Esempio n. 2
0
        public IList<SyncResult> SyncToDepartment(string exportPath, SyncToDepartmentObject syncToDept)
        {
            IList<SyncResult> resultList = new List<SyncResult>();
            Department department = syncToDept.Department;
            syncToDept = GetSyncData(syncToDept);

            #region useless
            /*SyncToDepartmentObject first = new SyncToDepartmentObject();
                                        first.Department = syncToDept.Department;
                                        first.ProductMasterList = syncToDept.ProductMasterList;
                                        first.PriceList = syncToDept.PriceList;
                                        first.StockOutList = new List<StockOut>();*/

            #endregion
            int countSyncFile = 1;
            string fileName = exportPath + "\\" + department.DepartmentId
                                          + "_" + countSyncFile.ToString()
                                          + "_SyncDown_"
                                          + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")
                                          + ".ssf";
            SyncResult result = new SyncResult();
            result.FileName = fileName;
            result.Status = "Thành công";
            resultList.Add(result);
            //var stream = File.Open(fileName, FileMode.Create);
            StreamWriter writer = new StreamWriter(fileName,
                                      false,
                                      Encoding.UTF8);
            var serializer = new JsonSerializer();
            serializer.Serialize(writer, syncToDept);
            writer.Flush();
            writer.Close();
            //BinaryFormatter writer = new BinaryFormatter();
            //writer.Serialize(stream, syncToDept);
            /*NxBinaryWriter nxWriter = new NxBinaryWriter(stream);
            nxWriter.WriteObject(first);*/
            //stream.Flush();
            //stream.Close();

            #region useless
            // write each stock out to a sync file for avoiding duplicate update
            /*if (!ObjectUtility.IsNullOrEmpty(syncToDept.StockOutList))
            {
                foreach (StockOut stockOut in syncToDept.StockOutList)
                {
                    //StockOut _initedstockOut = LazyInitializer.InitializeEntity(stockOut, 0, DaoConstants.MODEL_NAMESPACE, session)
                    countSyncFile += 1;
                    SyncToDepartmentObject soSync = new SyncToDepartmentObject();
                    first.ProductMasterList = new List<ProductMaster>();
                    first.PriceList = new List<MainPrice>();
                    soSync.Department = syncToDept.Department;
                    soSync.StockOutList = new List<StockOut>();
                    soSync.StockOutList.Add(stockOut);

                    string soFileName = exportPath + "\\" + department.DepartmentId
                                  + "_" + countSyncFile.ToString()
                                  + "_SyncDown_"
                                  + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")
                                  + ".ssf";
                    SyncResult soResult = new SyncResult();
                    soResult.FileName = soFileName;
                    soResult.Status = "Thành công";
                    resultList.Add(soResult);
                    Stream soStream = File.Open(soFileName, FileMode.Create);
                    BinaryFormatter soWriter = new BinaryFormatter();
                    soWriter.Serialize(soStream, soSync);
                    /*NxBinaryWriter nxSoWriter = new NxBinaryWriter(soStream);
                    nxSoWriter.WriteObject(soSync);♥1♥
                    //Serializer.Serialize(soStream, soSync);
                    soStream.Flush();
                    soStream.Close();
                }
            }*/

            #endregion
            return resultList;
            /*}
            );*/
        }