protected void ImportExcel(string FilePath, string SheetName)
        {
            JTable tab  = new JTable("NEWTRAIN");
            JTable tab1 = new JTable("NEWTRAIN");

            String FileName1 = HttpContext.Current.Server.MapPath(FilePath);

            if (File.Exists(FileName1))
            {
                DataSet                     ds1       = BusinessRule.PubCode.Util.xsldata(Server.MapPath(FilePath), SheetName);
                List <SearchField>          condition = new List <SearchField>();
                Dictionary <string, object> data      = new Dictionary <string, object>();
                if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
                {
                    int      n   = ds1.Tables[0].Columns.Count;
                    JCommand cmd = new JCommand(JConnect.GetConnect());
                    cmd.CommandText = "select max(num) from NEWTRAIN";
                    int num = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.Close();
                    for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                    {
                        condition.Clear();
                        condition.Add(new SearchField("TRAINNAME", ds1.Tables[0].Rows[i]["车次"].ToString()));
                        data.Clear();
                        data.Add("TRAINNAME", ds1.Tables[0].Rows[i]["车次"].ToString());
                        data.Add("ASTATION", ds1.Tables[0].Rows[i]["始发站"].ToString());
                        data.Add("BSTATION", ds1.Tables[0].Rows[i]["终到站"].ToString());
                        data.Add("TRAINBIGKIND", 0);
                        data.Add("TRAINTYPE", ds1.Tables[0].Rows[i]["列车类型"].ToString());
                        data.Add("MILE", ds1.Tables[0].Rows[i]["单程距离"].ToString());
                        data.Add("KXTS", ds1.Tables[0].Rows[i]["开行趟数"].ToString());
                        data.Add("CDZS", ds1.Tables[0].Rows[i]["车底组数"].ToString());
                        data.Add("YINZUO", ds1.Tables[0].Rows[i]["硬座"].ToString());
                        data.Add("RUANZUO", ds1.Tables[0].Rows[i]["软座"].ToString());
                        data.Add("OPENYINWO", ds1.Tables[0].Rows[i]["硬卧"].ToString());
                        data.Add("RUANWO", ds1.Tables[0].Rows[i]["软卧"].ToString());
                        data.Add("CANCHE", ds1.Tables[0].Rows[i]["餐车"].ToString());
                        data.Add("FADIANCHE", ds1.Tables[0].Rows[i]["发电车"].ToString());
                        data.Add("SHUYINCHE", ds1.Tables[0].Rows[i]["行李车"].ToString());
                        data.Add("YOUZHENGCHE", ds1.Tables[0].Rows[i]["邮政车"].ToString());
                        if (!tab1.HasData(condition))
                        {
                            data.Add("num", Convert.ToInt32(num) + 1);
                            tab.InsertData(data);
                            num++;
                        }
                        else
                        {
                            tab.EditData(data, condition);
                        }
                    }
                }
            }
            tab.Close();
            tab1.Close();
            WebFrame.Util.JAjax.Alert("导入完成!");
        }
Пример #2
0
        protected void ImportExcel(string FilePath, string SheetName)
        {
            JTable tab  = new JTable("HIGHTRAINPROFILE");
            JTable tab1 = new JTable("HIGHTRAINPROFILE");

            String FileName1 = HttpContext.Current.Server.MapPath(FilePath);

            if (File.Exists(FileName1))
            {
                DataSet                     ds1       = BusinessRule.PubCode.Util.xsldata(Server.MapPath(FilePath), SheetName);
                List <SearchField>          condition = new List <SearchField>();
                Dictionary <string, object> data      = new Dictionary <string, object>();
                if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
                {
                    int      n   = ds1.Tables[0].Columns.Count;
                    JCommand cmd = new JCommand(JConnect.GetConnect());
                    cmd.CommandText = "select max(id) from HIGHTRAINPROFILE";
                    int num = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.Close();
                    for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                    {
                        condition.Clear();
                        condition.Add(new SearchField("HIGHTRAINTYPE", ds1.Tables[0].Rows[i]["动车类型"].ToString()));
                        data.Clear();
                        data.Add("HIGHTRAINTYPE", ds1.Tables[0].Rows[i]["动车类型"].ToString());
                        data.Add("MILETYPE", ds1.Tables[0].Rows[i]["动车类别"].ToString());
                        data.Add("RATE1", ds1.Tables[0].Rows[i]["一等座基本票价"].ToString());
                        data.Add("PCOUNT1", ds1.Tables[0].Rows[i]["一等座定员"].ToString());
                        data.Add("RATE2", ds1.Tables[0].Rows[i]["二等座基本票价"].ToString());
                        data.Add("PCOUNT2", ds1.Tables[0].Rows[i]["二等座定员"].ToString());
                        data.Add("RATE3", ds1.Tables[0].Rows[i]["动卧上铺基本票价"].ToString());
                        data.Add("RATE31", ds1.Tables[0].Rows[i]["动卧下铺基本票价"].ToString());
                        data.Add("PCOUNT3", ds1.Tables[0].Rows[i]["动卧定员"].ToString());
                        data.Add("RATE4", ds1.Tables[0].Rows[i]["商务座基本票价"].ToString());
                        data.Add("PCOUNT4", ds1.Tables[0].Rows[i]["商务座定员"].ToString());

                        if (!tab1.HasData(condition))
                        {
                            data.Add("id", Convert.ToInt32(num) + 1);
                            data.Add("SPEED", 0);
                            data.Add("PRICE", 0);
                            data.Add("COST1", 0);
                            data.Add("COST2", 0);
                            data.Add("COST3", 0);
                            data.Add("COST21", 0);
                            data.Add("COST22", 0);
                            data.Add("SPEED2", 0);
                            data.Add("SPEED3", 0);
                            tab.InsertData(data);
                            num++;
                        }
                        else
                        {
                            tab.EditData(data, condition);
                        }
                    }
                }
            }
            tab.Close();
            tab1.Close();
            WebFrame.Util.JAjax.Alert("导入完成!");
        }