protected void bt_Delete_Click(object sender, EventArgs e)
 {
     if ((int)ViewState["ID"] != 0)
     {
         FNA_EvectionRouteBLL bll = new FNA_EvectionRouteBLL((int)ViewState["ID"]);
         bll.Delete();
         MessageBox.ShowAndClose(this, "删除成功!");
     }
 }
 protected void bt_Delete_Click(object sender, EventArgs e)
 {
     if ((int)ViewState["ID"] != 0)
     {
         FNA_EvectionRouteBLL bll = new FNA_EvectionRouteBLL((int)ViewState["ID"]);
         bll.Delete();
         MessageBox.ShowAndClose(this, "删除成功!");
     }
 }
    private void BindData()
    {
        int id = (int)ViewState["ID"];

        FNA_EvectionRoute m = new FNA_EvectionRouteBLL(id).Model;

        if (m != null)
        {
            pn_detail.BindData(m);
            ddl_Transport_SelectedIndexChanged(null, null);

            if (m["RelateJournal"] == "")
            {
                bt_ToJournal.Visible = false;
            }
            else
            {
                ViewState["RelateJournal"] = m["RelateJournal"];
            }

            if (m.Transport == "4" && m["RelateCarDispatch"] != "")
            {
                int dispatch = 0;
                if (int.TryParse(m["RelateCarDispatch"], out dispatch) && dispatch > 0)
                {
                    Car_DispatchRide d = new Car_DispatchRideBLL(dispatch).Model;
                    if (d != null)
                    {
                        pn_detail.BindData(d);
                        ddl_CarID_SelectedIndexChanged(null, null);
                    }
                }
            }

            if (m.WriteOffID > 0 || m.InsertStaff != (int)Session["UserID"] || m.ApproveFlag == 1)
            {
                pn_detail.Enabled = false;
                bt_Delete.Visible = false;
                bt_Save.Visible   = false;
            }
        }
    }
Ejemplo n.º 4
0
    protected void bt_ToEvectionRoute_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            JN_Journal j = new JN_JournalBLL((int)ViewState["ID"]).Model;

            IList <FNA_EvectionRoute> evections = FNA_EvectionRouteBLL.GetModelList("RelateStaff=" + j.Staff +
                                                                                    " AND MCS_SYS.dbo.UF_Spilt2('MCS_FNA.dbo.FNA_EvectionRoute',ExtPropertys,'RelateJournal')='"
                                                                                    + j.ID.ToString() + "'");
            if (evections.Count > 0)
            {
                //系统中已有关联于该工作日志的差旅行程
                Response.Redirect("~/SubModule/FNA/FeeWriteOff/Pop_EvectionRouteDetail.aspx?ID=" + evections[0].ID.ToString());
            }
            else
            {
                if (j.InsertStaff == (int)Session["UserID"])
                {
                    FNA_EvectionRouteBLL evectionbll = new FNA_EvectionRouteBLL();
                    evectionbll.Model.RelateStaff      = j.Staff;
                    evectionbll.Model.BeginDate        = j.BeginTime;
                    evectionbll.Model.EndDate          = j.EndTime;
                    evectionbll.Model.EvectionLine     = j["StartPoint"] + "-" + j["EndPoint"];
                    evectionbll.Model["HotelName"]     = j["HotelName"];
                    evectionbll.Model["HotelTele"]     = j["HotelPhone"];
                    evectionbll.Model["RelateJournal"] = j.ID.ToString();

                    evectionbll.Model.InsertStaff = j.InsertStaff;
                    evectionbll.Model.ApproveFlag = 2;
                    int id = evectionbll.Add();

                    Response.Redirect("~/SubModule/FNA/FeeWriteOff/Pop_EvectionRouteDetail.aspx?ID=" + id.ToString());
                }
                else
                {
                    MessageBox.Show(this, "对不起,只有日志填报人才可填报该日志的差旅行程信息!");
                    return;
                }
            }
        }
    }
    private void ReComputeCost(int flag)
    {
        decimal  Cost1 = 0, Cost2 = 0, Cost3 = 0, Cost4 = 0, Cost5 = 0;
        decimal  Cost11 = 0, Cost12 = 0, Cost13 = 0;    //车辆费用
        decimal  Cost21 = 0, Cost22 = 0;                //培训差旅费
        DateTime minbegindate = DateTime.Parse("2999-1-1"), maxenddate = DateTime.Parse("1900-1-1");

        #region 求选中行的差旅费、住宿费、补贴合计
        List <int> selectedevectionids = new List <int>();

        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx = (CheckBox)row.FindControl("cbx");
            if (cbx != null && cbx.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex][0];
                FNA_EvectionRoute evection = new FNA_EvectionRouteBLL(id).Model;

                #region 根据关联的工作日志的类型,判断是否培训费
                //获取关联的日志类型
                int journalid = 0, workingclassify = 0;
                if (int.TryParse(evection["RelateJournal"], out journalid) && journalid > 0)
                {
                    JN_Journal Joural = new JN_JournalBLL(journalid).Model;
                    if (Joural != null)
                    {
                        workingclassify = Joural.WorkingClassify;
                    }
                }

                switch (workingclassify)
                {
                case 4:         //总部组织的培训,计入总部培训-差旅费
                    Cost21 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                    break;

                case 5:         //省区组织的培训,计入营业部培训-差旅费
                    Cost22 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                    break;

                default:
                    Cost1 += evection.Cost1;          //交通费
                    Cost2 += evection.Cost2;          //住宿费
                    Cost3 += evection.Cost3;          //补贴
                    Cost4 += evection.Cost4;          //市内交通费
                    Cost5 += evection.Cost5;          //的士费
                    break;
                }
                #endregion

                if (minbegindate > evection.BeginDate)
                {
                    minbegindate = evection.BeginDate;
                }
                if (maxenddate < evection.EndDate)
                {
                    maxenddate = evection.EndDate;
                }

                int cardispatchid = 0;
                if (int.TryParse(gv_List.DataKeys[row.RowIndex]["Car_DispatchRide_ID"].ToString(), out cardispatchid) &&
                    cardispatchid > 0)
                {
                    Car_DispatchRide dispatch = new Car_DispatchRideBLL(cardispatchid).Model;
                    if (dispatch != null)
                    {
                        Cost11 += dispatch.RoadToll;    //过路过桥费
                        Cost12 += dispatch.FuelFee;     //油费
                        Cost13 += dispatch.ParkingFee;  //停车费
                        Cost13 += dispatch.OtherFee;    //其他费
                    }
                }
                selectedevectionids.Add(id);
            }
        }
        if (Cost1 + Cost2 + Cost3 + Cost4 + Cost5 + Cost11 + Cost12 + Cost13 + Cost21 + Cost22 == 0)
        {
            MessageBox.Show(this, "对不起,请勾选要报销的差旅行程记录!");
            return;
        }
        #endregion

        #region 重设科目金额
        FNA_FeeWriteOffBLL bll = new FNA_FeeWriteOffBLL((int)ViewState["WriteOffID"]);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost1ACTitle"), Cost1, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost2ACTitle"), Cost2, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost3ACTitle"), Cost3, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost4ACTitle"), Cost4, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost5ACTitle"), Cost5, flag, minbegindate, maxenddate);

        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost11ACTitle"), Cost11, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost12ACTitle"), Cost12, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost13ACTitle"), Cost13, flag, minbegindate, maxenddate);

        UpdateDetail(bll, ConfigHelper.GetConfigInt("TrainingCost1ACTitle"), Cost21, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("TrainingCost2ACTitle"), Cost22, flag, minbegindate, maxenddate);
        #endregion

        #region 置差旅行程的关联报销单ID
        foreach (int evectionid in selectedevectionids)
        {
            FNA_EvectionRouteBLL evectionbll = new FNA_EvectionRouteBLL(evectionid);
            if (flag == 1)
            {
                evectionbll.Model.WriteOffID = (int)ViewState["WriteOffID"];
            }
            else
            {
                evectionbll.Model.WriteOffID = 0;
            }
            evectionbll.Update();
        }
        #endregion
    }
    private void ReComputeCost(int flag)
    {
        decimal Cost1 = 0, Cost2 = 0, Cost3 = 0, Cost4 = 0, Cost5 = 0;
        decimal Cost11 = 0, Cost12 = 0, Cost13 = 0;     //车辆费用
        decimal Cost21 = 0, Cost22 = 0;                 //培训差旅费
        DateTime minbegindate = DateTime.Parse("2999-1-1"), maxenddate = DateTime.Parse("1900-1-1");

        #region 求选中行的差旅费、住宿费、补贴合计
        List<int> selectedevectionids = new List<int>();

        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx = (CheckBox)row.FindControl("cbx");
            if (cbx != null && cbx.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex][0];
                FNA_EvectionRoute evection = new FNA_EvectionRouteBLL(id).Model;

                #region 根据关联的工作日志的类型,判断是否培训费
                //获取关联的日志类型
                int journalid = 0, workingclassify = 0;
                if (int.TryParse(evection["RelateJournal"], out journalid) && journalid > 0)
                {
                    JN_Journal Joural = new JN_JournalBLL(journalid).Model;
                    if (Joural != null) workingclassify = Joural.WorkingClassify;
                }

                switch (workingclassify)
                {
                    case 4:     //总部组织的培训,计入总部培训-差旅费
                        Cost21 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                        break;
                    case 5:     //省区组织的培训,计入营业部培训-差旅费
                        Cost22 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                        break;
                    default:
                        Cost1 += evection.Cost1;      //交通费
                        Cost2 += evection.Cost2;      //住宿费
                        Cost3 += evection.Cost3;      //补贴
                        Cost4 += evection.Cost4;      //市内交通费
                        Cost5 += evection.Cost5;      //的士费
                        break;
                }
                #endregion

                if (minbegindate > evection.BeginDate) minbegindate = evection.BeginDate;
                if (maxenddate < evection.EndDate) maxenddate = evection.EndDate;

                int cardispatchid = 0;
                if (int.TryParse(gv_List.DataKeys[row.RowIndex]["Car_DispatchRide_ID"].ToString(), out cardispatchid)
                    && cardispatchid > 0)
                {
                    Car_DispatchRide dispatch = new Car_DispatchRideBLL(cardispatchid).Model;
                    if (dispatch != null)
                    {
                        Cost11 += dispatch.RoadToll;    //过路过桥费
                        Cost12 += dispatch.FuelFee;     //油费
                        Cost13 += dispatch.ParkingFee;  //停车费
                        Cost13 += dispatch.OtherFee;    //其他费
                    }
                }
                selectedevectionids.Add(id);
            }
        }
        if (Cost1 + Cost2 + Cost3 + Cost4 + Cost5 + Cost11 + Cost12 + Cost13 + Cost21 + Cost22 == 0)
        {
            MessageBox.Show(this, "对不起,请勾选要报销的差旅行程记录!");
            return;
        }
        #endregion

        #region 重设科目金额
        FNA_FeeWriteOffBLL bll = new FNA_FeeWriteOffBLL((int)ViewState["WriteOffID"]);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost1ACTitle"), Cost1, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost2ACTitle"), Cost2, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost3ACTitle"), Cost3, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost4ACTitle"), Cost4, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost5ACTitle"), Cost5, flag, minbegindate, maxenddate);

        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost11ACTitle"), Cost11, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost12ACTitle"), Cost12, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("EvectionCost13ACTitle"), Cost13, flag, minbegindate, maxenddate);

        UpdateDetail(bll, ConfigHelper.GetConfigInt("TrainingCost1ACTitle"), Cost21, flag, minbegindate, maxenddate);
        UpdateDetail(bll, ConfigHelper.GetConfigInt("TrainingCost2ACTitle"), Cost22, flag, minbegindate, maxenddate);
        #endregion

        #region 置差旅行程的关联报销单ID
        foreach (int evectionid in selectedevectionids)
        {
            FNA_EvectionRouteBLL evectionbll = new FNA_EvectionRouteBLL(evectionid);
            if (flag == 1)
                evectionbll.Model.WriteOffID = (int)ViewState["WriteOffID"];
            else
                evectionbll.Model.WriteOffID = 0;
            evectionbll.Update();
        }
        #endregion
    }
    protected void bt_WriteOff_Click(object sender, EventArgs e)
    {
        #region 求选中行的差旅费、住宿费、补贴合计
        decimal Cost1 = 0, Cost2 = 0, Cost3 = 0, Cost4 = 0, Cost5 = 0;
        decimal Cost11 = 0, Cost12 = 0, Cost13 = 0;     //车辆费用
        decimal Cost21 = 0, Cost22 = 0;

        DateTime   minbegindate = DateTime.Parse("2999-1-1"), maxenddate = DateTime.Parse("1900-1-1");
        List <int> selectedevectionids = new List <int>();

        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx = (CheckBox)row.FindControl("cbx");
            if (cbx != null && cbx.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex][0];
                FNA_EvectionRoute evection = new FNA_EvectionRouteBLL(id).Model;

                #region 根据关联的工作日志的类型,判断是否培训费
                //获取关联的日志类型
                int journalid = 0, workingclassify = 0;
                if (int.TryParse(evection["RelateJournal"], out journalid) && journalid > 0)
                {
                    JN_Journal Joural = new JN_JournalBLL(journalid).Model;
                    if (Joural != null)
                    {
                        workingclassify = Joural.WorkingClassify;
                    }
                }

                switch (workingclassify)
                {
                case 4:         //总部组织的培训,计入总部培训-差旅费
                    Cost21 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                    break;

                case 5:         //省区组织的培训,计入营业部培训-差旅费
                    Cost22 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                    break;

                default:
                    Cost1 += evection.Cost1;          //交通费
                    Cost2 += evection.Cost2;          //住宿费
                    Cost3 += evection.Cost3;          //补贴
                    Cost4 += evection.Cost4;          //市内交通费
                    Cost5 += evection.Cost5;          //的士费
                    break;
                }
                #endregion

                if (minbegindate > evection.BeginDate)
                {
                    minbegindate = evection.BeginDate;
                }
                if (maxenddate < evection.EndDate)
                {
                    maxenddate = evection.EndDate;
                }

                int cardispatchid = 0;
                if (int.TryParse(gv_List.DataKeys[row.RowIndex]["Car_DispatchRide_ID"].ToString(), out cardispatchid) &&
                    cardispatchid > 0)
                {
                    Car_DispatchRide dispatch = new Car_DispatchRideBLL(cardispatchid).Model;
                    if (dispatch != null)
                    {
                        Cost11 += dispatch.RoadToll;    //过路过桥费
                        Cost12 += dispatch.FuelFee;     //油费
                        Cost13 += dispatch.ParkingFee;  //停车费
                        Cost13 += dispatch.OtherFee;    //其他费
                    }
                }
                selectedevectionids.Add(id);
            }
        }
        if (Cost1 + Cost2 + Cost3 + Cost4 + Cost5 + Cost11 + Cost12 + Cost13 + Cost21 + Cost22 == 0)
        {
            MessageBox.Show(this, "对不起,请勾选要报销的差旅行程记录!");
            return;
        }
        #endregion

        #region 新增费用核销单头
        Org_Staff staff = new Org_StaffBLL((int)Session["UserID"]).Model;

        FNA_FeeWriteOffBLL bll = new FNA_FeeWriteOffBLL();
        bll.Model.SheetCode             = FNA_FeeWriteOffBLL.GenerateSheetCode(staff.OrganizeCity); //自动产生报销单号
        bll.Model.AccountMonth          = AC_AccountMonthBLL.GetCurrentMonth();
        bll.Model.FeeType               = ConfigHelper.GetConfigInt("EvectionFeeType");             //差旅费对应的费用类型
        bll.Model.OrganizeCity          = staff.OrganizeCity;
        bll.Model.ApproveFlag           = 1;
        bll.Model.State                 = 1;
        bll.Model.InsertStaff           = (int)Session["UserID"];
        bll.Model["HasFeeApply"]        = "N";        //无申请单
        bll.Model["IsEvectionWriteOff"] = "Y";        //是差旅报销
        #endregion

        #region 新增费用核销单明细
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost1ACTitle"), Cost1, minbegindate, maxenddate);   //交通费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost2ACTitle"), Cost2, minbegindate, maxenddate);   //住宿费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost3ACTitle"), Cost3, minbegindate, maxenddate);   //补贴
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost4ACTitle"), Cost4, minbegindate, maxenddate);   //市内交通费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost5ACTitle"), Cost5, minbegindate, maxenddate);   //的士费

        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost11ACTitle"), Cost11, minbegindate, maxenddate); //车辆费用-路桥费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost12ACTitle"), Cost12, minbegindate, maxenddate); //车辆费用-油费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost13ACTitle"), Cost13, minbegindate, maxenddate); //车辆费用-其他杂费

        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("TrainingCost1ACTitle"), Cost21, minbegindate, maxenddate);  //总部培训费-差旅费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("TrainingCost2ACTitle"), Cost22, minbegindate, maxenddate);  //营业部培训费-差旅费
        #endregion

        int writeoff = bll.Add();

        #region 置差旅行程的关联报销单ID
        foreach (int evectionid in selectedevectionids)
        {
            FNA_EvectionRouteBLL evectionbll = new FNA_EvectionRouteBLL(evectionid);
            evectionbll.Model.WriteOffID = writeoff;
            evectionbll.Update();
        }
        #endregion

        Response.Redirect("FeeWriteoffDetail.aspx?ID=" + writeoff.ToString());
    }
    protected void bt_WriteOff_Click(object sender, EventArgs e)
    {
        #region 求选中行的差旅费、住宿费、补贴合计
        decimal Cost1 = 0, Cost2 = 0, Cost3 = 0, Cost4 = 0, Cost5 = 0;
        decimal Cost11 = 0, Cost12 = 0, Cost13 = 0;     //车辆费用
        decimal Cost21 = 0, Cost22 = 0;

        DateTime minbegindate = DateTime.Parse("2999-1-1"), maxenddate = DateTime.Parse("1900-1-1");
        List<int> selectedevectionids = new List<int>();

        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx = (CheckBox)row.FindControl("cbx");
            if (cbx != null && cbx.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex][0];
                FNA_EvectionRoute evection = new FNA_EvectionRouteBLL(id).Model;

                #region 根据关联的工作日志的类型,判断是否培训费
                //获取关联的日志类型
                int journalid = 0, workingclassify = 0;
                if (int.TryParse(evection["RelateJournal"], out journalid) && journalid > 0)
                {
                    JN_Journal Joural = new JN_JournalBLL(journalid).Model;
                    if (Joural != null) workingclassify = Joural.WorkingClassify;
                }

                switch (workingclassify)
                {
                    case 4:     //总部组织的培训,计入总部培训-差旅费
                        Cost21 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                        break;
                    case 5:     //省区组织的培训,计入营业部培训-差旅费
                        Cost22 += evection.Cost1 + evection.Cost2 + evection.Cost3 + evection.Cost4 + evection.Cost5;
                        break;
                    default:
                        Cost1 += evection.Cost1;      //交通费
                        Cost2 += evection.Cost2;      //住宿费
                        Cost3 += evection.Cost3;      //补贴
                        Cost4 += evection.Cost4;      //市内交通费
                        Cost5 += evection.Cost5;      //的士费
                        break;
                }
                #endregion

                if (minbegindate > evection.BeginDate) minbegindate = evection.BeginDate;
                if (maxenddate < evection.EndDate) maxenddate = evection.EndDate;

                int cardispatchid = 0;
                if (int.TryParse(gv_List.DataKeys[row.RowIndex]["Car_DispatchRide_ID"].ToString(), out cardispatchid)
                    && cardispatchid > 0)
                {
                    Car_DispatchRide dispatch = new Car_DispatchRideBLL(cardispatchid).Model;
                    if (dispatch != null)
                    {
                        Cost11 += dispatch.RoadToll;    //过路过桥费
                        Cost12 += dispatch.FuelFee;     //油费
                        Cost13 += dispatch.ParkingFee;  //停车费
                        Cost13 += dispatch.OtherFee;    //其他费
                    }
                }
                selectedevectionids.Add(id);
            }
        }
        if (Cost1 + Cost2 + Cost3 + Cost4 + Cost5 + Cost11 + Cost12 + Cost13 + Cost21 + Cost22 == 0)
        {
            MessageBox.Show(this, "对不起,请勾选要报销的差旅行程记录!");
            return;
        }
        #endregion

        #region 新增费用核销单头
        Org_Staff staff = new Org_StaffBLL((int)Session["UserID"]).Model;

        FNA_FeeWriteOffBLL bll = new FNA_FeeWriteOffBLL();
        bll.Model.SheetCode = FNA_FeeWriteOffBLL.GenerateSheetCode(staff.OrganizeCity);   //自动产生报销单号
        bll.Model.AccountMonth = AC_AccountMonthBLL.GetCurrentMonth();
        bll.Model.FeeType = ConfigHelper.GetConfigInt("EvectionFeeType");                             //差旅费对应的费用类型
        bll.Model.OrganizeCity = staff.OrganizeCity;
        bll.Model.ApproveFlag = 1;
        bll.Model.State = 1;
        bll.Model.InsertStaff = (int)Session["UserID"];
        bll.Model["HasFeeApply"] = "N";                //无申请单
        bll.Model["IsEvectionWriteOff"] = "Y";        //是差旅报销
        #endregion

        #region 新增费用核销单明细
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost1ACTitle"), Cost1, minbegindate, maxenddate);//交通费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost2ACTitle"), Cost2, minbegindate, maxenddate);//住宿费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost3ACTitle"), Cost3, minbegindate, maxenddate);//补贴
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost4ACTitle"), Cost4, minbegindate, maxenddate);//市内交通费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost5ACTitle"), Cost5, minbegindate, maxenddate);//的士费

        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost11ACTitle"), Cost11, minbegindate, maxenddate);//车辆费用-路桥费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost12ACTitle"), Cost12, minbegindate, maxenddate);//车辆费用-油费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("EvectionCost13ACTitle"), Cost13, minbegindate, maxenddate);//车辆费用-其他杂费

        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("TrainingCost1ACTitle"), Cost21, minbegindate, maxenddate);//总部培训费-差旅费
        AddWriteOffDetail(bll, ConfigHelper.GetConfigInt("TrainingCost2ACTitle"), Cost22, minbegindate, maxenddate);//营业部培训费-差旅费
        #endregion

        int writeoff = bll.Add();

        #region 置差旅行程的关联报销单ID
        foreach (int evectionid in selectedevectionids)
        {
            FNA_EvectionRouteBLL evectionbll = new FNA_EvectionRouteBLL(evectionid);
            evectionbll.Model.WriteOffID = writeoff;
            evectionbll.Update();
        }
        #endregion

        Response.Redirect("FeeWriteoffDetail.aspx?ID=" + writeoff.ToString());
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        FNA_EvectionRouteBLL bll;
        Car_DispatchRideBLL  car_ridebll = null;

        if ((int)ViewState["ID"] == 0)
        {
            bll = new FNA_EvectionRouteBLL();
        }
        else
        {
            bll = new FNA_EvectionRouteBLL((int)ViewState["ID"]);
        }

        pn_detail.GetData(bll.Model);

        #region 保存车辆使用信息
        if (bll.Model.Transport == "4")
        {
            //自驾车时,关联派车单
            if (string.IsNullOrEmpty(bll.Model["RelateCarDispatch"]))
            {
                car_ridebll = new Car_DispatchRideBLL();
                pn_detail.GetData(car_ridebll.Model);
                if (car_ridebll.Model.KilometresEnd < car_ridebll.Model.KilometresStart)
                {
                    MessageBox.Show(this, "对不起,还车公里数不能小于发车公里数!");
                    return;
                }

                car_ridebll.Model.Destination   = bll.Model.EvectionLine;
                car_ridebll.Model.Matters       = "差旅行程";
                car_ridebll.Model.State         = 3; //已交车
                car_ridebll.Model.OrganizeCity  = new Org_StaffBLL((int)Session["UserID"]).Model.OrganizeCity;
                car_ridebll.Model.ActGoBackTime = DateTime.Now;
                car_ridebll.Model.ApproveFlag   = 2;
                car_ridebll.Model.ApplyStaff    = bll.Model.RelateStaff;
                car_ridebll.Model.InsertStaff   = (int)Session["UserID"];

                bll.Model["RelateCarDispatch"] = car_ridebll.Add().ToString();
            }
            else
            {
                car_ridebll = new Car_DispatchRideBLL(int.Parse(bll.Model["RelateCarDispatch"]));
                pn_detail.GetData(car_ridebll.Model);
                if (car_ridebll.Model.KilometresEnd < car_ridebll.Model.KilometresStart)
                {
                    MessageBox.Show(this, "对不起,还车公里数不能小于发车公里数!");
                    return;
                }

                car_ridebll.Model.Destination = bll.Model.EvectionLine;
                car_ridebll.Model.UpdateStaff = (int)Session["UserID"];
                car_ridebll.Update();
            }

            //更新车辆最后的公里数
            Car_CarListBLL CarBll = new Car_CarListBLL(car_ridebll.Model.CarID);
            if (CarBll.Model != null)
            {
                if (Car_DispatchRideBLL.GetModelList("CarID=" + car_ridebll.Model.CarID.ToString() +
                                                     " AND ID > " + car_ridebll.Model.ID.ToString()).Count == 0)
                {
                    //如果当前用车信息是该车辆最后一次用车记录,则更新车辆最后公里数
                    CarBll.Model.Kilometres = car_ridebll.Model.KilometresEnd;
                    CarBll.Update();
                }
            }
        }
        #endregion

        if ((int)ViewState["ID"] == 0)
        {
            bll.Model.ApproveFlag = 2;
            bll.Model.InsertStaff = (int)Session["UserID"];
            ViewState["ID"]       = bll.Add();
        }
        else
        {
            bll.Model.UpdateStaff = (int)Session["UserID"];
            bll.Update();
        }

        if (car_ridebll != null && car_ridebll.Model["RelateEvectionRoute"] == "")
        {
            car_ridebll.Model["RelateEvectionRoute"] = ViewState["ID"].ToString();
            car_ridebll.Update();
        }

        if (sender != null)
        {
            MessageBox.ShowAndClose(this, "保存成功!");
        }
    }
    protected void bt_ToEvectionRoute_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            JN_Journal j = new JN_JournalBLL((int)ViewState["ID"]).Model;

            IList<FNA_EvectionRoute> evections = FNA_EvectionRouteBLL.GetModelList("RelateStaff=" + j.Staff +
              " AND MCS_SYS.dbo.UF_Spilt2('MCS_FNA.dbo.FNA_EvectionRoute',ExtPropertys,'RelateJournal')='"
              + j.ID.ToString() + "'");
            if (evections.Count > 0)
            {
                //系统中已有关联于该工作日志的差旅行程
                Response.Redirect("~/SubModule/FNA/FeeWriteOff/Pop_EvectionRouteDetail.aspx?ID=" + evections[0].ID.ToString());
            }
            else
            {
                if (j.InsertStaff == (int)Session["UserID"])
                {
                    FNA_EvectionRouteBLL evectionbll = new FNA_EvectionRouteBLL();
                    evectionbll.Model.RelateStaff = j.Staff;
                    evectionbll.Model.BeginDate = j.BeginTime;
                    evectionbll.Model.EndDate = j.EndTime;
                    evectionbll.Model.EvectionLine = j["StartPoint"] + "-" + j["EndPoint"];
                    evectionbll.Model["HotelName"] = j["HotelName"];
                    evectionbll.Model["HotelTele"] = j["HotelPhone"];
                    evectionbll.Model["RelateJournal"] = j.ID.ToString();

                    evectionbll.Model.InsertStaff = j.InsertStaff;
                    evectionbll.Model.ApproveFlag = 2;
                    int id = evectionbll.Add();

                    Response.Redirect("~/SubModule/FNA/FeeWriteOff/Pop_EvectionRouteDetail.aspx?ID=" + id.ToString());
                }
                else
                {
                    MessageBox.Show(this, "对不起,只有日志填报人才可填报该日志的差旅行程信息!");
                    return;
                }
            }
        }
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        FNA_EvectionRouteBLL bll;
        Car_DispatchRideBLL car_ridebll = null;

        if ((int)ViewState["ID"] == 0)
            bll = new FNA_EvectionRouteBLL();
        else
            bll = new FNA_EvectionRouteBLL((int)ViewState["ID"]);

        pn_detail.GetData(bll.Model);

        #region 保存车辆使用信息
        if (bll.Model.Transport == "4")
        {
            //自驾车时,关联派车单
            if (string.IsNullOrEmpty(bll.Model["RelateCarDispatch"]))
            {
                car_ridebll = new Car_DispatchRideBLL();
                pn_detail.GetData(car_ridebll.Model);
                if (car_ridebll.Model.KilometresEnd < car_ridebll.Model.KilometresStart)
                {
                    MessageBox.Show(this, "对不起,还车公里数不能小于发车公里数!");
                    return;
                }

                car_ridebll.Model.Destination = bll.Model.EvectionLine;
                car_ridebll.Model.Matters = "差旅行程";
                car_ridebll.Model.State = 3; //已交车
                car_ridebll.Model.OrganizeCity = new Org_StaffBLL((int)Session["UserID"]).Model.OrganizeCity;
                car_ridebll.Model.ActGoBackTime = DateTime.Now;
                car_ridebll.Model.ApproveFlag = 2;
                car_ridebll.Model.ApplyStaff = bll.Model.RelateStaff;
                car_ridebll.Model.InsertStaff = (int)Session["UserID"];

                bll.Model["RelateCarDispatch"] = car_ridebll.Add().ToString();
            }
            else
            {
                car_ridebll = new Car_DispatchRideBLL(int.Parse(bll.Model["RelateCarDispatch"]));
                pn_detail.GetData(car_ridebll.Model);
                if (car_ridebll.Model.KilometresEnd < car_ridebll.Model.KilometresStart)
                {
                    MessageBox.Show(this, "对不起,还车公里数不能小于发车公里数!");
                    return;
                }

                car_ridebll.Model.Destination = bll.Model.EvectionLine;
                car_ridebll.Model.UpdateStaff = (int)Session["UserID"];
                car_ridebll.Update();
            }

            //更新车辆最后的公里数
            Car_CarListBLL CarBll = new Car_CarListBLL(car_ridebll.Model.CarID);
            if (CarBll.Model != null)
            {
                if (Car_DispatchRideBLL.GetModelList("CarID=" + car_ridebll.Model.CarID.ToString() +
                    " AND ID > " + car_ridebll.Model.ID.ToString()).Count == 0)
                {
                    //如果当前用车信息是该车辆最后一次用车记录,则更新车辆最后公里数
                    CarBll.Model.Kilometres = car_ridebll.Model.KilometresEnd;
                    CarBll.Update();
                }
            }
        }
        #endregion

        if ((int)ViewState["ID"] == 0)
        {
            bll.Model.ApproveFlag = 2;
            bll.Model.InsertStaff = (int)Session["UserID"];
            ViewState["ID"] = bll.Add();
        }
        else
        {
            bll.Model.UpdateStaff = (int)Session["UserID"];
            bll.Update();
        }

        if (car_ridebll != null && car_ridebll.Model["RelateEvectionRoute"] == "")
        {
            car_ridebll.Model["RelateEvectionRoute"] = ViewState["ID"].ToString();
            car_ridebll.Update();
        }

        if (sender != null)
            MessageBox.ShowAndClose(this, "保存成功!");
    }
    private void BindData()
    {
        int id = (int)ViewState["ID"];

        FNA_EvectionRoute m = new FNA_EvectionRouteBLL(id).Model;
        if (m != null)
        {
            pn_detail.BindData(m);
            ddl_Transport_SelectedIndexChanged(null, null);

            if (m["RelateJournal"] == "")
                bt_ToJournal.Visible = false;
            else
                ViewState["RelateJournal"] = m["RelateJournal"];

            if (m.Transport == "4" && m["RelateCarDispatch"] != "")
            {
                int dispatch = 0;
                if (int.TryParse(m["RelateCarDispatch"], out dispatch) && dispatch > 0)
                {
                    Car_DispatchRide d = new Car_DispatchRideBLL(dispatch).Model;
                    if (d != null)
                    {
                        pn_detail.BindData(d);
                        ddl_CarID_SelectedIndexChanged(null, null);
                    }
                }
            }

            if (m.WriteOffID > 0 || m.InsertStaff != (int)Session["UserID"] || m.ApproveFlag == 1)
            {
                pn_detail.Enabled = false;
                bt_Delete.Visible = false;
                bt_Save.Visible = false;
            }
        }
    }