Beispiel #1
0
    protected void TrainSearch_Click(object sender, EventArgs e)
    {
        Session["TrainResults"] = null;
        string oName = FromText.Text;
        string dName = ToText.Text;

        RomeApi += "&oName=" + oName + "&dName=" + dName + "";
        System.Net.WebRequest wrGETURL;
        wrGETURL = System.Net.WebRequest.Create(RomeApi);
        System.IO.Stream objStream;
        objStream = wrGETURL.GetResponse().GetResponseStream();
        System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
        xmlDoc.Load(objStream);
        XmlNamespaceManager mgr = new XmlNamespaceManager(xmlDoc.NameTable);

        mgr.AddNamespace("ns", "http://www.rome2rio.com/api/1.2/xml");
        System.Xml.XmlNode pricenode   = xmlDoc.SelectSingleNode("//ns:SearchResponse/ns:Route[@name='Train']/ns:IndicativePrice", mgr);
        System.Xml.XmlNode freqnode    = xmlDoc.SelectSingleNode("//ns:SearchResponse/ns:Route[@name='Train']/ns:TransitSegment/ns:TransitItinerary/ns:TransitLeg/ns:TransitHop", mgr);
        System.Xml.XmlNode timenode    = xmlDoc.SelectSingleNode("//ns:SearchResponse/ns:Route[@name='Train']", mgr);
        System.Xml.XmlNode carriernode = xmlDoc.SelectSingleNode("//ns:SearchResponse/ns:Route[@name='Train']/ns:TransitSegment/ns:TransitItinerary/ns:TransitLeg/ns:TransitHop/ns:TransitHopAgency", mgr);
        double             usd         = Convert.ToDouble(pricenode.Attributes[0].Value);
        string             carrier     = carriernode.Attributes[0].Value;
        string             time        = timenode.Attributes[2].Value;

        TrainClass[] array = new TrainClass[1];
        array[0] = new TrainClass(usd, carrier, time);
        Session.Add("TrainResults", array);
        RomeApi = "http://free.rome2rio.com/api/1.2/xml/Search?key=RNMpNhbV";
        GridView1.DataSource = (TrainClass[])Session["TrainResults"];
        GridView1.DataBind();
    }
        public void TrainClassModelExtensionsClass_ToTrainClassMethod_ReturnsObjectWithCorrectTableCodeProperty_IfParameterHasTableCodePropertyThatIsNotNull()
        {
            TrainClassModel testParam = GetModel();

            TrainClass testOutput = testParam.ToTrainClass();

            Assert.AreEqual(testParam.TableCode, testOutput.TableCode);
        }
        public void TrainClassExtensionsClass_ToYamlTrainClassModelMethod_ThrowsNullReferenceException_IfParameterIsNull()
        {
            TrainClass testParam = null;

            _ = testParam.ToYamlTrainClassModel();

            Assert.Fail();
        }
        public void TrainClassExtensionsClass_ToTrainClassModelMethod_ThrowsArgumentNullException_IfParameterIsNull()
        {
            TrainClass testObject = null;

            _ = testObject.ToTrainClassModel();

            Assert.Fail();
        }
Beispiel #5
0
 public VendorsEx(VendorType vendorType, string name, Location location, TrainClass trainClass, int entryId)
 {
     VendorType = vendorType;
     Name       = name;
     Location   = location;
     TrainClass = trainClass;
     EntryId    = entryId;
 }
Beispiel #6
0
 public VendorsEx(VendorType vendorType, string name, Location location, TrainClass trainClass, int entryId)
 {
     VendorType = vendorType;
     Name = name;
     Location = location;
     TrainClass = trainClass;
     EntryId = entryId;
 }
        public void TrainClassExtensionsClass_ToYamlTrainClassModelMethod_ReturnsObjectWithCorrectIdProperty_IfParameterIsNotNull()
        {
            TrainClass testParam = GetTestObject();

            TrainClassModel testOutput = testParam.ToYamlTrainClassModel();

            Assert.AreEqual(testParam.Id, testOutput.Id);
        }
        public void TrainClassModelExtensionsClass_ToTrainClassMethod_ReturnsObjectWithTableCodePropertyEqualToNull_IfParameterHasTableCodePropertyThatIsNull()
        {
            TrainClassModel testParam = GetModel();

            testParam.TableCode = null;

            TrainClass testOutput = testParam.ToTrainClass();

            Assert.IsNull(testOutput.TableCode);
        }
Beispiel #9
0
 public TrainClassParam(TrainClass trainclass)
 {
     this.Id         = trainclass.Id;
     this.Name       = trainclass.Name;
     this.CreateDate = trainclass.CreateDate;
     this.UpdateDate = trainclass.UpdateDate;
     this.DeleteDate = trainclass.DeleteDate;
     this.IsDelete   = trainclass.IsDelete;
     this.CreateBy   = ""; //isi
     this.UpdateBy   = ""; //isi
     this.DeleteBy   = ""; //isi
 }
        public void TrainClassExtensionsClass_ToTrainClassModelMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull()
        {
            TrainClass testObject = null;

            try
            {
                _ = testObject.ToTrainClassModel();
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("trainClass", ex.ParamName);
            }
        }
        /// <summary>
        /// Convert a <see cref="TrainClass"/> instance into a <see cref="TrainClassModel"/> instance.
        /// </summary>
        /// <param name="trainClass">The object to convert.</param>
        /// <returns>A <see cref="TrainClassModel"/> instance whose properties are the same as the parameter.</returns>
        public static TrainClassModel ToTrainClassModel(this TrainClass trainClass)
        {
            if (trainClass is null)
            {
                throw new ArgumentNullException(nameof(trainClass));
            }

            return(new TrainClassModel
            {
                Description = trainClass.Description,
                Id = trainClass.Id,
                TableCode = trainClass.TableCode,
            });
        }
Beispiel #12
0
        /// <summary>
        /// Convert a <see cref="TrainClass" /> instance to a <see cref="TrainClassModel" /> instance.
        /// </summary>
        /// <param name="trainClass">The object to be converted.</param>
        /// <returns>A <see cref="TrainClassModel" /> instance containing the same data as the parameter in serialisable form.</returns>
        /// <exception cref="NullReferenceException">Thrown if the parameter is <c>null</c>.</exception>
        public static TrainClassModel ToYamlTrainClassModel(this TrainClass trainClass)
        {
            if (trainClass is null)
            {
                throw new NullReferenceException();
            }

            return(new TrainClassModel
            {
                Description = trainClass.Description,
                Id = trainClass.Id,
                TableCode = trainClass.TableCode,
            });
        }
Beispiel #13
0
    public SplinePlus()
    {
        SPData            = CreateInstance(SPData);
        SPData.SplinePlus = this;

        SplineCreationClass = CreateInstance(SplineCreationClass);
        FollowerClass       = CreateInstance(FollowerClass);
        TrainClass          = CreateInstance(TrainClass);
        EventClass          = CreateInstance(EventClass);
        GizmosClass         = CreateInstance(GizmosClass);
        ProjectionClass     = CreateInstance(ProjectionClass);

        SPData.Selections     = CreateInstance(SPData.Selections);
        SPData.SmoothData     = CreateInstance(SPData.SmoothData);
        SPData.SharedSettings = CreateInstance(SPData.SharedSettings);
    }
 public bool AddClass(TrainClass trainClass)
 {
     try
     {
         using (TrainTicketBookingDbContext dbContext = new TrainTicketBookingDbContext())   //Adding train classes to the db
         {
             dbContext.TrainClass.Add(trainClass);
             dbContext.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #15
0
 public ActionResult AddClass([Bind(Exclude = "TrainClassDetails,ClassId")] TrainClassViewModel trainClassViewModel)
 {
     if (ModelState.IsValid)
     {
         TrainClass trainClass = AutoMapper.Mapper.Map <TrainClassViewModel, TrainClass>(trainClassViewModel);
         bool       result     = trainClassBL.AddClass(trainClass);
         if (!result)
         {
             TempData["Message"] = "Please Try Again";
             return(View());
         }
         TempData["Message"] = "Added Successfully!!!";
         return(RedirectToAction("DisplayClass"));
     }
     return(View());
 }
        private void DataView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataView.SelectedItem == null)
            {
                return;
            }

            TrainClass itemInfo = DataView.SelectedItem as TrainClass;

            if (itemInfo == null || !(itemInfo is TrainClass))
            {
                MessageBox.Show("获取选中项出现问题");
                return;
            }

            Text_lineid_Copy.Text    = itemInfo.lineid.ToString();
            Text_traintype_Copy.Text = itemInfo.traintype;
            Text_seatcount_Copy.Text = itemInfo.seatcount.ToString();
        }
        private void BtnDown_Click(object sender, EventArgs e)
        {
            if (_model == null || dataGridView.SelectedCells.Count == 0)
            {
                return;
            }
            int idx = dataGridView.SelectedCells[0].RowIndex;

            if (idx >= _model.Count - 1)
            {
                return;
            }

            TrainClass swap = _model[idx];

            _model[idx]     = _model[idx + 1];
            _model[idx + 1] = swap;

            UpdateViewToModel();
        }
        private void Button_delete_Click(object sender, RoutedEventArgs e)
        {
            if (DataView.SelectedItem == null)
            {
                return;
            }

            int        selected_trainid;
            TrainClass itemInfo = DataView.SelectedItem as TrainClass;

            if (itemInfo != null && itemInfo is TrainClass)
            {
                selected_trainid = itemInfo.trainid;
            }
            else
            {
                MessageBox.Show("获取选中项出现问题");
                return;
            }
            TcpClient     tcpClient     = null;
            NetworkStream networkStream = null;

            try
            {
                tcpClient = new TcpClient();
                tcpClient.Connect(ip_address, port); //建立与服务器的连接
                networkStream = tcpClient.GetStream();
                if (networkStream.CanWrite)
                {
                    var package = new TTS_Core.TrainOperationPackage(user, ip_address + ":" + listen_port.ToString(), "server",
                                                                     TTS_Core.Enum_OP.K_DELETE,
                                                                     selected_trainid, 0, "", 0);

                    byte[] sendBytes = package.DataPackageToBytes();
                    networkStream.Write(sendBytes, 0, sendBytes.Length);

                    var newClient   = tcp_listener.AcceptTcpClient();
                    var bytes       = ReadFromTcpClient(newClient); //获取数据
                    var package_rec = new TTS_Core.DataSetPackage(bytes);

                    if (package_rec.forbid != 0 && package_rec.forbid != 1)
                    {
                        MessageBox.Show("出大问题");
                    }

                    if (package_rec.forbid == 1)
                    {
                        MessageBox.Show("删除失败,请检查完整性约束或者是服务器故障");
                    }
                    else
                    {
                        DataView.Items.Remove(DataView.SelectedItem);
                        DataView.Items.Refresh();
                    }
                }
            }
            catch
            {
                MessageBox.Show("无法连接到服务器!");
                return;
            }
            finally
            {
                if (networkStream != null)
                {
                    networkStream.Close();
                }
                tcpClient.Close();
            }
        }
Beispiel #19
0
        public void LoadXml(XmlNode xmlNode)
        {
            if (xmlNode != null)
            {
                foreach (XmlNode childNode in xmlNode.ChildNodes)
                {
                    if (childNode.Name == "Vendor")
                    {
                        string     name       = string.Empty;
                        int        entryId    = int.MinValue;
                        VendorType type       = VendorType.Unknown;
                        string     x          = string.Empty;
                        string     y          = string.Empty;
                        string     z          = string.Empty;
                        TrainClass trainClass = TrainClass.Unknown;
                        foreach (XmlAttribute attribute in childNode.Attributes)
                        {
                            switch (attribute.Name)
                            {
                            case "Name":
                                name = attribute.InnerText;
                                break;

                            case "EntryId":
                                entryId = Convert.ToInt32(attribute.InnerText);
                                break;

                            case "Type":
                                type = (VendorType)Enum.Parse(typeof(VendorType), attribute.InnerText, true);
                                break;

                            case "TrainClass":
                                trainClass = (TrainClass)Enum.Parse(typeof(TrainClass), attribute.InnerText, true);
                                break;

                            case "X":
                                x = GetCorrectString(attribute.InnerText);
                                break;

                            case "Y":
                                y = GetCorrectString(attribute.InnerText);
                                break;

                            case "Z":
                                z = GetCorrectString(attribute.InnerText);
                                break;
                            }
                        }
                        if (!string.IsNullOrEmpty(name))
                        {
                            if (trainClass == TrainClass.Unknown)
                            {
                                Npc.Add(new VendorsEx(type, name,
                                                      new Location((float)Convert.ToDouble(x),
                                                                   (float)Convert.ToDouble(y),
                                                                   (float)Convert.ToDouble(z)), entryId));
                            }
                            else
                            {
                                Npc.Add(new VendorsEx(type, name,
                                                      new Location((float)Convert.ToDouble(x),
                                                                   (float)Convert.ToDouble(y),
                                                                   (float)Convert.ToDouble(z)), trainClass, entryId));
                            }
                        }
                    }
                }
            }
        }
Beispiel #20
0
 public bool AddClass(TrainClass trainClass)             //Method to add train classes in db
 {
     return(trainClassRepository.AddClass(trainClass));
 }
        private void Button_modify_Click(object sender, RoutedEventArgs e)
        {
            if (DataView.SelectedItem == null)
            {
                return;
            }

            TrainClass itemInfo = DataView.SelectedItem as TrainClass;

            if (itemInfo == null || !(itemInfo is TrainClass))
            {
                MessageBox.Show("获取选中项出现问题");
                return;
            }

            TcpClient     tcpClient     = null;
            NetworkStream networkStream = null;

            try
            {
                tcpClient = new TcpClient();
                tcpClient.Connect(ip_address, port); //建立与服务器的连接
                networkStream = tcpClient.GetStream();
                if (networkStream.CanWrite)
                {
                    int lineid    = 0;
                    int seatcount = 0;
                    if (!getStandard(out lineid, Text_lineid_Copy.Text) || !getStandard(out seatcount, Text_seatcount_Copy.Text))
                    {
                        MessageBox.Show("查询信息填写错误");
                        return;
                    }
                    var package = new TTS_Core.TrainOperationPackage(user, ip_address + ":" + listen_port.ToString(), "server",
                                                                     TTS_Core.Enum_OP.K_MODIFY,
                                                                     itemInfo.trainid, lineid, Text_traintype_Copy.Text, seatcount);

                    byte[] sendBytes = package.DataPackageToBytes(); //注册数据包转化为字节数组
                    networkStream.Write(sendBytes, 0, sendBytes.Length);

                    var newClient   = tcp_listener.AcceptTcpClient();
                    var bytes       = ReadFromTcpClient(newClient); //获取数据
                    var package_rec = new TTS_Core.DataSetPackage(bytes);

                    if (package_rec.forbid != 0 && package_rec.forbid != 1)
                    {
                        MessageBox.Show("出大问题");
                    }

                    if (package_rec.forbid == 1)
                    {
                        MessageBox.Show("修改失败,请检查完整性约束或者是服务器故障");
                    }
                    else
                    {
                        itemInfo.lineid    = lineid;
                        itemInfo.traintype = Text_traintype_Copy.Text;
                        itemInfo.seatcount = seatcount;
                        DataView.Items.Insert(DataView.SelectedIndex, itemInfo);
                        DataView.Items.Remove(DataView.SelectedItem);
                        DataView.Items.Refresh();
                    }
                }
            }
            catch
            {
                MessageBox.Show("无法连接到服务器!");
                return;
            }
            finally
            {
                if (networkStream != null)
                {
                    networkStream.Close();
                }
                tcpClient.Close();
            }
        }