Ejemplo n.º 1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <lgk.Model.tb_TicketCity> DataTableToList(DataTable dt)
        {
            List <lgk.Model.tb_TicketCity> modelList = new List <lgk.Model.tb_TicketCity>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                lgk.Model.tb_TicketCity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new lgk.Model.tb_TicketCity();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["Name"] != null && dt.Rows[n]["Name"].ToString() != "")
                    {
                        model.Name = dt.Rows[n]["Name"].ToString();
                    }
                    if (dt.Rows[n]["Code"] != null && dt.Rows[n]["Code"].ToString() != "")
                    {
                        model.Code = dt.Rows[n]["Code"].ToString();
                    }
                    if (dt.Rows[n]["City"] != null && dt.Rows[n]["City"].ToString() != "")
                    {
                        model.City = dt.Rows[n]["City"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(lgk.Model.tb_TicketCity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_TicketCity set ");
            strSql.Append("Name=@Name,");
            strSql.Append("Code=@Code,");
            strSql.Append("City=@City");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name", SqlDbType.VarChar, 100),
                new SqlParameter("@Code", SqlDbType.VarChar, 100),
                new SqlParameter("@City", SqlDbType.VarChar, 100),
                new SqlParameter("@ID",   SqlDbType.Int)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Code;
            parameters[2].Value = model.City;
            parameters[3].Value = model.ID;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(lgk.Model.tb_TicketCity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_TicketCity(");
            strSql.Append("Name,Code,City)");
            strSql.Append(" values (");
            strSql.Append("@Name,@Code,@City)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name", SqlDbType.VarChar, 100),
                new SqlParameter("@Code", SqlDbType.VarChar, 100),
                new SqlParameter("@City", SqlDbType.VarChar, 100)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Code;
            parameters[2].Value = model.City;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 4
0
        public lgk.Model.tb_TicketCity GetModel(string where)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Name,Code,City from tb_TicketCity ");
            strSql.Append(" where " + where);

            lgk.Model.tb_TicketCity model = new lgk.Model.tb_TicketCity();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), null);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "")
                {
                    model.Name = ds.Tables[0].Rows[0]["Name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Code"] != null && ds.Tables[0].Rows[0]["Code"].ToString() != "")
                {
                    model.Code = ds.Tables[0].Rows[0]["Code"].ToString();
                }
                if (ds.Tables[0].Rows[0]["City"] != null && ds.Tables[0].Rows[0]["City"].ToString() != "")
                {
                    model.City = ds.Tables[0].Rows[0]["City"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
 protected void LinkButton2_Click(object sender, EventArgs e)
 {
     if (textName.Value == "")
     {
         MessageBox.Show(this.Page, "机场名称不能为空");
         return;
     }
     if (textCode.Value == "")
     {
         MessageBox.Show(this.Page, "三字代码不能为空");
         return;
     }
     lgk.Model.tb_TicketCity model = new lgk.Model.tb_TicketCity();
     model.Name = textName.Value;
     model.Code = textCode.Value;
     model.City = city.Value;
     lgk.Model.tb_TicketCity ischeck = cotybll.GetModel(" Name='" + textName.Value + "'");
     if (ischeck == null)
     {
         cotybll.Add(model);
     }
     else
     {
         MessageBox.Show(this.Page, "该机场已存在");
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 将数据保存到数据库
        /// </summary>
        /// <param name="dt_user"></param>
        protected void SaveToDataBase(System.Data.DataTable dt_user)
        {
            //创建事务s
            SqlTransaction trans_user = null;
            SqlConnection  con        = new SqlConnection(PubConstant.ConnectionString);

            con.Open();
            //事务开始
            trans_user = con.BeginTransaction();
            try
            {
                for (int i = 0; i < dt_user.Rows.Count; i++)
                {
                    string sql = "";
                    lgk.Model.tb_TicketCity city = cotybll.GetModel("Name='" + dt_user.Rows[i][0].ToString() + "'");
                    if (city == null)
                    {
                        sql = "insert into tb_TicketCity (Name,Code,City) values ('" + dt_user.Rows[i][0].ToString() + "','" + dt_user.Rows[i][1].ToString() + "','" + dt_user.Rows[i][2].ToString() + "')";
                    }
                    else
                    {
                        sql = "update tb_TicketCity set Code='" + dt_user.Rows[i][1].ToString() + "' where Name='" + dt_user.Rows[i][0].ToString() + "'";
                    }

                    object obj = DbHelperSQL.GetSingle(sql.ToString());
                }
                trans_user.Commit();
                //flagOk = true;
                MessageBox.Show(this.Page, "数据导入成功!");
            }
            catch (Exception ex)
            {
                trans_user.Rollback();

                MessageBox.Show(this.Page, "数据导入失败!" + ex.ToString().Substring(0, ex.ToString().IndexOf("。") + 1) + " <br />请检查文件内容后重新导入!");
            }
            finally
            {
                con.Close();
                trans_user = null;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(lgk.Model.tb_TicketCity model)
 {
     return(dal.Update(model));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(lgk.Model.tb_TicketCity model)
 {
     return(dal.Add(model));
 }