Exemple #1
0
        public static int GetSalesManplusInCreate(int IDEmployee)
        {
            int tempSalary = 0;

            SQLiteConnection DB        = new SQLiteConnection(@"Data Source=" + Environment.CurrentDirectory + "/x86/Salary.db;Pooling=true;FailIfMissing=false;Version=3");
            SQLiteCommand    SalesPlus = new SQLiteCommand(DB);

            SalesPlus.Connection  = DB;
            SalesPlus.CommandText = "with NewTable as (select MainInfo.IDEmployee, MainInfo.ParentID, MainInfo.StartSalary, MainInfo.EntryDate, MainInfo.'Group' from MainInfo where IDEmployee = @IDEmployee union all select N.IDEmployee, N.ParentID, N.StartSalary, N.EntryDate, N.'Group' from NewTable inner join MainInfo N on NewTable.IDEmployee = N.ParentID) select StartSalary, NewTable.'Group', EntryDate, NewTable.IDEmployee ,NewTable.ParentID from NewTable where IDEmployee <> @IDEmployee";
            SalesPlus.Parameters.AddWithValue("@IDEmployee", IDEmployee);
            try
            {
                SalesPlus.Connection.Open();
                SQLiteDataReader dr = SalesPlus.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        int datecalc = DateTime.Now.Year - dr.GetDateTime(2).Year;
                        if (DateTime.Now.Year - dr.GetDateTime(2).Month < 0)
                        {
                            datecalc--;
                        }
                        switch (dr.GetString(1))
                        {
                        case "1)Работник":
                            int exp = dr.GetInt32(0) + Convert.ToInt32(datecalc * dr.GetInt32(0) * 0.03);
                            if (exp > dr.GetInt32(0) * 1.3)
                            {
                                exp = Convert.ToInt32(dr.GetInt32(0) * 1.3);
                            }
                            tempSalary = tempSalary + exp;
                            break;

                        case "2)Менеджер":
                            tempSalary = tempSalary + dr.GetInt32(0) + Convert.ToInt32(datecalc * dr.GetInt32(0) * 0.05) + Manager.GetManagerplusInCreate(dr.GetInt32(3));
                            break;

                        case "3)Продавец":
                            tempSalary = tempSalary + dr.GetInt32(0) + Convert.ToInt32(datecalc * dr.GetInt32(0) * 0.01) + GetSalesManplusInCreate(dr.GetInt32(4));
                            break;
                        }
                    }
                }
                dr.Close();
            }
            catch (Exception ex) { ex.ToString(); }
            finally
            {
                SalesPlus.Connection.Close();
            }
            return(tempSalary);
        }