Esempio n. 1
0
        public ReturnMachinePart Insert(MachinePart machinePart)
        {
            ReturnMachinePart returnMachinePart = new ReturnMachinePart();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tMachinePart_InsertUpdate";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value               = machinePart.ID;
                        cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar)).Value        = machinePart.Name;
                        cmd.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar)).Value = machinePart.Description;
                        cmd.Parameters.Add(new SqlParameter("@MachineType", SqlDbType.Int)).Value      = machinePart.MachineType;
                        cmd.ExecuteNonQuery();

                        returnMachinePart.Code    = "00";
                        returnMachinePart.Message = "Cập nhật dữ liệu thành công.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnMachinePart.Code           = "99";
                returnMachinePart.Message        = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnMachinePart.Total          = 0;
                returnMachinePart.lstMachinePart = null;
                mylog4net.Error("", ex);
            }
            return(returnMachinePart);
        }
Esempio n. 2
0
        public ReturnMachinePart GetbyID(int ID)
        {
            List <MachinePart> lstMachinePart    = null;
            MachinePart        machinePart       = null;
            ReturnMachinePart  returnMachinePart = new ReturnMachinePart();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        //cmd.Connection = _sqlConnection;
                        cmd.CommandText = "sp_tMachinePart_SelectByID";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = ID;

                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd, sqlConnection))
                        {
                            if (sqlDr.HasRows)
                            {
                                lstMachinePart = new List <MachinePart>();
                                while (sqlDr.Read())
                                {
                                    machinePart             = new MachinePart();
                                    machinePart.ID          = int.Parse(sqlDr["ID"].ToString());
                                    machinePart.Name        = sqlDr["Name"].ToString();
                                    machinePart.Description = sqlDr["Description"].ToString();
                                    machinePart.MachineType = int.Parse(sqlDr["MachineType"].ToString());
                                    machinePart.DateCreated = DateTime.Parse(sqlDr["DateCreated"].ToString());

                                    lstMachinePart.Add(machinePart);
                                }
                                returnMachinePart.Code           = "00";
                                returnMachinePart.Message        = "Lấy dữ liệu thành công.";
                                returnMachinePart.lstMachinePart = lstMachinePart;
                            }
                            else
                            {
                                returnMachinePart.Code           = "01";
                                returnMachinePart.Message        = "Không tồn tại bản ghi nào.";
                                returnMachinePart.Total          = 0;
                                returnMachinePart.lstMachinePart = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnMachinePart.Code           = "99";
                returnMachinePart.Message        = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnMachinePart.Total          = 0;
                returnMachinePart.lstMachinePart = null;
                mylog4net.Error("", ex);
            }
            return(returnMachinePart);
        }