Ejemplo n.º 1
0
        protected void calculateByDuration()
        {
            DayCompute dayCompute = new DayCompute();

            //設定工期計算方式
            if (radioBtnRestrictSchedule.Checked == true || radioBtnCalenderDay.Checked == true)
            {
                dayCompute.restOnSaturday = false;
                dayCompute.restOnSunday   = false;
                dayCompute.restOnHoliday  = false;
            }
            else
            {
                if (radioBtnNoWeekend.Checked == true)
                {
                    dayCompute.restOnSaturday = false; //表示週六要施工
                    dayCompute.restOnSunday   = false; //表示週日要施工
                }
                else if (radioBtnSun.Checked == true)
                {
                    dayCompute.restOnSaturday = false; //表示週六要施工
                    dayCompute.restOnSunday   = true;  //表示週日不施工
                }
                else if (radioBtnSatSun.Checked == true)
                {
                    dayCompute.restOnSaturday = true; //表示週六不施工
                    dayCompute.restOnSunday   = true; //表示週日不施工
                }

                if (radioBtnHolidayNoWorking.Checked)
                {
                    dayCompute.restOnHoliday = true;//表示國定假日不施工
                }
                else
                {
                    dayCompute.restOnHoliday = false;//表示國定假日依然要施工
                }
            }


            DateTime FinishDate = dayCompute.CountByDuration(dateTimeStart.Value, Convert.ToSingle(numericDuration.Value));

            dateTimeFinish.Value = FinishDate;
            numericDays.Value    = FinishDate.Subtract(dateTimeStart.Value).Days + 1;
        }
        private void LoadDataTable()
        {
            dataTable.Clear();

            ArrayList array = new ArrayList();

            string[] numbers = SQL.Read1DArray_SQL_Data("grantnumber", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' ORDER BY grantdate ASC");

            double totalValue         = Convert.ToDouble(this.numericAmount.Value);
            float  accuextendduration = 0;
            float  totalduration      = Convert.ToSingle(this.numericDuration.Value);

            DataRow dataRow;

            for (int i = 1; i <= numbers.Length; i++)
            {
                dataRow          = dataTable.NewRow();
                dataRow["No"]    = i.ToString();
                dataRow["核准日期"]  = Functions.TransferSQLDateToDateOnly(SQL.Read_SQL_data("grantdate", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'"));
                dataRow["核准文號"]  = SQL.Read_SQL_data("grantnumber", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'");
                dataRow["追加金額"]  = SQL.Read_SQL_data("extendvalue", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'");
                totalValue      += Convert.ToDouble(SQL.Read_SQL_data("extendvalue", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'"));
                dataRow["總金額"]   = totalValue;
                dataRow["追加起算日"] = Functions.TransferSQLDateToDateOnly(SQL.Read_SQL_data("extendstartdate", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'"));
                float extendDuration = Convert.ToSingle(SQL.Read_SQL_data("extendduration", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'"));
                dataRow["追加工期"]     = extendDuration;
                accuextendduration += extendDuration;
                dataRow["累計追加工期"]   = accuextendduration;
                totalduration      += extendDuration;
                dataRow["總工期"]      = totalduration;
                dataRow["契約完工日"]    = Functions.GetDateTimeValueSlash(dateTimeFinish.Value);

                DayCompute dayCompute = new DayCompute();

                SetupDayComputer(dayCompute);
                DateTime FinishDate = dayCompute.CountByDuration(dateTimeStart.Value, totalduration);

                dataRow["變動完工日"] = Functions.GetDateTimeValueSlash(FinishDate);//SQL.Read_SQL_data("modified_finishdate", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'");
                dataRow["填寫日期"]  = Functions.TransferSQLDateToDateOnly(SQL.Read_SQL_data("writedate", "extendduration", "project_no = '" + this.textBoxProjectNo.Text + "' && grantnumber = '" + numbers[i - 1] + "'"));

                dataTable.Rows.Add(dataRow);
            }
        }
        private void SetupDayComputer(DayCompute dayCompute)
        {
            if (radioBtnRestrictSchedule.Checked == true || radioBtnCalenderDay.Checked == true)
            {
                dayCompute.restOnSaturday = false;
                dayCompute.restOnSunday   = false;
                dayCompute.restOnHoliday  = false;
            }
            else
            {
                if (radioBtnNoWeekend.Checked == true)
                {
                    dayCompute.restOnSaturday = false; //表示週六要施工
                    dayCompute.restOnSunday   = false; //表示週日要施工
                }
                else if (radioBtnSun.Checked == true)
                {
                    dayCompute.restOnSaturday = false; //表示週六要施工
                    dayCompute.restOnSunday   = true;  //表示週日不施工
                }
                else if (radioBtnSatSun.Checked == true)
                {
                    dayCompute.restOnSaturday = true; //表示週六不施工
                    dayCompute.restOnSunday   = true; //表示週日不施工
                }

                if (radioBtnHolidayNoWorking.Checked)
                {
                    dayCompute.restOnHoliday = true;//表示國定假日不施工
                }
                else
                {
                    dayCompute.restOnHoliday = false;//表示國定假日依然要施工
                }
            }
        }
        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;
        }
Ejemplo n.º 5
0
        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";
            }
        }