Esempio n. 1
0
        public IHttpActionResult Posttb_Employee(tb_Employee tb_Employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tb_Employee.Add(tb_Employee);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (tb_EmployeeExists(tb_Employee.EMP_CODE))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tb_Employee.EMP_CODE }, tb_Employee));
        }
Esempio n. 2
0
        public IHttpActionResult Puttb_Employee(int id, tb_Employee tb_Employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tb_Employee.EMP_CODE)
            {
                return(BadRequest());
            }

            db.Entry(tb_Employee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tb_EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 3
0
        public IHttpActionResult Gettb_Employee(int id)
        {
            tb_Employee tb_Employee = db.tb_Employee.Find(id);

            if (tb_Employee == null)
            {
                return(NotFound());
            }

            return(Ok(tb_Employee));
        }
Esempio n. 4
0
        public IHttpActionResult Deletetb_Employee(int id)
        {
            tb_Employee tb_Employee = db.tb_Employee.Find(id);

            if (tb_Employee == null)
            {
                return(NotFound());
            }

            db.tb_Employee.Remove(tb_Employee);
            db.SaveChanges();

            return(Ok(tb_Employee));
        }
Esempio n. 5
0
        //删除
        public Boolean Delete(tb_Employee employee)
        {
            string sqlDelete = "update tb_EmpInfo  set ";

            sqlDelete += "EmpFlag='" + employee.intEmpFlag + "' where EmpID ='" + employee.intEmpID + "'";
            try
            {
                SqlConnection conn = (new GetSqlConnection()).GetCon();
                SqlCommand    cmd  = new SqlCommand(sqlDelete, conn);
                cmd.ExecuteNonQuery();
                conn.Dispose();
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return(false);
            }
        }
Esempio n. 6
0
        //添加
        public Boolean Add(tb_Employee employee)
        {
            MessageBox.Show(employee.daEmpBirthday.ToString());
            string sqlAdd = "insert into tb_EmpInfo values( ";

            sqlAdd += "'" + employee.intEmpID + "','" + employee.strEmpName + "','" + employee.strEmpLoginName + "',";
            sqlAdd += "'" + employee.strEmpLoginPwd + "','" + employee.intEmpSex + "','" + employee.daEmpBirthday + "',";
            sqlAdd += "'" + employee.strEmpDept + "','" + employee.strEmpPost + "','" + employee.strEmpPhone + "',";
            sqlAdd += "'" + employee.strEmpPhoneM + "','" + employee.strEmpAddress + "'," + employee.intEmpFlag + ")";
            try
            {
                SqlConnection conn = (new GetSqlConnection()).GetCon();
                SqlCommand    cmd  = new SqlCommand(sqlAdd, conn);
                cmd.ExecuteNonQuery();
                conn.Dispose();
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
        }
Esempio n. 7
0
        //修改
        public Boolean Update(tb_Employee employee)
        {
            string sqlUpdate = "update tb_EmpInfo  set ";

            sqlUpdate += "EmpName='" + employee.strEmpName + "',EmpLoginName='" + "',";
            sqlUpdate += "EmpSex='" + employee.intEmpSex + "',EmpBirthday='" + employee.daEmpBirthday + "',EmpDept='" + employee.strEmpDept + "',";
            sqlUpdate += "EmpPost='" + employee.strEmpPost + "',EmpPhone='" + employee.strEmpPhone + "', EmpPhoneM='" + employee.strEmpPhoneM + "',";
            sqlUpdate += "EmpAddress='" + employee.strEmpAddress + "' where EmpID = '" + employee.intEmpID + "'";

            MessageBox.Show(sqlUpdate);
            try
            {
                SqlConnection conn = (new GetSqlConnection()).GetCon();
                SqlCommand    cmd  = new SqlCommand(sqlUpdate, conn);
                cmd.ExecuteNonQuery();
                conn.Dispose();
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return(false);
            }
        }