Пример #1
0
        /// <summary>
        /// 更新到SAP
        /// </summary>
        /// <returns></returns>
        public bool UpdateToSAP()
        {
            StringBuilder sbError = new StringBuilder();
            StringBuilder sbSuccess = new StringBuilder();
            bool isAllSuccess = true;

            DataTable dtResult = new DataTable();
            DataTable dtPars = new DataTable();
            OSPCommon comm = new OSPCommon();

            dtPars = GetUpdatePars();
            dtResult= comm.UpdateOSPPrice(dtPars);
            foreach (DataRow dr in dtResult.Rows)
            {
                string sStyleNO=dr["StyleNO"]==null?string.Empty:dr["StyleNO"].ToString();
                string sStatus=dr["Status"]==null?string.Empty:dr["Status"].ToString();
                if (sStatus == "1")//是更新成功的
                {
                    UpdateItemStaus(sStyleNO, true);
                    sbSuccess.Append(string.Format("Style No. {0} update successed \\n", sStyleNO));
                }
                else//更新失败。
                {
                    string sError = dr["ErrorInfo"] == null ? string.Empty : dr["ErrorInfo"].ToString();
                    sbError.Append(string.Format("Style No. {0} update failed,error info:{1} \\n", sStyleNO, sError));
                    isAllSuccess = false;
                    UpdateItemStaus(sStyleNO,false);
                }
            }
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", string.Format("<script>alert('{0}\\n\\n{1}')</script>", sbError.ToString(), sbSuccess.ToString()));
            return isAllSuccess;
        }
Пример #2
0
        /// <summary>
        /// 绑定Workflow里的Item数据
        /// </summary>
        /// <param name="sWorkflowNO"></param>
        public void BindData(string sWorkflowNO)
        {
            OSPCommon comm = new OSPCommon();
            DataTable dt = new DataTable();
            dt = comm.GetData(sWorkflowNO);

            RepeaterPOData.DataSource = dt;
            RepeaterPOData.DataBind();
            SetSearchText();
        }
Пример #3
0
        /// <summary>
        /// 设置工作流变量
        /// </summary>
        /// <param name="sWorkflowNo"></param>
        /// <param name="isSubmit"></param>
        bool SetWorkflowVariable(string sWorkflowNo,bool isSubmit)
        {
            WorkflowContext context = WorkflowContext.Current;

            OSPCommon comm = new OSPCommon();
            NameCollection manager = OSPCommon.GetTaskUsers("wf_OSP");
            if (null == manager || manager.Count==0)
            {
                DisplayMessage("There are no user in group wf_OSP,\\n please contact IT For further help!");
                return false;
            }
            else
            {
                string sOSPActions = string.Empty;
                bool isAllUpdateToSap = true;//是否已经全部成功更新到SAP
                if (isSubmit)//提交
                {
                    bool isNotNeedApprove = DataEditEdit.IsNotNeedApprove();
                    if (isNotNeedApprove)//不需要工作流审批。
                    {
                        isAllUpdateToSap = DataEditEdit.UpdateToSAP(sWorkflowNo);
                        HiddenFieldIsNotNeedApprove.Value = "1";
                    }
                    else//需要工作流审批。
                    {
                        sOSPActions = OSPCommon.Submit;
                        HiddenFieldIsNotNeedApprove.Value = "0";
                    }
                }
                else//保存
                {
                    sOSPActions = OSPCommon.Save;
                    HiddenFieldIsNotNeedApprove.Value = "0";
                }

                WorkflowDataFields fields = WorkflowContext.Current.DataFields;

                fields["Status"] = CAWorkflowStatus.InProgress;
                fields["Title"] = sWorkflowNo;
                fields["Applicant"] = CurrentEmployee.DisplayName + "(" + CurrentEmployee.UserAccount + ")";
                SPUser ApplicantSPUser = SPContext.Current.Web.EnsureUser(Userinfo1.Applicant.UserAccount);
                fields["ApplicantSPUser"] = ApplicantSPUser;

                context.UpdateWorkflowVariable("OSPActions", sOSPActions);
                context.UpdateWorkflowVariable("EditURL", "/_Layouts/CA/WorkFlows/OSP/EditForm.aspx");
                context.UpdateWorkflowVariable("EditTitle", "Please complete OSP:" + sWorkflowNo);
                context.UpdateWorkflowVariable("ApproveURL", "/_Layouts/CA/WorkFlows/OSP/ApproveForm.aspx");
                context.UpdateWorkflowVariable("ApproveTitle", sWorkflowNo + " needs approve");
                context.UpdateWorkflowVariable("ApproveUser", manager);
                return isAllUpdateToSap;
            }
        }
Пример #4
0
 /// <summary>
 /// 发送邮件
 /// </summary>
 /// <param name="sStatus"></param>
 void SendNoticeMail(string sStatus)
 {
     WorkflowDataFields fields = WorkflowContext.Current.DataFields;
     OSPCommon comm = new OSPCommon();
     try
     {
         comm.SendMail(WorkFlowUtil.GetApplicantAccount(fields["Applicant"].ToString()), sStatus, fields["Title"].ToString(), CurrentEmployee.UserAccount);
     }
     catch (Exception e)
     {
         CommonUtil.logError(e.ToString());
     }
 }
Пример #5
0
        /// <summary>
        /// 绑定Workflow里的Item数据
        /// </summary>
        public void BindData()
        {
            WorkflowDataFields fields = WorkflowContext.Current.DataFields;
            string sWorkflowNO = fields["Title"].ToString();

            OSPCommon comm = new OSPCommon();
            DataTable dt = new DataTable();
            dt = comm.GetData(sWorkflowNO);

            RepeaterPOData.DataSource = dt;
            RepeaterPOData.DataBind();
            LabelCount.Text = dt.Rows.Count.ToString();
        }
Пример #6
0
        /// <summary>
        /// 更新list里该 StyleNO的审批为True,SAP的更新状态。 
        /// </summary>
        /// <param name="sStyleNo"></param>
        /// <param name="isSuccess"></param>
        void UpdateItemStaus(string sStyleNo,bool isSuccess)
        {
            OSPCommon comm = new OSPCommon();

            foreach (RepeaterItem item in RepeaterPOData.Items)
            {
                Label LabelStyleNO = item.FindControl("LabelStyleNO") as Label;
                if (sStyleNo == LabelStyleNO.Text.Trim())
                {
                    HiddenField HiddenFieldID = item.FindControl("HiddenFieldID") as HiddenField;///当前Item的 ID
                    HiddenField HiddenFieldISSuccess = item.FindControl("HiddenFieldISSuccess") as HiddenField;///当前Item的 ID
                    comm.UpdateItemSapStatus(HiddenFieldID.Value, true, isSuccess);///更新list里该 StyleNO的审批为True,SAP的更新状态。
                    HiddenFieldISSuccess.Value = isSuccess?"1":"0";
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 得到更新到 SAP的参数 ,并将审批不通过数据修改到list
        /// </summary>
        /// <returns></returns>
        DataTable GetUpdatePars()
        {
            DataTable dtUpdate = new DataTable();
            dtUpdate.Columns.Add("StyleNO");
            dtUpdate.Columns.Add("NewOSP");
            foreach (RepeaterItem item in RepeaterPOData.Items)
            {
                DropDownList DropDownListApprove = item.FindControl("DropDownListApprove") as DropDownList;
                HiddenField HiddenFieldISSuccess = item.FindControl("HiddenFieldISSuccess") as HiddenField;
                if (HiddenFieldISSuccess.Value == "0")//没有更新成功
                {
                    bool IsApproved = DropDownListApprove.SelectedValue == "1" ? true : false;
                    HiddenField HiddenFieldID = item.FindControl("HiddenFieldID") as HiddenField;///当前Item的 ID
                    if (IsApproved)//审批通过,加入到要修改的集合中。
                    {
                        Label LabelStyleNO = item.FindControl("LabelStyleNO") as Label;
                        Label LabelNewOSP = item.FindControl("LabelNewOSP") as Label;

                        DataRow dr = dtUpdate.NewRow();
                        dr["StyleNO"] = LabelStyleNO.Text;
                        dr["NewOSP"] = LabelNewOSP.Text.Trim();
                        dtUpdate.Rows.Add(dr);
                    }
                    else//审批不通过
                    {
                        OSPCommon comm = new OSPCommon();
                        comm.UpdateItemSapStatus(HiddenFieldID.Value, IsApproved, false);//将审批不通过修改到Item的状态 中
                        HiddenFieldISSuccess.Value = "1";//页面上标注为己经更新。
                    }
                }
            }
            return dtUpdate;
        }
Пример #8
0
        /// <summary>
        /// 得到Repeater里的数据
        /// </summary>
        /// <param name="sWorkflowNumber"></param>
        /// <returns></returns>
        public DataTable GetResultDt(string sWorkflowNumber)
        {
            DataTable dt = new DataTable();
            OSPCommon comm = new OSPCommon();
            dt = comm.CreateData();
            StringBuilder sbErrorInfo = new StringBuilder();
            foreach (RepeaterItem item in RepeaterPOData.Items)
            {
                TextBox TextBoxNewOSP = item.FindControl("TextBoxNewOSP") as TextBox;
                Label LabelStyleNO = item.FindControl("LabelStyleNO") as Label;
                decimal dNewOSP = 0;
                if (!decimal.TryParse(TextBoxNewOSP.Text.Trim(), out dNewOSP))
                {
                    sbErrorInfo.Append(string.Format("Style No.:{0} ,NewOSP Value format error or empty ! \\n"));
                    continue;
                }
                Label LabelAllocatedDate = item.FindControl("LabelAllocatedDate") as Label;
                string sAllocatedDate = LabelAllocatedDate.Text.Trim();
                if (sAllocatedDate.Length > 0)
                {
                    continue;
                }

                Label LabelOriginalOsp = item.FindControl("LabelOriginalOsp") as Label;
                Label LabelPONO = item.FindControl("LabelPONO") as Label;
                Label LabelSubDiv = item.FindControl("LabelSubDiv") as Label;
                Label LabelClass = item.FindControl("LabelClass") as Label;
                Label LabelQty = item.FindControl("LabelQty") as Label;
                Label LabelCurrentOMU = item.FindControl("LabelCurrentOMU") as Label;
                Label LabelCreatedBy = item.FindControl("LabelCreatedBy") as Label;
                Label LabelPAD = item.FindControl("LabelPAD") as Label;
                Label LabelSAD = item.FindControl("LabelSAD") as Label;
                Label LabelGR = item.FindControl("LabelGR") as Label;
                HiddenField HiddenFieldISSuccess = item.FindControl("HiddenFieldISSuccess") as HiddenField;
                HiddenField HiddenFieldCost = item.FindControl("HiddenFieldCost") as HiddenField;
                decimal dNewOMU = 0;
                decimal dCost=0;
                DataRow dr = dt.NewRow();
                if (decimal.TryParse(HiddenFieldCost.Value, out dCost) && dNewOSP != 0)
                {
                    dNewOMU = ((dNewOSP - dCost) / dNewOSP)*100;
                    dr["NewOMU"] = dNewOMU.ToString("0.00")+"%";
                }

                decimal dOrigialOSP = 0;
                string sOMUReduction = string.Empty;
                decimal dQty = 0;
                if (decimal.TryParse(LabelOriginalOsp.Text.Trim(), out dOrigialOSP)&&decimal.TryParse(LabelQty.Text.Trim(), out dQty))
                {
                    sOMUReduction = Math.Round((dOrigialOSP - dNewOSP) * dQty,0).ToString();// ((dOrigialOSP - dNewOSP) * dQty)
                    dr["OMUReduction"] = sOMUReduction;
                }
                dr["Title"] = LabelStyleNO.Text.Trim();
                dr["WorkflowNumber"] = sWorkflowNumber;
                dr["Class"] = LabelClass.Text.Trim() ;
                dr["SubDiv"] = LabelSubDiv.Text.Trim();
                dr["PONO"] = LabelPONO.Text.Trim();
                dr["Qty"] = dQty.ToString();
                dr["OriginalOsp"] = dOrigialOSP.ToString();
                dr["NewOSP"] = dNewOSP;
                dr["CurrentOMU"] = LabelCurrentOMU.Text.Trim();
                dr["CreatedBy"] = LabelCreatedBy.Text.Trim();
                dr["PAD"] = LabelPAD.Text.Trim();
                dr["SAD"] = LabelSAD.Text.Trim();
                dr["GR"] = LabelGR.Text.Trim();
                dr["Cost"] = dCost;
                dr["AllocatedDate"] = sAllocatedDate;
                string sIsSuccess = HiddenFieldISSuccess.Value;
                dr["IsSuccess"] = sIsSuccess;
                if (sIsSuccess == "1")
                {
                    dr["IsApproved"] = "1";
                }

                dt.Rows.Add(dr);
            }
            if (sbErrorInfo.Length > 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", string.Format("<script>alert('{0}')</script>", sbErrorInfo.ToString()));
                return null;
            }
            else
            {
                return dt;
            }
        }
Пример #9
0
 /// <summary>
 /// 绑定 Repeater
 /// </summary>
 /// <param name="dtSearchCondition"></param>
 void BindRepeater(DataTable dtSearchCondition)
 {
     OSPCommon comm = new OSPCommon();
     DataTable dt = new DataTable();
     dt = comm.GetOSPInfoFromSAP(dtSearchCondition);
     if (comm.sErrorMsg.Length > 0)
     {
         string sMessage = comm.sErrorMsg.ToString();
         Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", string.Format("<script>alert('{0}')</script>", sMessage));
     }
     RepeaterPOData.DataSource = dt;
     RepeaterPOData.DataBind();
     LabelCount.Text = dt.Rows.Count.ToString();
 }
Пример #10
0
        protected void ButtonBatchSearch_Click(object sender, EventArgs e)
        {
            string sPONOs = TextBoxPONOs.Text.Trim();
            if (sPONOs.Length == 0)
            {
                return;
            }

            List<string> listStyleNO = new List<string>();
            listStyleNO = sPONOs.Split(',').ToList();
            OSPCommon comm = new OSPCommon();

            listStyleNO = comm.GetDistingctList(listStyleNO);///去除重复的StyleNo.

            DataTable dtSearchConditon = IniteSearchCondition();
            foreach (string str in listStyleNO)
            {
                DataRow dr = dtSearchConditon.NewRow();
                dr["StyleNO"] = str;
                //dr["NewOSP"] = 100;
                dtSearchConditon.Rows.Add(dr);
            }
            BindRepeater(dtSearchConditon);
        }
Пример #11
0
        /// <summary>
        /// 执行工作流
        /// </summary>
        /// <param name="isSubmit"></param>
        /// <returns></returns>
        bool RunWorkflow(bool isSubmit)
        {
            WorkflowDataFields fields = WorkflowContext.Current.DataFields;
            string sWorkflowNO = fields["Title"].ToString();
            bool isSuccess = true;

            DataTable dt = DataEdit1.GetResultDt(sWorkflowNO);
            if (null == dt || dt.Rows.Count == 0)
            {
                DisplayMessage("No avaliable data!");
                return false;
            }
            else
            {
                OSPCommon comm = new OSPCommon();
                comm.DeleteData(sWorkflowNO);//删除老数据
                comm.BatchAddToListByDatatable(dt, "OSPItems");//添加新数据
                WorkflowContext context = WorkflowContext.Current;
                if (isSubmit)//是提交
                {
                    bool isNotNeedApprove = DataEdit1.IsNotNeedApprove();
                    if (isNotNeedApprove)//不需要审批
                    {
                        bool isAllUpdated = DataEdit1.UpdateToSAP(sWorkflowNO);
                        if (isAllUpdated)//全部更新成功。
                        {
                            context.UpdateWorkflowVariable("OSPActions", OSPCommon.End);
                            fields["Status"] = CAWorkflowStatus.Completed;

                            //comm.UpdateOSPSuccess(sWorkflowNO);
                        }
                        else
                        {
                            isSuccess = false;
                        }
                    }
                }

                fields["Applicant"] = CurrentEmployee.DisplayName + "(" + CurrentEmployee.UserAccount + ")";
                SPUser ApplicantSPUser = SPContext.Current.Web.EnsureUser(Userinfo1.Applicant.UserAccount);
                fields["ApplicantSPUser"] = ApplicantSPUser;
                return isSuccess;
            }
        }
Пример #12
0
        /// <summary>
        /// 开启工作流
        /// </summary>
        /// <param name="isSubmit"></param>
        /// <returns></returns>
        bool StartWorkflow(bool isSubmit)
        {
            bool isOK = DataEditEdit.CheckData();
            if (!isOK)
            {
                return false;
            }
            string sWorkflowNumber = CreateWorkFlowNumber();

            DataTable dt = DataEditEdit.GetResultDt(sWorkflowNumber);
            if (null == dt || dt.Rows.Count == 0)
            {
                DisplayMessage("No avaliable data!");
                return false;
            }
            else
            {
                if (SetWorkflowVariable(sWorkflowNumber, isSubmit))//保存
                {
                    OSPCommon comm = new OSPCommon();
                    comm.BatchAddToListByDatatable(dt, "OSPItems");
                    if (HiddenFieldIsNotNeedApprove.Value=="1")//不需要通过审批
                    {
                        WorkflowContext context = WorkflowContext.Current;
                        WorkflowDataFields fields = WorkflowContext.Current.DataFields;

                        context.UpdateWorkflowVariable("OSPActions", OSPCommon.End);
                        fields["Status"] = CAWorkflowStatus.Completed;
                        comm.UpdateOSPSuccess(sWorkflowNumber);
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }