Esempio n. 1
0
        //public ReturnMachineMtnFrequency Insert(MachineMtnFrequency machineMtnFrequency)
        //{
        //    ReturnMachineMtnFrequency returnMachineMtnFrequency = new ReturnMachineMtnFrequency();
        //    try
        //    {
        //        using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
        //        {
        //            using (SqlCommand cmd = new SqlCommand("", sqlConnection))
        //            {
        //                cmd.CommandText = "sp_tMachineMtnFrequency_InsertUpdate";
        //                cmd.CommandType = CommandType.StoredProcedure;
        //                cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = machineMtnFrequency.ID;
        //                cmd.Parameters.Add(new SqlParameter("@MachineID", SqlDbType.VarChar)).Value = machineMtnFrequency.MachineID;
        //                cmd.Parameters.Add(new SqlParameter("@FrequencyID", SqlDbType.SmallInt)).Value = machineMtnFrequency.FrequencyID;
        //                cmd.ExecuteNonQuery();

        //                returnMachineMtnFrequency.Code = "00";
        //                returnMachineMtnFrequency.Message = "Cập nhật dữ liệu thành công.";
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        returnMachineMtnFrequency.Code = "99";
        //        returnMachineMtnFrequency.Message = "Lỗi xử lý dữ liệu: " + ex.ToString();
        //        returnMachineMtnFrequency.Total = 0;
        //        returnMachineMtnFrequency.lstMachineMtnFrequency = null;
        //    }
        //    return returnMachineMtnFrequency;
        //}

        public ReturnMachineMtnFrequency Insert(MachineMtnFrequency machineMtnFrequency)
        {
            ReturnMachineMtnFrequency returnMachineMtnFrequency = new ReturnMachineMtnFrequency();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tMachineMtnFrequency_InsertUpdate";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value               = machineMtnFrequency.ID;
                        cmd.Parameters.Add(new SqlParameter("@MachineID", SqlDbType.VarChar)).Value    = machineMtnFrequency.MachineID;
                        cmd.Parameters.Add(new SqlParameter("@FrequencyID", SqlDbType.SmallInt)).Value = machineMtnFrequency.FrequencyID;
                        cmd.ExecuteNonQuery();

                        returnMachineMtnFrequency.Code    = "00";
                        returnMachineMtnFrequency.Message = "Cập nhật dữ liệu thành công.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnMachineMtnFrequency.Code    = "99";
                returnMachineMtnFrequency.Message = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnMachineMtnFrequency.Total   = 0;
                returnMachineMtnFrequency.lstMachineMtnFrequency = null;
                mylog4net.Error("", ex);
            }
            return(returnMachineMtnFrequency);
        }
Esempio n. 2
0
        public ReturnMachineMtnFrequency GetbyMachineID(string MachineID)
        {
            List <MachineMtnFrequency> lstMachineMtnFrequency    = null;
            MachineMtnFrequency        machineMtnFrequency       = null;
            ReturnMachineMtnFrequency  returnMachineMtnFrequency = new ReturnMachineMtnFrequency();

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

                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd, sqlConnection))
                        {
                            if (sqlDr.HasRows)
                            {
                                lstMachineMtnFrequency = new List <MachineMtnFrequency>();
                                while (sqlDr.Read())
                                {
                                    machineMtnFrequency             = new MachineMtnFrequency();
                                    machineMtnFrequency.ID          = Convert.ToInt16(sqlDr["ID"].ToString());
                                    machineMtnFrequency.MachineID   = sqlDr["MachineID"].ToString();
                                    machineMtnFrequency.FrequencyID = Convert.ToInt16(sqlDr["FrequencyID"].ToString());

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