Exemplo n.º 1
0
        /// <summary>
        /// 校验数据个列合法性
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        private void CheckItemData(DataGridViewRow dgvRow, Bill b, ref Dictionary <string, int> boxnumber, ref int errorint, ref double weight)
        {
            #region ID号
            dgvRow.Cells["dgvExcelID"].Value = b.ID;
            #endregion

            #region 序号
            if (b.Sequence != null)
            {
                dgvRow.Cells["dgvExcelSequence"].Value = b.Sequence;
                try
                {
                    int.Parse(b.Sequence);
                    dgvRow.Cells["dgvExcelSequence"].Style.BackColor = Color.White;
                }
                catch (Exception)
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelSequence"].Style.BackColor = Color.Red;
                }
                if (b.Sequence.Contains(",") || b.Sequence.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelSequence"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelSequence"].Value = "";
            }
            #endregion

            #region 箱子号
            if (b.BoxNo != null)
            {
                dgvRow.Cells["dgvExcelBoxNo"].Value = b.BoxNo;
                if (b.BoxNo.Contains(",") || b.BoxNo.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelBoxNo"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelBoxNo"].Value = "";
            }
            #endregion

            #region 封号
            if (b.SealNo != null)
            {
                dgvRow.Cells["dgvExcelSealNo"].Value = b.SealNo;
                if (b.SealNo.Contains(",") || b.SealNo.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelSealNo"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelSealNo"].Value = "";
            }
            #endregion

            #region 重量
            if (b.Weight != null)
            {
                dgvRow.Cells["dgvExcelWeight"].Value = b.Weight;
                try
                {
                    double singleweigth = double.Parse(b.Weight);
                    dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.White;
                    if (b.BoxState == CommValue.BoxState[0])                   //如果重的 重量大于系数
                    {
                        if (b.BoxSize.Substring(0, 2) == CommValue.BoxSize[0]) //20长的 要大于2.3
                        {
                            if (singleweigth <= CommValue.SingleCoefficient)
                            {
                                dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.Brown;
                            }
                        }
                        else
                        {
                            //如果是40长的箱子
                            if (singleweigth <= CommValue.DoubleCoefficient)
                            {
                                dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.Brown;
                            }
                        }
                    }
                    else
                    {
                        //如果是空的箱子 则直接可以赋值
                        if (b.BoxSize.Substring(0, 2) == CommValue.BoxSize[0])   //20长的
                        {
                            if (b.Weight != CommValue.SingleCoefficient.ToString())
                            {
                                dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.Yellow;
                            }
                        }
                        else
                        {
                            if (b.Weight != CommValue.DoubleCoefficient.ToString())
                            {
                                dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.Yellow;
                            }
                        }
                    }

                    weight += double.Parse(b.Weight);
                }
                catch (Exception)
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.Red;
                }
                if (b.Weight.Contains(",") || b.Weight.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                //当为空时候的判断 是否是空箱
                if (b.BoxState == CommValue.BoxState[1])                   //是否为空箱子
                {
                    if (b.BoxSize.Substring(0, 2) == CommValue.BoxSize[0]) //20长的
                    {
                        dgvRow.Cells["dgvExcelWeight"].Value = CommValue.SingleCoefficient.ToString();
                        b.Weight = CommValue.SingleCoefficient.ToString();
                    }
                    else
                    {
                        dgvRow.Cells["dgvExcelWeight"].Value = (CommValue.DoubleCoefficient).ToString();
                        b.Weight = (CommValue.DoubleCoefficient).ToString();
                    }
                }
                else
                {
                    dgvRow.Cells["dgvExcelWeight"].Value           = "0";
                    dgvRow.Cells["dgvExcelWeight"].Style.BackColor = Color.Red;
                }
            }
            #endregion

            #region 箱子型号
            if (b.BoxSize != null)
            {
                dgvRow.Cells["dgvExcelBoxSize"].Value = b.BoxSize;
                if (!string.IsNullOrEmpty(new BaseService <BoxSize>().GetRecord(" name='" + b.BoxSize + "'").ID))
                {
                    boxnumber[b.BoxSize]++;
                    dgvRow.Cells["dgvExcelBoxSize"].Style.BackColor = Color.White;
                }
                else
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelBoxSize"].Style.BackColor = Color.Red;
                }
                if (b.BoxSize.Contains(",") || b.BoxSize.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelBoxSize"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelBoxSize"].Value = "";
            }
            #endregion

            #region 箱子状态
            if (b.BoxState != null)
            {
                dgvRow.Cells["dgvExcelBoxState"].Value = b.BoxState;
                if (CommValue.BoxState.Contains(b.BoxState))     //利用常量数组来完成比较
                {
                    dgvRow.Cells["dgvExcelBoxState"].Style.BackColor = Color.White;
                }
                else
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelBoxState"].Style.BackColor = Color.Red;
                }
                if (b.BoxState.Contains(",") || b.BoxState.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelBoxState"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelBoxState"].Value = "";
            }
            #endregion

            #region 船公司
            if (b.Company != null)
            {
                dgvRow.Cells["dgvExcelCompany"].Value = b.Company;
                if (!string.IsNullOrEmpty(new BaseService <Company>().GetRecord(" name='" + b.Company + "'").ID))
                {
                    dgvRow.Cells["dgvExcelCompany"].Style.BackColor = Color.White;
                }
                else
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelCompany"].Style.BackColor = Color.Red;
                }
                if (b.Company.Contains(",") || b.Company.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelCompany"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelCompany"].Value = "";
            }
            #endregion

            #region 目的港
            if (b.Aim != null)
            {
                dgvRow.Cells["dgvExcelAim"].Value = b.Aim;
                if (b.BoxState != "空" || (!string.IsNullOrEmpty(b.Aim)))     //空船必须判断
                {
                    if (!string.IsNullOrEmpty(new BaseService <Aim>().GetRecord(" name='" + b.Aim + "' ").ID))
                    {
                        dgvRow.Cells["dgvExcelAim"].Style.BackColor = Color.White;
                    }
                    else
                    {
                        errorint++;
                        dgvRow.Cells["dgvExcelAim"].Style.BackColor = Color.Red;
                    }
                }
                if (b.Aim.Contains(",") || b.Aim.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelAim"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelAim"].Value = "";
            }
            #endregion

            #region 货种
            if (b.GoodsType != null)
            {
                dgvRow.Cells["dgvExcelGoodsType"].Value = b.GoodsType;
                if (b.BoxState != "空" || (!string.IsNullOrEmpty(b.GoodsType)))
                {
                    GoodsType goods = new BaseService <GoodsType>().GetRecord(" name='" + b.GoodsType + "'");
                    if (!string.IsNullOrEmpty(goods.ID))
                    {
                        //如果没有上级的则出现另类颜色
                        if (!string.IsNullOrEmpty(goods.UpID) && goods.UpID != "0")
                        {
                            dgvRow.Cells["dgvExcelGoodsType"].Style.BackColor = Color.White;
                        }
                        else
                        {
                            dgvRow.Cells["dgvExcelGoodsType"].Style.BackColor = Color.Yellow;       //黄色的为没定义上一 级货种
                        }
                    }
                    else
                    {
                        errorint++;
                        dgvRow.Cells["dgvExcelGoodsType"].Style.BackColor = Color.Red;        //红色为错误的格式,无对应记录内容
                    }
                }
                if (b.GoodsType.Contains(",") || b.GoodsType.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelGoodsType"].Style.BackColor = Color.Green;            //非法字符
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelGoodsType"].Value = "";
            }
            #endregion

            #region 工作地点
            if (b.WorkPlace != null)
            {
                dgvRow.Cells["dgvExcelWorkPlace"].Value = b.WorkPlace;
                if (!string.IsNullOrEmpty(new BaseService <WorkPlace>().GetRecord(" name='" + b.WorkPlace + "'").ID))
                {
                    dgvRow.Cells["dgvExcelWorkPlace"].Style.BackColor = Color.White;
                }
                else
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelWorkPlace"].Style.BackColor = Color.Red;
                }
                if (b.WorkPlace.Contains(",") || b.WorkPlace.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelWorkPlace"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelWorkPlace"].Value = "";
            }
            #endregion

            #region 代理
            if (b.Proxy != null)
            {
                dgvRow.Cells["dgvExcelProxy"].Value = b.Proxy;
                if (b.BoxState != "空" || (!string.IsNullOrEmpty(b.Proxy)))
                {
                    if (!string.IsNullOrEmpty(new BaseService <Proxy>().GetRecord(" name='" + b.Proxy + "'").ID))
                    {
                        dgvRow.Cells["dgvExcelProxy"].Style.BackColor = Color.White;
                    }
                    else
                    {
                        errorint++;
                        dgvRow.Cells["dgvExcelProxy"].Style.BackColor = Color.Red;
                    }
                }
                if (b.Proxy.Contains(",") || b.Proxy.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelProxy"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelProxy"].Value = "";
            }
            #endregion

            #region 船舶名称
            if (b.ShipName != null)
            {
                dgvRow.Cells["dgvExcelShipName"].Value = b.ShipName;
                if (b.ShipName.Contains(",") || b.ShipName.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelShipName"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelShipName"].Value = "";
            }
            #endregion

            #region 运单号
            if (b.WayBillNo != null)
            {
                dgvRow.Cells["dgvExcelWayBillNo"].Value = b.WayBillNo;
                if (b.WayBillNo.Contains(",") || b.WayBillNo.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelWayBillNo"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelWayBillNo"].Value = "";
            }
            #endregion

            #region 来源地
            if (b.Source != null)
            {
                dgvRow.Cells["dgvExcelSource"].Value = b.Source;
                if (b.BoxState != "空" || (!string.IsNullOrEmpty(b.Source)))
                {
                    if (!string.IsNullOrEmpty(new BaseService <Source>().GetRecord(" name='" + b.Source + "'").ID))
                    {
                        dgvRow.Cells["dgvExcelSource"].Style.BackColor = Color.White;
                    }
                    else
                    {
                        errorint++;
                        dgvRow.Cells["dgvExcelSource"].Style.BackColor = Color.Red;
                    }
                }
                if (b.Source.Contains(",") || b.Source.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelSource"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelSource"].Value = "";
            }
            #endregion

            #region 流向
            if (b.Direction != null)
            {
                dgvRow.Cells["dgvExcelDirection"].Value = b.Direction;
                if (b.BoxState != "空" || (!string.IsNullOrEmpty(b.Direction)))
                {
                    if (!string.IsNullOrEmpty(new BaseService <Direction>().GetRecord(" name='" + b.Direction + "'").ID))
                    {
                        dgvRow.Cells["dgvExcelDirection"].Style.BackColor = Color.White;
                    }
                    else
                    {
                        errorint++;
                        dgvRow.Cells["dgvExcelDirection"].Style.BackColor = Color.Red;
                    }
                }
                if (b.Direction.Contains(",") || b.Direction.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelDirection"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelDirection"].Value = "";
            }
            #endregion

            #region 发往地
            if (b.SendPlace != null)
            {
                dgvRow.Cells["dgvExcelSendPlace"].Value = b.SendPlace;
                if (b.BoxState != "空" || (!string.IsNullOrEmpty(b.SendPlace)))
                {
                    if (!string.IsNullOrEmpty(new BaseService <SendPlace>().GetRecord(" name='" + b.SendPlace + "'").ID))
                    {
                        dgvRow.Cells["dgvExcelSendPlace"].Style.BackColor = Color.White;
                    }
                    else
                    {
                        errorint++;
                        dgvRow.Cells["dgvExcelSendPlace"].Style.BackColor = Color.Red;
                    }
                }
                if (b.SendPlace.Contains(",") || b.SendPlace.Contains("'"))
                {
                    errorint++;
                    dgvRow.Cells["dgvExcelSendPlace"].Style.BackColor = Color.Green;
                }
            }
            else
            {
                dgvRow.Cells["dgvExcelSendPlace"].Value = "";
            }
            #endregion

            #region 备注标注
            dgvRow.Cells["dgvExcelDemo"].Value = b.Demo;
            if (b.Demo.Contains(",") || b.Demo.Contains("'"))
            {
                errorint++;
                dgvRow.Cells["dgvExcelDemo"].Style.BackColor = Color.Green;
            }
            #endregion
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            List <ItemLine> panier = new List <ItemLine>();

            UserManager.User utilisateur = new UserManager.User();
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "bill_queue", durable: false, exclusive: false, autoDelete: false, arguments: null);
                    channel.BasicQos(0, 1, false);
                    var consumer = new EventingBasicConsumer(channel);
                    channel.BasicConsume(queue: "bill_queue", autoAck: false, consumer: consumer);
                    Console.WriteLine(" [x] Awaiting RPC requests");


                    consumer.Received += (model, ea) =>
                    {
                        string response = null;

                        var body       = ea.Body;
                        var props      = ea.BasicProperties;
                        var replyProps = channel.CreateBasicProperties();
                        replyProps.CorrelationId = props.CorrelationId;

                        try
                        {
                            response = "";
                            var message = Encoding.UTF8.GetString(body.ToArray());
                            if (message == "facture")
                            {
                                Bill b = Bill.CreateBill(utilisateur, panier);
                                Console.WriteLine("Total" + b.sousTotalAvecTaxe);
                                b.afficher();
                                response = "Facture élaborée";
                            }
                            else
                            {
                                string[] messageSplit = message.Split(":");

                                if (messageSplit[0] == "User")
                                {
                                    utilisateur.nom = messageSplit[1];
                                }
                                else
                                {
                                    string nomProduit = messageSplit[0];
                                    int    quantite   = Int32.Parse(messageSplit[1]);


                                    ItemLine selectionne = null;
                                    foreach (ItemLine item in StockManager.StockManager.getStock())
                                    {
                                        if (item.item.nom == nomProduit)
                                        {
                                            selectionne = item;
                                        }
                                    }
                                    if (selectionne != null)
                                    {
                                        panier.Add(new ItemLine(selectionne.item, quantite));
                                        response = "Commande enregistrée";
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(" [.] " + e.Message);
                            response = "";
                        }
                        finally
                        {
                            var responseBytes = Encoding.UTF8.GetBytes(response);
                            channel.BasicPublish(exchange: "", routingKey: props.ReplyTo, basicProperties: replyProps, body: responseBytes);
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                        }
                    };

                    Console.WriteLine(" Press [enter] to exit.");
                    Console.ReadLine();
                }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "bill_queue", durable: false, exclusive: false, autoDelete: false, arguments: null);
                    channel.BasicQos(0, 1, false);
                    var consumer = new EventingBasicConsumer(channel);
                    channel.BasicConsume(queue: "bill_queue", autoAck: false, consumer: consumer);
                    Console.WriteLine("[x] Awaiting RPC requests");

                    consumer.Received += (model, ea) =>
                    {
                        string response = null;

                        var body       = ea.Body;
                        var props      = ea.BasicProperties;
                        var replyProps = channel.CreateBasicProperties();
                        replyProps.CorrelationId = props.CorrelationId;

                        try
                        {
                            var message = Encoding.UTF8.GetString(body).Trim();

                            var request = JsonConvert.DeserializeObject <Request>(message);

                            var bill = new Bill
                            {
                                User         = request.User,
                                Lines        = new List <BillLine>(),
                                TotalExclTax = 0,
                            };

                            foreach (var line in request.Items)
                            {
                                var subtotal = line.Quantity * line.Item.UnitPrice;
                                bill.Lines.Add(new BillLine
                                {
                                    Item     = line.Item,
                                    Quantity = line.Quantity,
                                    SubTotal = subtotal,
                                });
                                bill.TotalExclTax += subtotal;
                            }

                            bill.Total = bill.TotalExclTax * 1.15f;

                            response = JsonConvert.SerializeObject(bill);

                            if (response == null)
                            {
                                response = "";
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(" [.] " + e.Message);
                            response = "";
                        }
                        finally
                        {
                            var responseBytes = Encoding.UTF8.GetBytes(response);
                            channel.BasicPublish(exchange: "", routingKey: props.ReplyTo, basicProperties: replyProps, body: responseBytes);
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                        }
                    };

                    while (true)
                    {
                        ;
                    }
                }
        }