Ejemplo n.º 1
0
        public static t_unit GetModel(long id)
        {
            t_unit result = new t_unit();
            string sql    = @"
                            select  * from t_unit where status_code!=-1 {0} ;
                        ";

            using (MySqlConnection sql_conn = new MySqlConnection(mysqlCon))
            {
                string strWhere = "";
                if (!string.IsNullOrEmpty(id.ToString()) && id != 0)
                {
                    strWhere += " and id= " + id + "";
                }

                sql = string.Format(sql, strWhere);
                sql_conn.Open();
                MySqlCommand cmd = new MySqlCommand(sql, sql_conn);
                DataSet      ds  = new DataSet();

                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                adapter.Fill(ds);

                result = (t_unit)IListDataSet.DataSetToIList <t_unit>(ds, 0)[0];
                return(result);
            }
        }
Ejemplo n.º 2
0
        //copy复制
        public ActionResult Copy(string formVals = "{}")
        {
            var vmResult = new CommonAjaxResponseModel <bool>();

            try
            {
                t_unit model = formVals.ToModel <t_unit>();


                //  t_unit model2 = UnitDAL.GetModel(model.id);

                int unit_id = UnitDAL.CopyUnit(model);

                //List<t_unit_goods> uglist = UnitDAL.GetUnitGoodsListById(model.id);

                if (unit_id != 0 && unit_id != model.id)
                {
                    UnitDAL.CopyUnitGoods(model.id, unit_id);

                    vmResult.BFlag = CommonResponseBFlag.Success;
                    vmResult.TData = true;
                }
            }
            catch (Exception ex)
            {
                vmResult.BFlag = CommonResponseBFlag.SysError;
                vmResult.Msg   = ex.Message;
            }
            return(Json(vmResult));
        }
Ejemplo n.º 3
0
        //添加系列 -编辑
        public ActionResult Add(string formVals = "{}")
        {
            var vmResult = new CommonAjaxResponseModel <bool>();

            try
            {
                t_unit model = formVals.ToModel <t_unit>();

                if (model.id != 0)
                {
                    UnitDAL.Update(model);

                    vmResult.BFlag = CommonResponseBFlag.Success;
                    vmResult.TData = true;
                }
                else
                {
                    //插入
                    model.status_code = 1;
                    UnitDAL.Add(model);
                    vmResult.BFlag = CommonResponseBFlag.Success;
                    vmResult.TData = true;
                }
            }
            catch (Exception ex)
            {
                vmResult.BFlag = CommonResponseBFlag.SysError;
                vmResult.Msg   = ex.Message;
            }
            return(Json(vmResult));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public t_unit DataRowToModel(DataRow row)
        {
            t_unit model = new t_unit();

            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["code"] != null)
                {
                    model.code = row["code"].ToString();
                }
                if (row["unit_kind"] != null)
                {
                    model.unit_kind = row["unit_kind"].ToString();
                }
                if (row["unit_name"] != null)
                {
                    model.unit_name = row["unit_name"].ToString();
                }
                if (row["count"] != null && row["count"].ToString() != "")
                {
                    model.count = int.Parse(row["count"].ToString());
                }
                if (row["price"] != null && row["price"].ToString() != "")
                {
                    model.price = decimal.Parse(row["price"].ToString());
                }
                if (row["total_price"] != null && row["total_price"].ToString() != "")
                {
                    model.total_price = decimal.Parse(row["total_price"].ToString());
                }
                if (row["begin_time"] != null && row["begin_time"].ToString() != "")
                {
                    model.begin_time = DateTime.Parse(row["begin_time"].ToString());
                }
                if (row["end_time"] != null && row["end_time"].ToString() != "")
                {
                    model.end_time = DateTime.Parse(row["end_time"].ToString());
                }
                if (row["status_code"] != null && row["status_code"].ToString() != "")
                {
                    model.status_code = int.Parse(row["status_code"].ToString());
                }
                if (row["create_time"] != null && row["create_time"].ToString() != "")
                {
                    model.create_time = DateTime.Parse(row["create_time"].ToString());
                }
                if (row["update_time"] != null && row["update_time"].ToString() != "")
                {
                    model.update_time = DateTime.Parse(row["update_time"].ToString());
                }
            }
            return(model);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(t_unit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_unit set ");
            strSql.Append("code=@code,");
            strSql.Append("unit_kind=@unit_kind,");
            strSql.Append("unit_name=@unit_name,");
            strSql.Append("count=@count,");
            strSql.Append("price=@price,");
            strSql.Append("total_price=@total_price,");
            strSql.Append("begin_time=@begin_time,");
            strSql.Append("end_time=@end_time,");
            strSql.Append("status_code=@status_code,");
            strSql.Append("create_time=@create_time,");
            strSql.Append("update_time=@update_time");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@code",        MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_kind",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_name",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@count",       MySqlDbType.Int32,      11),
                new MySqlParameter("@price",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@total_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@begin_time",  MySqlDbType.DateTime),
                new MySqlParameter("@end_time",    MySqlDbType.DateTime),
                new MySqlParameter("@status_code", MySqlDbType.Int32,     255),
                new MySqlParameter("@create_time", MySqlDbType.DateTime),
                new MySqlParameter("@update_time", MySqlDbType.DateTime),
                new MySqlParameter("@id",          MySqlDbType.Int32, 11)
            };
            parameters[0].Value  = model.code;
            parameters[1].Value  = model.unit_kind;
            parameters[2].Value  = model.unit_name;
            parameters[3].Value  = model.count;
            parameters[4].Value  = model.price;
            parameters[5].Value  = model.total_price;
            parameters[6].Value  = model.begin_time;
            parameters[7].Value  = model.end_time;
            parameters[8].Value  = model.status_code;
            parameters[9].Value  = model.create_time;
            parameters[10].Value = model.update_time;
            parameters[11].Value = model.id;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

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

            strSql.Append("insert into t_unit(");
            strSql.Append("code,unit_kind,unit_name,count,price,total_price,begin_time,end_time,status_code,create_time,update_time)");
            strSql.Append(" values (");
            strSql.Append("@code,@unit_kind,@unit_name,@count,@price,@total_price,@begin_time,@end_time,@status_code,@create_time,@update_time)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@code",        MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_kind",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_name",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@count",       MySqlDbType.Int32,      11),
                new MySqlParameter("@price",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@total_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@begin_time",  MySqlDbType.DateTime),
                new MySqlParameter("@end_time",    MySqlDbType.DateTime),
                new MySqlParameter("@status_code", MySqlDbType.Int32,     255),
                new MySqlParameter("@create_time", MySqlDbType.DateTime),
                new MySqlParameter("@update_time", MySqlDbType.DateTime)
            };
            parameters[0].Value  = model.code;
            parameters[1].Value  = model.unit_kind;
            parameters[2].Value  = model.unit_name;
            parameters[3].Value  = model.count;
            parameters[4].Value  = model.price;
            parameters[5].Value  = model.total_price;
            parameters[6].Value  = model.begin_time;
            parameters[7].Value  = model.end_time;
            parameters[8].Value  = model.status_code;
            parameters[9].Value  = model.create_time;
            parameters[10].Value = model.update_time;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public ActionResult UnitGoodsList(long?id)
        {
            if (id == null)
            {
                Response.Redirect(Url.Action("Index", "Unit"));
                return(View());
            }
            long newId = (long)id;

            t_unit model = UnitDAL.GetModel(newId);

            //List<t_unit_goods> goods_list = new List<t_unit_goods>();
            //if(UnitDAL.GetUnitGoodsList(newId)!=null)
            // goods_list = UnitDAL.GetUnitGoodsList(newId);

            ViewBag.unit_model = model;
            //ViewBag.goods_list = goods_list;


            return(View());
        }
Ejemplo n.º 8
0
        public static int CopyUnit(t_unit model)
        {
            int    unit_id = 0;
            string sql     = @"INSERT INTO `t_unit` (`code`, `unit_kind`, `unit_name`, `count`, `price`, `total_price`, `begin_time`, `end_time`, `status_code`, `create_time`) 
select @code, @unit_kind, @unit_name, count, price, total_price,begin_time,end_time, status_code,now() from t_unit where id=@id;
 ";

            using (MySqlConnection sql_conn = new MySqlConnection(mysqlCon))
            {
                sql_conn.Open();
                MySqlCommand cmd = new MySqlCommand(sql, sql_conn);
                cmd.Parameters.AddWithValue("@code", model.code);
                cmd.Parameters.AddWithValue("@unit_kind", model.unit_kind);
                cmd.Parameters.AddWithValue("@unit_name", model.unit_name);
                cmd.Parameters.AddWithValue("@id", model.id);

                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                int p = cmd.ExecuteNonQuery();

                if (p == 1)
                {
                    string       sql2 = "select id from t_unit where code=@code and unit_kind=@unit_kind and unit_name=@unit_name and id<>@id;";
                    MySqlCommand cmd2 = new MySqlCommand(sql2, sql_conn);
                    cmd2.Parameters.AddWithValue("@code", model.code);
                    cmd2.Parameters.AddWithValue("@unit_kind", model.unit_kind);
                    cmd2.Parameters.AddWithValue("@unit_name", model.unit_name);
                    cmd2.Parameters.AddWithValue("@id", model.id);

                    DataSet          ds       = new DataSet();
                    MySqlDataAdapter adapter2 = new MySqlDataAdapter(cmd2);
                    adapter2.Fill(ds);

                    unit_id = int.Parse(ds.Tables[0].Rows[0][0].ToString());
                }

                return(unit_id);
            }
        }
Ejemplo n.º 9
0
        public static int Add(t_unit model)
        {
            string sql = @"

INSERT INTO `t_unit` (`code`, `unit_kind`, `unit_name`, `count`, `price`, `total_price`, `begin_time`, `end_time`, `status_code`,create_time) 
select @code, @unit_kind,@unit_name,@count,@price,@total_price,@begin_time,@end_time,1,now()";

            using (MySqlConnection sql_conn = new MySqlConnection(mysqlCon))
            {
                sql_conn.Open();
                MySqlCommand cmd = new MySqlCommand(sql, sql_conn);
                cmd.Parameters.AddWithValue("@code", model.code);
                cmd.Parameters.AddWithValue("@unit_kind", model.unit_kind);
                cmd.Parameters.AddWithValue("@unit_name", model.unit_name);
                cmd.Parameters.AddWithValue("@count", model.count);
                cmd.Parameters.AddWithValue("@price", model.price);
                cmd.Parameters.AddWithValue("@total_price", model.count * model.price);
                cmd.Parameters.AddWithValue("@begin_time", model.begin_time);
                cmd.Parameters.AddWithValue("@end_time", model.end_time);
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                int p = cmd.ExecuteNonQuery();
                return(p);
            }
        }
Ejemplo n.º 10
0
        public static int Update(t_unit model)
        {
            string sql = @"
UPDATE `t_unit` SET `code`=@code, `unit_kind`=@unit_kind, `unit_name`=@unit_name, `count`=@count, `price`=@price, `total_price`=@total_price, `begin_time`=@begin_time, `end_time`=@end_time, `update_time`=now() WHERE `id`=@id;";

            using (MySqlConnection sql_conn = new MySqlConnection(mysqlCon))
            {
                sql_conn.Open();
                MySqlCommand cmd = new MySqlCommand(sql, sql_conn);
                cmd.Parameters.AddWithValue("@code", model.code);
                cmd.Parameters.AddWithValue("@unit_kind", model.unit_kind);
                cmd.Parameters.AddWithValue("@unit_name", model.unit_name);
                cmd.Parameters.AddWithValue("@count", model.count);
                cmd.Parameters.AddWithValue("@price", model.price);
                cmd.Parameters.AddWithValue("@total_price", model.count * model.price);
                cmd.Parameters.AddWithValue("@begin_time", model.begin_time);
                cmd.Parameters.AddWithValue("@end_time", model.end_time);

                cmd.Parameters.AddWithValue("@id", model.id);
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                int p = cmd.ExecuteNonQuery();
                return(p);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public t_unit GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,code,unit_kind,unit_name,count,price,total_price,begin_time,end_time,status_code,create_time,update_time from t_unit ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            t_unit  model = new t_unit();
            DataSet ds    = DbHelperMySQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(t_unit model)
 {
     return(dal.Update(model));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(t_unit model)
 {
     return(dal.Add(model));
 }