2023年3月

1、非同一文件夹之间页面之间的跳转。

 protected void Transfer_Basic(objectsender, EventArgs e)
{
if(Label1.Text!="")
{
Response.Redirect(
"../Basic1/basic2.aspx");
}
}

2、同一文件夹内页面之间的跳转。

protected void Trsnfer_Sign(objectsender, EventArgs e)
{
Response.Redirect(
"sign_in.aspx");
}

需求:在ASP.NET中,从数据库中导出数据,规定时间内预测出下一个数据,然后蒋数据绘制折线图。

代码:

    public partial classWare1 : System.Web.UI.Page
{
static string s = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["User"].ToString();
DataClasses1DataContext ds
= newDataClasses1DataContext(s);protected void Page_Load(objectsender, EventArgs e)
{
//页面加载时,就开始显示该仓库中存在的货物信息 DengJi DJ = newDengJi();
WareHouse ware
= newWareHouse();var num = from ware1 in ds.WareHouse where ware1.Wnumber == 1 && ware1.Snumber % 2 == 0 selectware1;if (num.Count() > 0)
{
SqlConnection sd
= newSqlConnection(s);string str2 = "select Id,class,company,realnumber,accept_time,nphone,Snum,quality from Dengji where Wnum =" + 1+ "and Status = '在库'";
SqlDataAdapter sda
= newSqlDataAdapter(str2, sd);
DataSet ds
= newDataSet();
sda.Fill(ds,
"DengJi");
GridView1.DataSource
= ds.Tables[0].DefaultView;
GridView1.DataBind();
GridView1.HeaderRow.Cells[
0].Text = "ID";
GridView1.HeaderRow.Cells[
1].Text = "种类";
GridView1.HeaderRow.Cells[
2].Text = "公司名称";
GridView1.HeaderRow.Cells[
3].Text = "入库数量";
GridView1.HeaderRow.Cells[
4].Text = "入库时间";
GridView1.HeaderRow.Cells[
5].Text = "客户电话";
GridView1.HeaderRow.Cells[
6].Text = "货架号";
GridView1.HeaderRow.Cells[
7].Text = "货损率";

}
else{

}

}
protected void Button1_Click(object sender, EventArgs e)//更改温度 、湿度、风速的值 {
Temple temple
= newTemple();var num1 =ds.Temple.Count();
temple.Id
= num1 + 1;
temple.xname
=System.DateTime.Now;
temple.ytem
= double.Parse(DropDownList1.SelectedItem.Text);
temple.yhumidity
= double.Parse(DropDownList2.SelectedItem.Text);
temple.ywind
= double.Parse(DropDownList3.SelectedItem.Text);
ds.Temple.InsertOnSubmit(temple);
ds.SubmitChanges();
}
public class GrayModel//灰色预测模型 {private doublea0, a1, a2;private int size;//定义数组长度 private doubleerror;publicGrayModel()
{

}
public void build(double[] Str)
{
size
= Str.Length;//获取数组Str长度 double[] Str1 = new double[size];//新建一个长度与以知数组长度一致的数组Str1 Str1[0] = Str[0];//把给定数组的第一个元素赋给数组Str1 for (int i = 1; i < size; i++)
{
Str1[i]
= Str[i] + Str1[i - 1];//获取新的数组值,也就是AGO计算 }double[,] a = new double[size - 1, 2];//生成二维数组a double[,] bt = new double[2, size - 1];//生成二维数组bt double[,] y = new double[size - 1, 1];//生成一维数组y for (int i = 0; i < a.GetLength(0); i++)//GetLength(0)是获取行数 {
a[i,
0] = -(Str1[i] + Str1[i + 1]) / 2;
a[i,
1] = 1;
bt[
0, i] = a[i, 0];
bt[
1, i] = 1;
y[i,
0] = Str[i + 1];
}
double[,] t = new double[2, 2];//新建矩阵t multiply(bt, a, t);//矩阵bt,a相乘,最后返回矩阵t t = inverse(t);//获取矩阵t的转置矩阵 double[,] t1 = new double[2, size - 1];//新建矩阵t1 multiply(t, bt, t1);double[,] t2 = new double[2, 1];//新建矩阵t2 multiply(t1, y, t2);
a0
= t2[0, 0];double u = t2[1, 0];
a2
= u /a0;
a1
= Str[0] -a2;
a0
= -a0;

error
= 0;for (int i = 0; i < Str.Length; i++)
{
double d = (Str[i] -GetStr(i));
error
+= d *d;
}
error
/=Str.Length;
}
public double GetError()//误差 {returnerror;
}
double GetStr1(intk)
{
return a1 * Math.Exp(a0 * k) +a2;
}
double GetStr(int k)//返回a0 * a1 * Math.exp(a0 * k); {if (k == 0)return double.Parse((a1 * Math.Exp(a0 * k) + a2).ToString("0.0"));else return double.Parse((a1 * (Math.Exp(a0 * k) - Math.Exp(a0 * (k - 1)))).ToString("0.0"));
}
public double NextValue(int index)//预测后续的值 {if (index < 0)throw new Exception("超出索引范围");return GetStr(size +index);
}
public double nextValue()//返回预测值 {return NextValue(0);
}
static double[,] inverse(double[,] t)//求矩阵t的逆矩阵 {double[,] a = new double[2, 2];double det = t[0, 0] * t[1, 1] - t[0, 1] * t[1, 0];
a[
0, 0] = t[1, 1] /det;
a[
0, 1] = -t[1, 0] /det;
a[
1, 0] = -t[0, 1] /det;
a[
1, 1] = t[0, 0] /det;returna;
}
static void multiply(double[,] left, double[,] right, double[,] dest)//两个矩阵相乘 {int first1 = left.GetLength(0);//获取第一个数组的第一维长度,也就是行数 int first2 = left.GetLength(1);//获取第一个数组的二维长度,也就是列数 int second1 = right.GetLength(1);//获取第二个数组的列数 for (int k = 0; k < first1; k++)
{
for (int j = 0; j < second1; j++)
{
dest[k, j]
= 0;for (int i = 0; i < first2; i++)
{
dest[k, j]
+= left[k, i] *right[i, j];
}
}
}
}
}
protected void Timer1_Tick(objectsender, EventArgs e)
{
//绘制图表 Chart1.ChartAreas["ChartArea1"].AxisY.Maximum =System.Double.NaN;
Chart1.ChartAreas[
"ChartArea1"].AxisY.Minimum =System.Double.NaN;//Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 5; Series series = new Series("温度");//设置图表类型,绘制温度表 series.ChartType = SeriesChartType.Line;//设置曲线样式 Temple temple = newTemple();
series.BorderWidth
= 1;//线粗 series.ShadowOffset = 1;int i = 0;int j = 0;var temple1 = from r inds.Templewhere r.Id > ds.Temple.Max(p => p.Id) - 10 //orderby r.Id descending selectr.ytem;//从数据库中获取10个数字//var tem = from r in ds.Temple select r.ytem;//查找温度值,在点上表明数字 foreach (var templ1 intemple1)
{
series.Points.AddY(templ1);
series.Points[i].Label
=templ1.ToString();
i
++;
}
//将温度值作为y值,并且在该点标识出温度值 var xna = from r inds.Templewhere r.Id > ds.Temple.Max(p => p.Id) - 10 //orderby r.Id descending select r.xname;//查找时间值 foreach (var xna12 inxna)
{
series.Points[j].AxisLabel
=xna12.ToString(); ;
j
++;
}
//将时间值作为x轴的值 Series series1= new Series("风速");//绘制风速图 series1.ChartType = SeriesChartType.Spline;//曲线样式 series1.BorderWidth = 1;
series1.ShadowOffset
= 1;int a = 0;var wind = from r inds.Templewhere r.Id > ds.Temple.Max(p => p.Id) - 10 //orderby r.Id descending selectr.ywind;//var win = from r in ds.Temple select r.ywind;//y的值 foreach (var wind1 inwind)
{
series1.Points.AddY(wind1);
series1.Points[a].Label
=wind1.ToString();
a
++;
}
//获取y的值,并显示出y值 Series series2= new Series("湿度");//绘制湿度图 series2.ChartType =SeriesChartType.Spline;
series2.BorderWidth
= 1;
series2.ShadowOffset
= 1;int c = 0;var humity1 = from r inds.Templewhere r.Id > ds.Temple.Max(p => p.Id) - 10 //orderby r.Id descending selectr.yhumidity;//var hum1 = from h in ds.Temple select h.yhumidity;//y的值 foreach (var h1 inhumity1)
{
series2.Points.AddY(h1);
series2.Points[c].Label
=h1.ToString();
c
++;
}


series1.YAxisType
=AxisType.Primary;
Chart1.Series.Add(series);
Chart1.Series.Add(series1);
Chart1.Series.Add(series2);
//在图表中显示出曲线//进行预测数据的前期获取 Temple tem1 = newTemple();var temp1 = from r inds.Templewhere r.Id > ds.Temple.Max(p => p.Id) - 20 select new{
ytem1
=r.ytem,
win1
=r.ywind,
hum1
=r.yhumidity
};
//List<double> array = new List<double>(); double[] array = new double[0];//新建数组 foreach (var num1 intemp1)
{
double p =num1.ytem1;
array
= array.Concat(new double[] { p }).ToArray();

}
//将获取的数据保存在array中 double[] array1 = new double[0];foreach (var num2 intemp1)
{
array1
= array1.Concat(new double[] { num2.win1 }).ToArray();

}
double[] array2 = new double[0];foreach(var num3 intemp1)
{
array2
= array2.Concat(new double[] { num3.hum1 }).ToArray();
}
//预测数据的计算 GrayModel gm = new GrayModel();//调用灰色预测模型进行温度数据预测 gm.build(array);
tem1.ytem
=gm.nextValue();
GrayModel gm1
= newGrayModel();
gm1.build(array1);
tem1.ywind
=gm1.nextValue();
GrayModel gm2
= newGrayModel();
gm2.build(array2);
tem1.yhumidity
=gm2.nextValue();var q =ds.Temple.Count();
tem1.Id
= q + 1;
tem1.xname
=System.DateTime.Now;
ds.Temple.InsertOnSubmit(tem1);
//将时间,学列,温度,湿度,风速数据保存在数据库中 ds.SubmitChanges();//this.Label1.Text = System.DateTime.Now.ToString(); }

上面代码的说明:从数据库中获取了指定数量 的数据,然后使用灰色预测模型预测出新的数据,最后将显示出10个数据的折线图。

需求:选择不同的路径选择方式,得出相应的线路。

代码:

<div class="input-card" style="width: auto;">
            <div class="input-item" style="width:auto;">出发起点<input id="text_1" type="text" value="华东交通大学" />
            出发终点<input id="text_2" type="text" value="" />
            路径选择方式<select id="test">
                        <option value="1">最快捷模式</option>
                        <option value="2">最经济模式</option>
                        <option value="3">最短距离模式</option>
                        <option value="4">考虑实时路况</option>
                        </select>
            <input type="button" value="查询" onclick="searchByStationName();"/>
            <button class="btn" onclick="toggle()">显示/隐藏实时路况</button>
            </div>
            </div>
    <script>
        var map = new AMap.Map('container', {
resizeEnable:
true, //是否监控地图容器尺寸变化 zoom: 13, //初始化地图层级 center: [116.397428, 39.90923] //初始化地图中心点 });//实时路况图层 var trafficLayer = newAMap.TileLayer.Traffic({
zIndex:
10});
trafficLayer.setMap(map);
var isVisible = true;functiontoggle() {if(isVisible) {
trafficLayer.hide();
isVisible
= false;
}
else{
trafficLayer.show();
isVisible
= true;
}
}
functionsearchByStationName() {//根据起终点名称规划驾车导航路线 var myselect = document.getElementById("test");var index =myselect.selectedIndex;switch(myselect.options[index].value) {case "1":var driving = newAMap.Driving({
map: map,
panel:
"panel",
policy: AMap.DrivingPolicy.LEAST_TIME
//最快捷模式 });break;case "2":var driving = newAMap.Driving({
map: map,
panel:
"panel",
policy: AMap.DrivingPolicy.LEAST_FEE
//最经济模式 });break;case "3":var driving = newAMap.Driving({
map: map,
panel:
"panel",
policy: AMap.DrivingPolicy.LEAST_DISTANCE
//最短距离模式 });break;case "4":var driving = newAMap.Driving({
map: map,
panel:
"panel",
policy: AMap.DrivingPolicy.REAL_TRAFFIC
//考虑实时路况 });break;
}
driving.search([
{ keyword: document.getElementById(
"text_1").value, city: '北京'},
{ keyword: document.getElementById(
"text_2").value, city: '北京'}
],
function(status, result) {if (status === 'complete') {
log.success(
'绘制驾车路线完成')
}
else{
log.error(
'获取驾车数据失败:' +result)
}
});
}
//构造路线导航类 functionBillCalculate() {

}
</script>

总结:不同的路径选择方式,policy值需要分别进行书写。

From this codes,we will know the definition of dictionary and there are some explanation under this code to understand the meaning.

1 alien={'color':'blue','point':6}#the definition of dictionary
2 #in python ,dictionary is represented by a series of key-value pairs place in {}
3 print(alien['color'])#print the value of color
4 #from this example,we can find the way to receive the appointed value from dictionary
5 value_color=alien['color']6 value_point=alien['point']7 print(f"your face is {value_color}")#using variables in strings
8 print(f"your face is {value_color},and have {value_point} buttons in your clothes")9 #modify the value in key-value pairs is the same of C,you just overwrite the old value with new values
10 del alien['color']11 print(alien)12 alien['age']=16
13 alien['leg']=5
14 value_mother=alien.get('mother','no mother values assigned')15 #if the value of mother is not assgned,it will print'no mother values assigned',rather show error
16 print(value_mother)17 value_age=alien.get('age','no age values assigned')18 print(value_age)19 #from this example ,we can find if we can not sure there is the appointed value in dictionary,we should consider using .get() firstly

Code running result:

If we only read this code,we will feel bored quickly,so i write some examples:

1 #We have already know the traversal in Python,the first example is tell this.
2 favorite_fruit={3     'Tom':'banana',4     'Jack':'apple',5     'Kim':'strawberry',6     'Limin':'grapefruit'
7 }8 for name,fruit infavorite_fruit.items():9     print(f"\nName:{name}")10     print(f"Fruit:{fruit}")11 #now,we have one question for whether we could get the key only or just get value
12 #in order to meet the above needs,we should use .key() method
13 print("\n")14 Good_Students=['Jack','Kim']15 '''
16 (solution 1)if 'Fu' not in favorite_fruit.keys():17 print("Fu,please tell me waht fruit you like")18         '''
19 for name infavorite_fruit.keys():20     print(name.title())21     if name inGood_Students:22         fruit=favorite_fruit[name].title()#get the specified value
23         print(f"\t {name.title()},i know you like {fruit}")#the same meaning
24     if 'Fu' not infavorite_fruit.keys():25         print("Fu,please tell me waht fruit you like")26         '''
27 #if the code is set in this place ,we will find it will be print many times!28 #so,we need one solution to solve it29 #for instance,we can adjust the place the code is30 (solution 2)if 'Fu' not in favorite_fruit.keys():31 #print("Fu,please tell me waht fruit you like")32         '''
33 #we have solved the above problem,so why not try to traversal the value?
34 print("there are many kinds of fruit that student like\n")35 for fruits infavorite_fruit.values():36     print(fruits.title())37     #find the fruit which initials is A
38     if(fruits[:1].title()=='A'):39         print("\t the fruit's initials is A")40 #however,if there are many duplicate values in the set,that means the program will do useless work
41 #To solve the problem,we can use .set()
42 for fruits inset(favorite_fruit.values()):43     print(fruits.title())44     #find the fruit which initials is A
45     if(fruits[:1].title()=='A'):46         print("\t the fruit's initials is A")47 #the result is not change
48 #now,we have another question,we have find the way to get values through keys,so,could we find the keys through values?
49 #the answer is Yes,we still ues the same code,and add some new code above the original code
50 defget_key(key,value):51     return [r_key for (r_key,r_value) in key.items() if r_value==value]52 for fruits infavorite_fruit.values():53     print(fruits.title())54     #find the fruit which initials is A
55     if(fruits[:1].title()=='A'):56         find_value=fruits57         goal_key=get_key(favorite_fruit,find_value)58         final_key=goal_key[0]#the value is stored in list
59         print(f"\t {final_key} is the goal keys")

However,at this time,someone maybe think if therer are many data that are related to be stored in the dictionary,it may seem stupid if we still choose to enter the data one by one,

we can use nested,and this is the content of my next blog.

Thank you for your reading!

1、Like the means it seems.the meaning of class is create object instantiation.

For instance

classDog:"""a simple attempt to simulate a puppy"""
    def __init__(self, name, age):"""initialize properties name and age"""self.name=name
self.age
=agedefsit(self):"""simulate dog sit when commanded""" print(f"{self.name}is now sitting.")defroll_over(self):"""simulate dog roll over when commanded""" print(f"{self.name}roll over!")
my_dog
=Dog('Henry',6) #create one class and initialize it print(f"my dog's name is {my_dog.name}")
my_dog.sit()
#call method

2、then ,we maybe want to know,if we need revise the value of attributes,what we need to do ?

we can revise it straightly

my_dog.age=12
print
(f
"
my dog's age is {my_dog.age}
"
)

or we can revise it by method

defupdate_age(self,dog_age):
self.age
=dog_ageprint(f"{self.name}is {self.age}.")#revise the value of age

3、inherit

someone may want to know why we need inherit.sometimes,we have several function need to created but the functionality is the same,so we can inhreit another class to derease our repeated code.the class be called is father,the other is subclass.

class Car:#subclass must behind the father,and father must in included in file
    def __init__(self, make,model,year):
self.make
=make
self.model
=model
self.year
=year
self.odometer_reading
=0defget_discriptive_name(self):
long_name
=f"{self.year} {self.make} {self.model}" returnlong_name.title()defread_odometer(self):print(f"this car has {self.odoment_reading}miles on it")defupdate_odometer(self,mileage):if mileage>=self.odometer_reading:
self.odometer_reading
=mileageelse:print("You can't roll back an odometer")defincrement_odometer(self,miles):
self.odometer_reading
+=milesclass ElectricCar(Car): #subclass is defined,and father'name must be appointed in parentheses def __init__(self, make, model, year):
super().
__init__(make, model, year)#call father's method self.battery_size=75 defdescribe_battery(self):print(f"This car has a {self.battery_size}-kwh battery.")
my_tesla
=ElectricCar('tesla','model s',2019)print(my_tesla.get_discriptive_name())
my_tesla.describe_battery()

then ,we need to consider one problem that if we need create one class which has been writed already,we do not want to write it again.we maybe recall the same solvement used in function.we can do it like do in function.import the class from module

from Class_2 importCar
my_new_car
=Car('audi','a4',2016)print(my_new_car.get_descriptive_name())
my_new_car.odometer_reading
=23my_new_car.read_odometer()

thank you for your reading.