using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using util = FCOMMON.Util;
namespace FPJ0000
{
    public partial class fProjectSchedule : FCOMMON.fBase
    {
        string fn_fpcolsize = "";
        int projectindex = 0;
        public fProjectSchedule(int project_)
        {
            InitializeComponent();
            projectindex = project_;
            this.dsPRJ.ProjectsSchedule.TableNewRow += ProjectsSchedule_TableNewRow;
            fn_fpcolsize = util.MakeFilePath(util.CurrentPath, "formSetting", "fp_" + this.Name + ".ini");
        }

        void ProjectsSchedule_TableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            e.Row["wuid"] = FCOMMON.info.Login.no;
            e.Row["wdate"] = DateTime.Now;
            e.Row["project"] = this.projectindex;
        }

        private void fProjectSchedule_Load(object sender, EventArgs e)
        {
            RefreshData();
          
        }
        void RefreshData()
        {
            try
            {
                this.ta.Fill(this.dsPRJ.ProjectsSchedule, this.projectindex);
                FPUtil.ColSizeLoad(ref this.fpSpread1, fn_fpcolsize);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
        private void projectsScheduleBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.bs.EndEdit();
            this.tam.UpdateAll(this.dsPRJ);

        }

        private void fillToolStripButton_Click(object sender, EventArgs e)
        {
           

        }

        private void autoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.fpSpread1.ActiveSheet.DataAutoSizeColumns = true;

            for (int i = 0; i < this.fpSpread1.ActiveSheet.Rows.Count; i++)
                this.fpSpread1.ActiveSheet.SetRowHeight(i, 25);
            //dv1.AutoResizeColumns();
        }

        private void resetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (FarPoint.Win.Spread.Column col in this.fpSpread1.ActiveSheet.Columns)
            {
                col.Width = 100;
            }
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FPUtil.ColsizeSave(this.fpSpread1, fn_fpcolsize);
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FPUtil.ColSizeLoad(ref this.fpSpread1, fn_fpcolsize);
        }

        private void exportListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fpSpread1.SaveExcel("schedule.xls",
                    FarPoint.Excel.ExcelSaveFlags.SaveAsViewed
                    | FarPoint.Excel.ExcelSaveFlags.SaveAsFiltered
                    | FarPoint.Excel.ExcelSaveFlags.NoFormulas
                    | FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders);
        }
    }
}
