Example #1
0
        public static void SyncProductLinkTemplate()
        {
            var rowVersionList = RpcFacade.Call <IEnumerable <RpcObject> >("/MainSystem/B3Butchery/Rpcs/ProductLinkRpc/GetRowVersion", SysConfig.Current.AccountingUnit_ID).Select(obj => new Tuple <long, int>(obj.Get <long>("ID"), obj.Get <int>("RowVersion"))).ToList();
            var folder         = Path.Combine(Util.DataFolder, typeof(ClientProductLink).Name);

            BeforeWriteFile(rowVersionList, folder);
            var templateList = RpcFacade.Call <IEnumerable <RpcObject> >("/MainSystem/B3Butchery/Rpcs/ProductLinkRpc/GetProductLinkTemplate", rowVersionList.Select(x => new long?(x.Item1)).ToArray());

            foreach (var template in templateList)
            {
                var clientBill = new ClientProductLink();
                clientBill.ID              = template.Get <long>("ID");
                clientBill.Name            = template.Get <string>("Name");
                clientBill.Department_ID   = template.Get <long>("Department_ID");
                clientBill.Department_Name = template.Get <string>("Department_Name");
                clientBill.CollectType     = string.Format("{0}", template.Get <object>("CollectType"));
                clientBill.ProductLinks_ID = template.Get <long?>("ProductLinks_ID");
                if (Util.ExistError(() => string.IsNullOrEmpty(clientBill.CollectType), string.Format("No.{0} 模板中采集方式不能为空", clientBill.ID)))
                {
                    return;
                }
                var rowVersion = template.Get <int>("RowVersion");
                var detailList = template.Get <IList <RpcObject> >("Details");
                foreach (var detail in detailList)
                {
                    var d = new ClientProductLink_GoodsDetail();
                    d.Goods_ID   = detail.Get <long>("Goods_ID");
                    d.Goods_Name = detail.Get <string>("Goods_Name");
                    d.Goods_Code = detail.Get <string>("Goods_Code");
                    d.Goods_UnitConvertDirection = string.Format("{0}", detail.Get <object>("Goods_UnitConvertDirection"));
                    d.Goods_MainUnitRatio        = detail.Get <decimal?>("Goods_MainUnitRatio");
                    d.Goods_SecondUnitRatio      = detail.Get <decimal?>("Goods_SecondUnitRatio");
                    clientBill.Details.Add(d);
                }

                XmlSerializer serializer = new XmlSerializer(typeof(ClientProductLink));
                using (var stream = File.Open(Path.Combine(folder, clientBill.ID + ".xml"), FileMode.Create))
                {
                    serializer.Serialize(stream, clientBill);
                }

                using (var stream = File.CreateText(Path.Combine(folder, clientBill.ID + ".ver")))
                {
                    stream.Write(rowVersion);
                }
            }
        }
Example #2
0
        public ProductLinkDialog(long departMentID, long template)
        {
            InitializeComponent();
            Util.SetSceen(this);
            productLink = new ClientProductLinkBillSave
            {
                AccountingUnit_ID = SysConfig.Current.AccountingUnit_ID.Value,
                Department_ID     = departMentID,
                Domain_ID         = SysConfig.Current.Domain_ID,
                User_ID           = SysConfig.Current.User_ID,
                CreateTime        = DateTime.Now
            };

            comboBoxProductPlan.Items.Add("");
            comboBoxGoods.Items.Add("");

            string file = Path.Combine(Path.Combine(Util.DataFolder, typeof(ClientProductLink).Name), template.ToString() + ".xml");

            XmlSerializer serializer = new XmlSerializer(typeof(ClientProductLink));

            using (var stream = File.Open(file, FileMode.Open))
            {
                productLinkTemplate = serializer.Deserialize(stream) as ClientProductLink;
            }
            productLink.CollectType     = productLinkTemplate.CollectType;
            productLink.ProductLinks_ID = productLinkTemplate.ProductLinks_ID;
            foreach (var detail in productLinkTemplate.Details)
            {
                if (detail.Goods_ID != 0)
                {
                    comboBoxGoods.Items.Add(new Option(detail.Goods_Name, detail.Goods_ID));
                }
                if (!goodsInfo.ContainsKey(detail.Goods_ID))
                {
                    goodsInfo.Add(detail.Goods_ID, new Tuple <string, decimal?, decimal?>(detail.Goods_UnitConvertDirection, detail.Goods_MainUnitRatio, detail.Goods_SecondUnitRatio));
                }
            }

            var productPlanFolder = Path.Combine(Util.DataFolder, typeof(ClientProductPlan).Name);

            if (Directory.Exists(productPlanFolder))
            {
                var productPlanFile = Directory.GetFiles(productPlanFolder, "*.xml");

                XmlSerializer ppSerializer = new XmlSerializer(typeof(ClientProductPlan));
                foreach (var ppFile in productPlanFile)
                {
                    using (var stream = File.Open(ppFile, FileMode.Open))
                    {
                        var productPlan = ppSerializer.Deserialize(stream) as ClientProductPlan;
                        //if (productPlan.PlanDate == productPlan.SyncDate)
                        comboBoxProductPlan.Items.Add(new Option(productPlan.PlanNumber, productPlan.ID));
                    }
                }

                if (comboBoxProductPlan.Items.Count > 1)
                {
                    comboBoxProductPlan.SelectedIndex = 1;
                }
            }
            comboBoxProductPlan.Focus();
            HardwareUtil.Device.ScannerReader += new EventHandler <ScanEventArgs>(Device_ScannerReaders);
        }