帮助我在下面的程序 [英] help me in the below program
本文介绍了帮助我在下面的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Collections;
using System .Collections.Generic ;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.OleDb;
using System.ComponentModel;
public partial class _Default : System.Web.UI.Page
{
class Point { double X, Y; }
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string connectionString = "";
if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string fileLocation = Server.MapPath("~/App_Data/" + fileName);
FileUpload1.SaveAs(fileLocation);
if (fileExtension == ".xls")
{
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (fileExtension == ".xlsx")
{
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
ArrayList List = new ArrayList();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
if (Session["dtInSession"] != null)
{
dt = (DataTable)Session["dtInSession"];
}
for (int i = 0; i < dtExcelRecords.Rows.Count; i++)
{
//if you want to get the string
DataRow thisRow = (DataRow)dtExcelRecords.Rows[i];
string X = Convert.ToString(thisRow["X"]);
string Y = Convert.ToString(thisRow["Y"]);
//double Length = Convert.ToDouble(Y);
double X1 = Convert.ToDouble(X);
double Y1 = Convert.ToDouble(Y);
DataRow dr = dt.NewRow();
polygonArea(X,Y);
}
}
}
//calculation
private Double polygonArea(int X[],int Y[])
{
Double area = 0.0;
int j = X.Length - 1;
for (int i=0; i < X.Length; i++)
{
area=area+(X[j]+X[i]*(Y[j]-Y[i]));
j=i;
}
area =area/ 2;
if (area < 0)
area = area * -1;
return area;
}
}
推荐答案
今天第三次!
更改:
For the third time today!
Change:
private Double polygonArea(int X[],int Y[])
收件人:
To:
private Double polygonArea(int[] X,int[] Y)
这篇关于帮助我在下面的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文