初めてのプログラミングに取り組んでおり、少しずつ仕様が実装できることがとても楽しい状況にいます。
保管費用の計算の自動化を目標にしています。
保管費用は期毎に加算され、期は1日-10日,11日-20日,21日-月末日の月に3期。
例えば、7月9日に入庫し7月12日出庫した場合だと9-10,11-12の二期となり、期毎の費用×2となります。
思いつけた方法で取り組んでみましたが正しい結果を得れているのかわかりません。
得れていても沢山のミスや無駄を含んでいるような気がしてなりません。
良い方法をご教受ください。
int KeepDay = 0;
string dum1 = DateTime.Today.ToString();
string today = dum1; //本日の日付
DateTime dt_today = DateTime.Parse(today);
string inDay = _Log_day_y + "/" + _Log_day_m + "/" + _Log_day_d ; //入庫日
DateTime dt_inday = DateTime.Parse(inDay);
TimeSpan ts0 = dt_today - dt_inday;
KeepDay = ts0.Days;
string Log_keepDay = "保管日数:" + KeepDay + "日";
int Keep_y = dt_today.Year - dt_inday.Year;
int Keep_m = dt_today.Month - dt_inday.Month;
Keep_m = Keep_y * 12 + Keep_m;
int Keep_tod = dt_today.Day;
int Keep_ind = dt_inday.Day;
int tod_count = 0;
int ind_count = 0;
if (Keep_tod - 10 <= 0)
{
tod_count = 2;
}
else
{
if (Keep_tod - 20 <= 0)
{
tod_count = 3;
}
else
{
tod_count = 4;
}
}
if (Keep_ind - 10 <= 0)
{
ind_count = 2;
}
else
{
if (Keep_ind - 20 <= 0)
{
ind_count = 3;
}
else
{
ind_count = 4;
}
}
int Keep_d = 0;
if (tod_count >= ind_count)
{
Keep_d = tod_count - ind_count + 1;
}
else
{
Keep_d = ind_count - tod_count;
}
Keep_d = Keep_m * 3 + Keep_d;
//int InExp = 28; //入庫費用
//int OutExp = 28; //出庫費用
int KeepExp = 11; //保管費用
KeepExp = Keep_d * KeepExp;
var Log_keepExp = "保管経費:" + KeepExp + "円";
上記コードで試行した場合
1:入庫→2014/06/11 出庫→2014/07/11 結果→44円(4期)
2:入庫→2012/07/11 出庫→2014/07/11 結果→803円(73期)
3:入庫→2010/07/11 出庫→2014/07/11 結果→1595円(145期)
[2] 環境
[2.1] OS : Windows7
[2.2] コンパイラ名 : Visual Studio Express 2013
[3] その他
・どの程度C言語を理解しているか
全くできていません。
・ライブラリを使っている場合は何を使っているか
使用していません。
以上
宜しくお願いいたします。