protected void bt_Submit_Click(object sender, EventArgs e)
    {
        Save();

        if ((int)ViewState["InventoryID"] > 0)
        {
            SVM_InventoryDifferencesBLL bll = new SVM_InventoryDifferencesBLL((int)ViewState["InventoryID"]);
            if (bll.Model["TaskID"] != "" && bll.Model["SubmitFlag"] == "1")
            {
                return;
            }
            CM_Client client = new CM_ClientBLL(bll.Model.Client).Model;

            NameValueCollection dataobjects = new NameValueCollection();
            dataobjects.Add("ID", bll.Model.ID.ToString());
            dataobjects.Add("AccountMonth", bll.Model.AccountMonth.ToString());
            dataobjects.Add("OrganizeCity", bll.Model.OrganizeCity.ToString());

            dataobjects.Add("ClientID", bll.Model.Client.ToString());
            dataobjects.Add("ClientFullName", client.FullName);
            dataobjects.Add("ClientType", client.ClientType.ToString());
            dataobjects.Add("DIClassify", client["DIClassify"]);
            dataobjects.Add("RTClassify", client["RTClassify"]);
            dataobjects.Add("RTChannel", client["RTChannel"]);

            dataobjects.Add("ComputeInventory", ((decimal)ViewState["ComputeInventory"]).ToString("0.0"));
            dataobjects.Add("TotalDiffValue", ((decimal)ViewState["TotalDiffValue"]).ToString("0.0"));
            dataobjects.Add("TotalAbsDiffValue", ((decimal)ViewState["TotalAbsDiffValue"]).ToString("0.0"));
            dataobjects.Add("AbsDiffRate", ((decimal)ViewState["AbsDiffRate"]).ToString("0.00") + "%");
            dataobjects.Add("ISCXP", bll.Model["IsCXP"]);

            int TaskID = EWF_TaskBLL.NewTask("SVM_InventoryDifferences_Flow", (int)Session["UserID"], "客户名称:" + client.FullName, "~/SubModule/SVM/InventoryDifferenceInput.aspx?InventoryID=" + ViewState["InventoryID"].ToString(), dataobjects);
            if (TaskID > 0)
            {
                bt_Submit.Visible       = false;
                bll.Model["TaskID"]     = TaskID.ToString();
                bll.Model["SubmitFlag"] = "1";
                bll.Update();
                new EWF_TaskBLL(TaskID).Start();        //直接启动流程
            }

            Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + TaskID.ToString());
        }
    }
    protected void Save()
    {
        SVM_InventoryDifferencesBLL bll = new SVM_InventoryDifferencesBLL((int)ViewState["InventoryID"]);
        DropDownList ddl_Month          = (DropDownList)UC_DetailView1.FindControl("SVM_InventoryDifferences_AccountMonth");

        bll.Model.InventoryDate = DateTime.Now.Date;
        bll.Model.AccountMonth  = int.Parse(ddl_Month.SelectedValue);
        bll.Model["SubmitFlag"] = bll.Model["SubmitFlag"] == "" ? "2" : bll.Model["SubmitFlag"];
        bll.Update();
        foreach (GridViewRow gr in gv_List.Rows)
        {
            int id = (int)gv_List.DataKeys[gr.RowIndex][0];
            SVM_InventoryDifferences_Detail item = bll.GetDetailModel(id);

            item.Quantity = int.Parse(((TextBox)gr.FindControl("tbx_Quantity1")).Text) * new PDT_ProductBLL(item.Product).Model.ConvertFactor +
                            int.Parse(((TextBox)gr.FindControl("tbx_Quantity2")).Text);
            item.Remark    = ((TextBox)gr.FindControl("tbx_Remark")).Text;
            item.LotNumber = ((DropDownList)gr.FindControl("ddl_DifferencesReason")).SelectedValue;
            bll.UpdateDetail(item);
        }
    }
    protected void Save()
    {
        SVM_InventoryDifferencesBLL bll = new SVM_InventoryDifferencesBLL((int)ViewState["InventoryID"]);
        DropDownList ddl_Month = (DropDownList)UC_DetailView1.FindControl("SVM_InventoryDifferences_AccountMonth");
        bll.Model.InventoryDate = DateTime.Now.Date;
        bll.Model.AccountMonth = int.Parse(ddl_Month.SelectedValue);
        bll.Model["SubmitFlag"] = bll.Model["SubmitFlag"] == "" ? "2" : bll.Model["SubmitFlag"];
        bll.Update();
        foreach (GridViewRow gr in gv_List.Rows)
        {
            int id = (int)gv_List.DataKeys[gr.RowIndex][0];
            SVM_InventoryDifferences_Detail item = bll.GetDetailModel(id);

            item.Quantity = int.Parse(((TextBox)gr.FindControl("tbx_Quantity1")).Text) * new PDT_ProductBLL(item.Product).Model.ConvertFactor +
                int.Parse(((TextBox)gr.FindControl("tbx_Quantity2")).Text);
            item.Remark = ((TextBox)gr.FindControl("tbx_Remark")).Text;
            item.LotNumber = ((DropDownList)gr.FindControl("ddl_DifferencesReason")).SelectedValue;
            bll.UpdateDetail(item);
        }
    }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        Save();

        if ((int)ViewState["InventoryID"] > 0)
        {
            SVM_InventoryDifferencesBLL bll = new SVM_InventoryDifferencesBLL((int)ViewState["InventoryID"]);
            if (bll.Model["TaskID"] != "" && bll.Model["SubmitFlag"] == "1") return;
            CM_Client client = new CM_ClientBLL(bll.Model.Client).Model;

            NameValueCollection dataobjects = new NameValueCollection();
            dataobjects.Add("ID", bll.Model.ID.ToString());
            dataobjects.Add("AccountMonth", bll.Model.AccountMonth.ToString());
            dataobjects.Add("OrganizeCity", bll.Model.OrganizeCity.ToString());

            dataobjects.Add("ClientID", bll.Model.Client.ToString());
            dataobjects.Add("ClientFullName", client.FullName);
            dataobjects.Add("ClientType", client.ClientType.ToString());
            dataobjects.Add("DIClassify", client["DIClassify"]);
            dataobjects.Add("RTClassify", client["RTClassify"]);
            dataobjects.Add("RTChannel", client["RTChannel"]);

            dataobjects.Add("ComputeInventory", ((decimal)ViewState["ComputeInventory"]).ToString("0.0"));
            dataobjects.Add("TotalDiffValue", ((decimal)ViewState["TotalDiffValue"]).ToString("0.0"));
            dataobjects.Add("TotalAbsDiffValue", ((decimal)ViewState["TotalAbsDiffValue"]).ToString("0.0"));
            dataobjects.Add("AbsDiffRate", ((decimal)ViewState["AbsDiffRate"]).ToString("0.00")+"%");
            dataobjects.Add("ISCXP", bll.Model["IsCXP"]);

            int TaskID = EWF_TaskBLL.NewTask("SVM_InventoryDifferences_Flow", (int)Session["UserID"], "客户名称:" + client.FullName, "~/SubModule/SVM/InventoryDifferenceInput.aspx?InventoryID=" + ViewState["InventoryID"].ToString(), dataobjects);
            if (TaskID > 0)
            {
                bt_Submit.Visible = false;
                bll.Model["TaskID"] = TaskID.ToString();
                bll.Model["SubmitFlag"] = "1";
                bll.Update();
                new EWF_TaskBLL(TaskID).Start();        //直接启动流程
            }

            Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + TaskID.ToString());
        }
    }