Exemple #1
0
        public void AddExpenseItem(string key, string operationExpenseItem, double cost, fad3DataStatus dataStatus, string unit, double unitQuantity, string expenseItemGuid = "")
        {
            FishingExpenseItemsPerOperation expenseItem = new FishingExpenseItemsPerOperation(key, operationExpenseItem, cost, unit, unitQuantity, dataStatus);

            if (dataStatus == fad3DataStatus.statusNew)
            {
                expenseItemGuid = Guid.NewGuid().ToString();
            }
            _expenseItemsList.Add(expenseItemGuid, expenseItem);
        }
Exemple #2
0
        public static (ExpensePerOperation exp, bool success) ReadData(string samplingGuid, bool readComplete = false)
        {
            ExpensePerOperation exp = new ExpensePerOperation(samplingGuid);
            bool   success          = false;
            string sql = $"Select * from tblFishingExpense where SamplingGuid ={{{samplingGuid}}}";

            using (var con = new OleDbConnection(global.ConnectionString))
            {
                using (var dt = new DataTable())
                {
                    con.Open();
                    var adapter = new OleDbDataAdapter(sql, con);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        DataRow dr = dt.Rows[0];
                        if (double.TryParse(dr["CostOfFishing"].ToString(), out double costOfFishing))
                        {
                            SamplingExpenses  = $"Cost of fishing: {costOfFishing.ToString()}\r\n";
                            exp.CostOfFishing = costOfFishing;
                        }
                        else
                        {
                            SamplingExpenses = $"Cost of fishing: -\r\n";
                        }
                        if (double.TryParse(dr["ReturnOfInvestment"].ToString(), out double roi))
                        {
                            exp.ReturnOfInvestment = roi;
                            SamplingExpenses      += $"Return of investment: {roi.ToString()}\r\n";
                        }
                        else
                        {
                            SamplingExpenses += $"Return of investment: -\r\n";
                        }
                        if (double.TryParse(dr["IncomeFromFishSold"].ToString(), out double income))
                        {
                            exp.IncomeFromFishSale = income;
                            SamplingExpenses      += $"Income from fish sales: {income.ToString()}\r\n";
                        }
                        else
                        {
                            SamplingExpenses += $"Income from fish sales: -\r\n";
                        }
                        if (double.TryParse(dr["FishWeightForConsumption"].ToString(), out double weightFishConsumed))
                        {
                            exp.WeightFishConsumed = weightFishConsumed;
                            SamplingExpenses      += $"Weight of fish consumed: {weightFishConsumed.ToString()}";
                        }
                        else
                        {
                            SamplingExpenses += $"Weight of fish consumed: -";
                        }
                        success = true;
                    }
                    else
                    {
                        SamplingExpenses = "Cost of fishing: -\r\nReturn of investment: -\r\nIncome from fish sales: -\r\nWeight of fish consumed: -";
                    }
                }
                if (success)
                {
                    Dictionary <string, FishingExpenseItemsPerOperation> expenseItemsList = new Dictionary <string, FishingExpenseItemsPerOperation>();
                    sql = $"Select * from tblFishingExpenseItems where SamplingGuid={{{samplingGuid}}}";
                    //using (var con1 = new OleDbConnection(global.ConnectionString))
                    //{
                    using (var dt = new DataTable())
                    {
                        //con1.Open();
                        //var adapter = new OleDbDataAdapter(sql, con1);
                        var adapter = new OleDbDataAdapter(sql, con);
                        adapter.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            SamplingExpenses += "\r\n\r\nCost items:\r\n";
                            foreach (DataRow dr in dt.Rows)
                            {
                                string key          = dr["ExpenseRow"].ToString();
                                string item         = dr["ExpenseItem"].ToString();
                                double cost         = (double)dr["Cost"];
                                string unit         = dr["Unit"].ToString();
                                double?unitQuantity = null;
                                if (double.TryParse(dr["UnitQuantity"].ToString(), out double v))
                                {
                                    unitQuantity = v;
                                }
                                FishingExpenseItemsPerOperation expenseItem = new FishingExpenseItemsPerOperation(key, item, cost, unit, unitQuantity, fad3DataStatus.statusFromDB);
                                SamplingExpenses += $"{item}: {cost.ToString()}\r\n";
                                exp.AddExpenseItem(key, expenseItem);
                            }
                        }
                    }
                    //}
                }
                return(exp, success);
            }
        }
Exemple #3
0
 public void AddExpenseItem(string key, FishingExpenseItemsPerOperation item)
 {
     _expenseItemsList.Add(key, item);
 }