Exemplo n.º 1
0
        private void UpdateTerminal()
        {
            if (MessageBox.Show(string.Format(UpdateConfirmText, "Terminal"), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }
            try
            {
                using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
                {
                    Conn.Open();
                    using (SqlTransaction tran = Conn.BeginTransaction())
                    {
                        if ((int)Conn.ExecuteScalar("SELECT COUNT(*) FROM TERMINALS WHERE TERMINAL_NAME = @TERMINAL_NAME AND TERMINAL_CODE = @TERMINAL_CODE", TheTerminal, tran) > 0)
                        {
                            MessageBox.Show("Same Terminal Name already exist. Please enter unique Name and try again", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            return;
                        }
                        string Remarks = Newtonsoft.Json.JsonConvert.SerializeObject(Conn.Query <Terminal>("SELECT * FROM TERMINALS WHERE TERMINAL_CODE = @TERMINAL_CODE", TheTerminal.TERMINAL_CODE, tran).First());
                        TheTerminal.UID = GlobalClass.User.UID;
                        if (TheTerminal.Update(tran))
                        {
                            GlobalClass.SetUserActivityLog(tran, "Terminal Setting", "Edit", WorkDetail: "TERMINAL_CODE : " + TheTerminal.TERMINAL_CODE, Remarks: Remarks);
                            tran.Commit();
                            MessageBox.Show("Terminal Updated Successfully", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                            var terminal = TerminalList.First(x => x.TERMINAL_CODE == TheTerminal.TERMINAL_CODE);
                            terminal.TERMINAL_NAME = TheTerminal.TERMINAL_NAME;
                            terminal.STATUS        = TheTerminal.STATUS;
                            ExecuteUndo(null);
                        }
                        else
                        {
                            MessageBox.Show("Terminal could not be saved. Please check entered data and try again.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                }
            }

            catch (SqlException ex)
            {
                if (ex.Number == 2601)
                {
                    MessageBox.Show("Entered Terminal name already exist in the database. Enter unique name and try again", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
                }
                MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
 private void SaveTerminal()
 {
     if (MessageBox.Show(string.Format(SaveConfirmText, MessageBoxCaption), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 if (TheTerminal.Save(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Terminal Setting", "New", WorkDetail: "TERMINAL_CODE : " + TheTerminal.TERMINAL_CODE, Remarks: TheTerminal.TERMINAL_NAME);
                     tran.Commit();
                     MessageBox.Show("Terminal Saved Successfully", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     TerminalList.Add(new Terminal {
                         TERMINAL_NAME = TheTerminal.TERMINAL_NAME, TERMINAL_CODE = TheTerminal.TERMINAL_CODE, UID = TheTerminal.UID, STATUS = TheTerminal.STATUS
                     });
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Terminal could not be saved. Please check entered data and try again.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 2627)
         {
             MessageBox.Show("Entered Terminal Code already exist in the database. Enter unique Code and try again", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         MessageBox.Show(ex.Number + " : " + ex.Message, "Vehicle Type", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 3
0
 private void ExecuteDelete(object obj)
 {
     if (MessageBox.Show(string.Format(DeleteConfirmText, "Terminal"), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 string Remarks = Newtonsoft.Json.JsonConvert.SerializeObject(Conn.Query <Terminal>("SELECT * FROM TERMINALS WHERE TERMINAL_CODE = @TERMINAL_CODE", TheTerminal.TERMINAL_CODE, tran).First());
                 if (TheTerminal.Delete(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Terminal Setting", "DELETE", WorkDetail: "TERMINAL_CODE : " + TheTerminal.TERMINAL_CODE, Remarks: Remarks);
                     tran.Commit();
                     MessageBox.Show("Terminal Deleted Successfully", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     TerminalList.Remove(TerminalList.First(x => x.TERMINAL_CODE == TheTerminal.TERMINAL_CODE));
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Terminal could not be Deleted. Please check entered data and try again.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 547)
         {
             MessageBox.Show("Selected Terminal cannot be deleted because it has already been linked to another transaction.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }