protected void Compute(string projectNo, string computeType, string countHoliday, string startDate) { DayCompute dayCompute = new DayCompute(); comboBoxNoCountByType.Text = "0"; if (computeType == "1")//限期完工 日曆天 { //追加工期後總計天數 this.textBoxTotalDays.Text = this.textBoxTotalDuration.Text; this.label29.Text = "工期計算方式為限期完工"; } else if (computeType == "2") { //追加工期後總計天數 this.textBoxTotalDays.Text = this.textBoxTotalDuration.Text; this.label29.Text = "工期計算方式為日曆天"; } else { if (computeType == "3")//工作天 無休 { dayCompute.restOnSaturday = false; dayCompute.restOnSunday = false; this.label29.Text = "工期計算方式為工作工,無週休二日"; } else if (computeType == "4")//工作天 周休一日 { dayCompute.restOnSaturday = false; dayCompute.restOnSunday = true; this.label29.Text = "工期計算方式為工作工,週休一日"; if (dateToday.Value.DayOfWeek == DayOfWeek.Sunday) { comboBoxNoCountByType.Text = "1"; } } else if (computeType == "5")//工作天 周休二日 { dayCompute.restOnSaturday = true; dayCompute.restOnSunday = true; this.label29.Text = "工期計算方式為工作工,週休二日"; if (dateToday.Value.DayOfWeek == DayOfWeek.Sunday) { comboBoxNoCountByType.Text = "1"; } else if (dateToday.Value.DayOfWeek == DayOfWeek.Saturday) { string extraDay = SQL.Read_SQL_data("working", "holiday", "date = '" + Functions.TransferDateTimeToSQL(dateToday.Value) + "'"); if (extraDay == string.Empty || extraDay == "1") { comboBoxNoCountByType.Text = "1"; } } } if (countHoliday == "1") { dayCompute.restOnHoliday = true; this.label29.Text += ",國定假日不施工"; string holiday = SQL.Read_SQL_data("working", "holiday", "date = '" + Functions.TransferDateTimeToSQL(dateToday.Value) + "'"); if (holiday == "1") { comboBoxNoCountByType.Text = "1"; } } else if (countHoliday == "0") { dayCompute.restOnHoliday = false; this.label29.Text += ",國定假日照常施工"; } DateTime FinishDateAfterExtention = dayCompute.CountByDuration(Functions.TransferSQLDateToDateTime(startDate), Convert.ToSingle(this.textBoxTotalDuration.Text)); //DateTime FinishDateContract = dayCompute.CountByDuration(Functions.TransferSQLDateToDateTime(startDate), Convert.ToSingle(this.textBoxContractDuration.Text)); //追加工期後總計天數 this.textBoxTotalDays.Text = Convert.ToString(FinishDateAfterExtention.Subtract(dateStart.Value).Days + 1); ////契約天數 //this.textBoxContractDays.Text = Convert.ToString(FinishDateContract.Subtract(dateStart.Value).Days + 1); } //開工迄今天數 = 今日日期 - 開工日期 + 1 if (this.dateToday.Value.Date.Subtract(this.dateStart.Value.Date).Days + 1 < 0) { this.dateToday.Value = this.dateStart.Value; } else { this.textBoxDaysStartToCurrent.Text = Convert.ToString(this.dateToday.Value.Date.Subtract(this.dateStart.Value.Date).Days + 1); } //不計工期 string[] reportDates = SQL.Read1DArray_SQL_Data("date", "dailyreport", "project_no = '" + projectNo + "'"); for (int i = 0; i < reportDates.Length; i++) { if (Functions.TransferSQLDateToDateTime(reportDates[i]).CompareTo(dateToday.Value) == -1)//發生早於今日日期 { float nonCountingDays = Convert.ToSingle(SQL.Read_SQL_data("nonecounting", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferSQLDateToDateOnly(reportDates[i]) + "'")); if (nonCountingDays == 0.5) { dayCompute.AddNotWorking(Functions.TransferSQLDateToDateTime(reportDates[i]), 0); } else if (nonCountingDays == 1) { dayCompute.AddNotWorking(Functions.TransferSQLDateToDateTime(reportDates[i]), 0); dayCompute.AddNotWorking(Functions.TransferSQLDateToDateTime(reportDates[i]), 1); } } } if (comboBoxNoCount.Text == "0.5") { dayCompute.AddNotWorking(dateToday.Value, 0); } else if (comboBoxNoCount.Text == "1") { dayCompute.AddNotWorking(dateToday.Value, 0); dayCompute.AddNotWorking(dateToday.Value, 1); } this.textBoxDurationNotCount.Text = Convert.ToString(dayCompute.CountTotalNotWorkingDay(dateStart.Value, dateToday.Value)); //實際工期 = 開工迄今天數 - 不計工期 this.textBoxRealDuration.Text = Convert.ToString(Convert.ToDecimal(this.textBoxDaysStartToCurrent.Text) - Convert.ToDecimal(this.textBoxDurationNotCount.Text)); //剩餘工期 = 工期總計 - 實際工期 this.textBoxRestDuration.Text = Convert.ToString(Convert.ToDecimal(this.textBoxTotalDuration.Text) - Convert.ToDecimal(this.textBoxRealDuration.Text)); //契約完工日 this.dateProjectEnd_Contract.Value = Functions.TransferSQLDateToDateTime(SQL.Read_SQL_data("contract_finishdate", "project_info", "project_no ='" + projectNo + "'")); if (Convert.ToSingle(this.textBoxRestDuration.Text) < 0) { //變動完工日從SQL讀出來 this.dateProjectEnd_Modify.Value = Functions.TransferSQLDateToDateTime(SQL.Read_SQL_data("modified_finishdate", "project_info", "project_no = '" + g_ProjectNumber + "'")); //剩餘天數 = 變動完工日 - 今日日期 this.textBoxRestDays.Text = Convert.ToString(this.dateProjectEnd_Modify.Value.Subtract(dateToday.Value).Days); //逾期天數 this.textBoxOverDays.Text = Convert.ToString(dateToday.Value.Subtract(dateProjectEnd_Modify.Value).Days); } else { //變動完工日 this.dateProjectEnd_Modify.Value = dayCompute.CountByDuration(dateToday.Value.AddDays(1), Convert.ToSingle(this.textBoxRestDuration.Text)); //把變動完工日寫進SQL SQL.Set_SQL_data("modified_finishdate", "project_info", "project_no = '" + g_ProjectNumber + "'", Functions.TransferDateTimeToSQL(this.dateProjectEnd_Modify.Value)); //剩餘天數 = 變動完工日 - 今日日期 this.textBoxRestDays.Text = Convert.ToString(this.dateProjectEnd_Modify.Value.Subtract(dateToday.Value).Days); //逾期天數 this.textBoxOverDays.Text = "0"; } }
public void LoadProjectInfo(string number) { g_ProjectNo = number; dataTableStatistic.Clear(); DayCompute dayCompute = new DayCompute(); string computeType = SQL.Read_SQL_data("computetype", "project_info", "project_no = '" + g_ProjectNo + "'"); string countHoliday = SQL.Read_SQL_data("holiday", "project_info", "project_no = '" + g_ProjectNo + "'"); if (computeType == "1")//限期完工 日曆天 { this.label1.Text = "工期計算方式為限期完工"; } else if (computeType == "2") { this.label1.Text = "工期計算方式為日曆天"; } else if (computeType == "3")//工作天 無休 { dayCompute.restOnSaturday = false; dayCompute.restOnSunday = false; this.label1.Text = "工期計算方式為工作工,無週休二日"; } else if (computeType == "4")//工作天 周休一日 { dayCompute.restOnSaturday = false; dayCompute.restOnSunday = true; this.label1.Text = "工期計算方式為工作工,週休一日"; } else if (computeType == "5")//工作天 周休二日 { dayCompute.restOnSaturday = true; dayCompute.restOnSunday = true; this.label1.Text = "工期計算方式為工作工,週休二日"; } if (countHoliday == "1") { dayCompute.restOnHoliday = true; this.label1.Text += ",國定假日不施工"; } else if (countHoliday == "0") { dayCompute.restOnHoliday = false; this.label1.Text += ",國定假日照常施工"; } string rainyDayCountType = SQL.Read_SQL_data("rainyday", "project_info", "project_no = '" + g_ProjectNo + "'"); if (rainyDayCountType == "1") { this.label3.Text += "需豪雨才不計工期"; } else if (rainyDayCountType == "0") { this.label3.Text += "下雨即不計工期"; } float originalTotalDuration = Convert.ToSingle(SQL.Read_SQL_data("contractduration", "project_info", "project_no = '" + g_ProjectNo + "'")); float originalTotalDays = Convert.ToSingle(SQL.Read_SQL_data("contractdays", "project_info", "project_no = '" + g_ProjectNo + "'")); DateTime originalFinishDate = Functions.TransferSQLDateToDateTime(SQL.Read_SQL_data("contract_finishdate", "project_info", "project_no = '" + g_ProjectNo + "'")); string[] extendDurationStartDates = SQL.Read1DArray_SQL_Data("extendstartdate", "extendduration", "project_no = '" + g_ProjectNo + "'"); float accumulateExtendDurations = 0; string startDate = SQL.Read_SQL_data("startdate", "project_info", "project_no = '" + g_ProjectNo + "'"); DTStartDate = Functions.TransferSQLDateToDateTime(startDate); DataRow dataRow; int i = 0; bool stop = false; while (!stop) { DateTime dateToday = DTStartDate.AddDays(i); dataRow = dataTableStatistic.NewRow(); dataRow["日期"] = dateToday.ToString("yyyy/MM/dd"); dataRow["開工迄今"] = (i + 1).ToString(); dataRow["星期"] = Functions.ComputeDayOfWeek(dateToday); //Image img = Image.FromFile("D:\\12Small.jpg"); //dataRow["農曆"] = imageToByteArray(img); dataRow["節日"] = dayCompute.GetCondition(dateToday); string morningWeather = SQL.Read_SQL_data("morning_weather", "dailyreport", "project_no = '" + g_ProjectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(dateToday) + "'"); dataRow["上午天氣"] = (morningWeather == string.Empty) ? "無資料" : morningWeather; string afternoonWeather = SQL.Read_SQL_data("afternoon_weather", "dailyreport", "project_no = '" + g_ProjectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(dateToday) + "'"); dataRow["下午天氣"] = (afternoonWeather == string.Empty) ? "無資料" : afternoonWeather; string morningCondition = SQL.Read_SQL_data("morning_condition", "dailyreport", "project_no = '" + g_ProjectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(dateToday) + "'"); dataRow["上午人為因素"] = (morningCondition == string.Empty) ? "無資料" : morningCondition; string afternoonCondition = SQL.Read_SQL_data("afternoon_condition", "dailyreport", "project_no = '" + g_ProjectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(dateToday) + "'"); dataRow["下午人為因素"] = (afternoonCondition == string.Empty) ? "無資料" : afternoonCondition; string nonCountingToday = SQL.Read_SQL_data("nonecounting", "dailyreport", "project_no = '" + g_ProjectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(dateToday) + "'"); if (nonCountingToday == "0.5") dayCompute.AddNotWorking(dateToday, 0); else if (nonCountingToday == "1") { dayCompute.AddNotWorking(dateToday, 0); dayCompute.AddNotWorking(dateToday, 1); } dataRow["本日不計工期"] = dayCompute.GetWorkingDayNonCounting(dateToday); float nonCountingTotal = dayCompute.CountTotalNotWorkingDay(DTStartDate, dateToday); dataRow["累計不計工期"] = nonCountingTotal; dataRow["累計工期"] = i + 1 - nonCountingTotal; dataRow["原剩餘工期"] = originalTotalDuration - 1 - i + dayCompute.CountNotWorkingDayWithoutEverydayCondition(DTStartDate, dateToday); dataRow["原剩餘天數"] = originalTotalDays - 1 - i; dataRow["原完工日"] = originalFinishDate.ToString("yyyy/MM/dd"); string extendDuration = SQL.Read_SQL_data("extendduration", "extendduration", "project_no = '" + g_ProjectNo + "' AND extendstartdate = '" + Functions.TransferDateTimeToSQL(dateToday) + "'"); if (extendDuration != string.Empty) { accumulateExtendDurations += Convert.ToSingle(extendDuration); dataRow["追加工期"] = extendDuration; } float modifiedRestDuration = originalTotalDuration - 1 - i + nonCountingTotal + accumulateExtendDurations; dataRow["變動剩餘工期"] = modifiedRestDuration; DateTime modifiedFinishDate = dayCompute.CountByDuration(dateToday.AddDays(1), modifiedRestDuration); dataRow["變動完工日"] = modifiedFinishDate.ToString("yyyy/MM/dd"); if (dateToday.CompareTo(modifiedFinishDate) == 0) stop = true; dataRow["變動剩餘天數"] = modifiedFinishDate.Subtract(dateToday).Days; dataRow["原百分比"] = ""; dataTableStatistic.Rows.Add(dataRow); i++; } //dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Red; }
private void LoadReportInfo(string projectNo, DateTime date) { g_DisableHandler = true; //上午天氣 comboBoxWeatherMorning.Text = SQL.Read_SQL_data("morning_weather", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(date) + "'"); //下午天氣 comboBoxWeatherAfternoon.Text = SQL.Read_SQL_data("afternoon_weather", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(date) + "'"); //干擾因素 textBoxInterference.Text = SQL.Read_SQL_data("interference", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(date) + "'"); //上午條件 comboBoxConditionMorning.Text = SQL.Read_SQL_data("morning_condition", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(date) + "'"); //下午條件 comboBoxConditionMorning.Text = SQL.Read_SQL_data("afternoon_condition", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(date) + "'"); //本日不計 comboBoxNoCount.Text = SQL.Read_SQL_data("nonecounting", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferDateTimeToSQL(date) + "'"); //今日開始追加工期 int accuextendduration = 0; ArrayList extendDate = new ArrayList(); string[] extendDates = SQL.Read1DArray_SQL_Data("extendstartdate", "extendduration", "project_no ='" + projectNo + "'"); this.textBoxExtendToday.Text = "0"; for (int i = 0; i < extendDates.Length; i++) { DateTime extDate = Functions.TransferSQLDateToDateTime(extendDates[i]); if (extDate.Date.CompareTo(dateToday.Value.Date) == 0)//為追加起始日 { this.textBoxExtendToday.Text = SQL.Read_SQL_data("extendduration", "extendduration", "project_no ='" + projectNo + "' AND extendstartdate = '" + Functions.TransferDateTimeToSQL(dateToday.Value) + "'"); } if ((extDate.Date.CompareTo(dateToday.Value.Date) == 0 || extDate.Date.CompareTo(dateToday.Value.Date) == -1) && extDate.Date.CompareTo(Functions.TransferSQLDateToDateTime(g_StartDate)) != -1)//0為追加起始日 -1為開始日比今日日期早 { int extendDuration = Convert.ToInt32(SQL.Read_SQL_data("extendduration", "extendduration", "project_no = '" + projectNo + "' AND extendstartdate = '" + Functions.TransferDateTimeToSQL(extDate) + "'")); accuextendduration += extendDuration; } } //累計追加工期 this.textBoxAccumulateExtend.Text = accuextendduration.ToString(); //工期總計 this.textBoxTotalDuration.Text = Convert.ToString(Convert.ToSingle(SQL.Read_SQL_data("contractduration", "project_info", "project_no ='" + projectNo + "'")) + accuextendduration); //開工迄今天數 = 今日日期 - 開工日期 + 1 if (this.dateToday.Value.Date.Subtract(this.dateStart.Value.Date).Days + 1 < 0) { this.dateToday.Value = this.dateStart.Value; } else { this.textBoxDaysStartToCurrent.Text = Convert.ToString(this.dateToday.Value.Date.Subtract(this.dateStart.Value.Date).Days + 1); } //不計工期 string[] reportDates = SQL.Read1DArray_SQL_Data("date", "dailyreport", "project_no = '" + projectNo + "'"); for (int i = 0; i < reportDates.Length; i++) { if (Functions.TransferSQLDateToDateTime(reportDates[i]).CompareTo(dateToday.Value) == -1)//發生早於今日日期 { float nonCountingDays = Convert.ToSingle(SQL.Read_SQL_data("nonecounting", "dailyreport", "project_no = '" + projectNo + "' AND date = '" + Functions.TransferSQLDateToDateOnly(reportDates[i]) + "'")); if (nonCountingDays == 0.5) { dayCompute.AddNotWorking(Functions.TransferSQLDateToDateTime(reportDates[i]), 0); } else if (nonCountingDays == 1) { dayCompute.AddNotWorking(Functions.TransferSQLDateToDateTime(reportDates[i]), 0); dayCompute.AddNotWorking(Functions.TransferSQLDateToDateTime(reportDates[i]), 1); } } } this.textBoxDurationNotCount.Text = Convert.ToString(dayCompute.CountTotalNotWorkingDay(dateStart.Value, dateToday.Value)); //實際工期 = 開工迄今天數 - 不計工期 this.textBoxRealDuration.Text = Convert.ToString(Convert.ToDecimal(this.textBoxDaysStartToCurrent.Text) - Convert.ToDecimal(this.textBoxDurationNotCount.Text)); //剩餘工期 = 工期總計 - 實際工期 this.textBoxRestDuration.Text = Convert.ToString(Convert.ToDecimal(this.textBoxTotalDuration.Text) - Convert.ToDecimal(this.textBoxRealDuration.Text)); if (Convert.ToSingle(this.textBoxRestDuration.Text) < 0) { //變動完工日從SQL讀出來 this.dateProjectEnd_Modify.Value = Functions.TransferSQLDateToDateTime(SQL.Read_SQL_data("modified_finishdate", "project_info", "project_no = '" + g_ProjectNumber + "'")); //剩餘天數 = 變動完工日 - 今日日期 this.textBoxRestDays.Text = Convert.ToString(this.dateProjectEnd_Modify.Value.Subtract(dateToday.Value).Days); } else { //變動完工日 this.dateProjectEnd_Modify.Value = dayCompute.CountByDuration(dateToday.Value.AddDays(1), Convert.ToSingle(this.textBoxRestDuration.Text)); //把變動完工日寫進SQL SQL.Set_SQL_data("modified_finishdate", "project_info", "project_no = '" + g_ProjectNumber + "'", Functions.TransferDateTimeToSQL(this.dateProjectEnd_Modify.Value)); //剩餘天數 = 變動完工日 - 今日日期 this.textBoxRestDays.Text = Convert.ToString(this.dateProjectEnd_Modify.Value.Subtract(dateToday.Value).Days); } LoadDataTable(projectNo, date); g_DisableHandler = false; }