コード例 #1
0
        public bool ReadData(short requestID, VMEditEmpData empData = null)
        {
            bool error = false;

            try
            {
                using (conn = new SqlConnection(CONNECTION_STRING))
                {
                    EmpRecord record;

                    conn.Open();
                    cmd            = new SqlCommand();
                    cmd.Connection = conn;

                    switch (requestID)
                    {
                    case (short)RequestType.SELECT_ALL:
                        Employee = null;
                        Employee = new List <EmpRecord>();

                        cmd.CommandText = requests[(short)RequestType.SELECT_ALL];
                        SqlDataReader rd = cmd.ExecuteReader();

                        foreach (IDataRecord dataRow in rd)
                        {
                            empID       = dataRow.GetInt32((short)FieldNbr.ONE);
                            empName     = dataRow.GetString((short)FieldNbr.TWO);
                            empPosition = dataRow.GetString((short)FieldNbr.THREE);
                            empSalary   = dataRow.GetDecimal((short)FieldNbr.FOUR);

                            record = new EmpRecord()
                            {
                                ID = empID, Name = empName, Position = empPosition, Salary = empSalary
                            };
                            emp.Add(record);
                        }

                        break;

                    case (short)RequestType.UPDATE_ALL:
                        cmd.CommandText = requests[(short)RequestType.UPDATE_ALL] + empData.EditID;
                        cmd.Parameters.AddWithValue("@name", empData.EditName);
                        cmd.Parameters.AddWithValue("@pos", empData.EditPosition);
                        cmd.Parameters.AddWithValue("@payRate", empData.EditSalary);
                        cmd.ExecuteNonQuery();

                        break;
                    }
                }

                Message = MAIN_MESSAGE;
            }
            catch (Exception ex)
            {
                error   = true;
                Message = ex.Message.ToString();
            }

            return(error);
        }
コード例 #2
0
        public Edit()
        {
            InitializeComponent();
            vmEmpEdit   = new VMEditEmpData();
            DataContext = vmEmpEdit;

            //Get values from ListView (main form)
            this.GetDataFromListView();
        }