Beispiel #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         var project_id = Request.QueryString["project_id"];
         thisProject = new pro_project_dal().FindNoDeleteById(long.Parse(project_id));
         if (thisProject != null)
         {
             project_udf_list     = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.PROJECTS);
             project_udfValueList = new UserDefinedFieldsBLL().GetUdfValue(DicEnum.UDF_CATE.PROJECTS, thisProject.id, project_udf_list);
             thisAccount          = new CompanyBLL().GetCompany(thisProject.account_id);
             if (thisProject.opportunity_id != null)
             {
                 thisOppo = new crm_opportunity_dal().FindNoDeleteById((long)thisProject.opportunity_id);
             }
         }
     }
     catch (Exception)
     {
         Response.End();
     }
 }
Beispiel #2
0
        protected List <crm_quote_item> degressionItem    = null; // 成本的配置项
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                #region  拉框赋值
                stage_id.DataTextField  = "show";
                stage_id.DataValueField = "val";
                stage_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "opportunity_stage").Value;
                stage_id.DataBind();

                win_reason_type_id.DataTextField  = "show";
                win_reason_type_id.DataValueField = "val";
                win_reason_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_win_reason_type").Value;
                win_reason_type_id.DataBind();
                win_reason_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                resource_id.DataTextField  = "show";
                resource_id.DataValueField = "val";
                resource_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value;
                resource_id.DataBind();

                competitor_id.DataTextField  = "show";
                competitor_id.DataValueField = "val";
                competitor_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "competition").Value;
                competitor_id.DataBind();
                competitor_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                // period_type
                period_type.DataTextField  = "show";
                period_type.DataValueField = "val";
                period_type.DataSource     = dic.FirstOrDefault(_ => _.Key == "period_type").Value;
                period_type.DataBind();
                period_type.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                // notifi_temp 通知模板
                var tempList = new sys_notify_tmpl_dal().GetTempByEvent(DicEnum.NOTIFY_EVENT.OPPORTUNITY_CLOSED);
                notifi_temp.DataTextField  = "name";
                notifi_temp.DataValueField = "id";
                notifi_temp.DataSource     = tempList;
                notifi_temp.DataBind();
                #endregion
                var id         = Request.QueryString["id"];
                var account_id = Request.QueryString["account_id"];
                if (!string.IsNullOrEmpty(id))
                {
                    if (string.IsNullOrEmpty(account_id))
                    {
                        if (!IsPostBack)
                        {
                            opportunity_id.Enabled = false;
                        }
                    }
                    opportunity = new crm_opportunity_dal().GetOpportunityById(long.Parse(id));
                    if (opportunity != null)
                    {
                        account    = new CompanyBLL().GetCompany(opportunity.account_id);
                        account_id = account.id.ToString();
                    }
                }
                if (!string.IsNullOrEmpty(account_id))
                {
                    account = new CompanyBLL().GetCompany(long.Parse(account_id));
                    var oppoList = new crm_opportunity_dal().FindOpHistoryByAccountId(long.Parse(account_id));
                    if (oppoList != null && oppoList.Count > 0)
                    {
                        opportunity_id.DataTextField  = "name";
                        opportunity_id.DataValueField = "id";
                        opportunity_id.DataSource     = oppoList;
                        opportunity_id.DataBind();
                    }
                    else
                    {
                        Response.Write("<script>alert('该客户还没有商机!');window.close();</script>");
                    }

                    //opportunity_id.Items.Insert(0, new ListItem() { Value = "0", Text = "   ", Selected = true });
                    if (string.IsNullOrEmpty(id))
                    {
                        opportunity = oppoList[0];
                    }
                    opportunity_id.SelectedValue = opportunity.id.ToString();
                }

                if (!IsPostBack)
                {
                    if (opportunity != null)
                    {
                        if (opportunity.status_id == (int)OPPORTUNITY_STATUS.CLOSED)
                        {
                            Response.Write("<script>if(!confirm('商机已被关闭,如果继续,系统会重复创建计费项和合同?')){window.close();}</script>");
                        }
                    }
                    if (opportunity.stage_id != null)
                    {
                        stage_id.SelectedValue = opportunity.stage_id.ToString();
                    }
                    else
                    {
                        var stageList    = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.OPPORTUNITY_STATUS);
                        var defaultStage = stageList.FirstOrDefault(_ => _.ext1 == "1");
                        if (defaultStage != null)
                        {
                            stage_id.SelectedValue = defaultStage.id.ToString();
                        }
                    }
                    // stage_id.SelectedValue = opportunity.stage_id == null ? "0" : opportunity.stage_id.ToString();
                    resource_id.SelectedValue        = opportunity.resource_id.ToString();
                    competitor_id.SelectedValue      = opportunity.competitor_id == null ? "0" : opportunity.competitor_id.ToString();
                    win_reason_type_id.SelectedValue = opportunity.win_reason_type_id == null ? "0" : opportunity.win_reason_type_id.ToString();
                }
                // 折扣的下拉框不同于别的下拉框-- 需要去两个数据源去赋值
                StringBuilder text     = new StringBuilder();
                var           costCode = new d_cost_code_dal().GetListCostCode((int)COST_CODE_CATE.MATERIAL_COST_CODE);
                text.Append($"<option value='0'>   </option>");
                if (costCode != null && costCode.Count > 0)
                {
                    foreach (var item in costCode)
                    {
                        text.Append($"<option value='{item.id}'>{item.name}</option>");
                    }
                }
                codeSelect.Value = text.ToString();
                var disSource   = "";
                var disCostCode = costCode.Where(_ => _.id == (int)CostCode.NOTAXDISCOUNT || _.id == (int)CostCode.DISCOUNT).ToList();
                if (disCostCode != null && disCostCode.Count > 0)
                {
                    foreach (var item in disCostCode)
                    {
                        disSource += $"<option value='{item.id}'>{item.name}</option>";
                    }
                }
                disCodeSelct.Value        = disSource;
                period_type.SelectedValue = ((int)QUOTE_ITEM_PERIOD_TYPE.MONTH).ToString();
                primaryQuote = new QuoteBLL().GetPrimaryQuote(opportunity.id);


                if (primaryQuote != null)
                {
                    if (!IsPostBack)
                    {
                        if (primaryQuote.project_id != null) // 判断该报价是否关联项目提案,如果关联,默认选中,不关联,灰掉,不可选
                        {
                            activeproject.Checked = true;
                            activeproject.Enabled = true;
                            addRequest.Enabled    = false;
                            isaddRequest.Value    = "1";
                        }
                        else
                        {
                            activeproject.Checked = false;
                            addRequest.Enabled    = true;

                            activeproject.Enabled = false;
                            isactiveproject.Value = "1";
                        }
                    }
                    quoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id = {primaryQuote.id}");
                    if (quoteItemList != null && quoteItemList.Count > 0)
                    {
                        // 如果报价项中包含了服务 / 服务包、初始费用,则可以选中(默认不选)
                        // 此功能需要具有合同模块权限以及修改合同服务/包权限

                        var isServiceChargeItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.SERVICE || _.type_id == (int)QUOTE_ITEM_TYPE.SERVICE_PACK || _.type_id == (int)QUOTE_ITEM_TYPE.START_COST).ToList();
                        if (!IsPostBack)
                        {
                            if (isServiceChargeItem != null && isServiceChargeItem.Count > 0)
                            {
                                // todo--需要判断用户权限
                            }
                            else
                            {
                                addContractRequest.Enabled  = false;
                                isAddContractRequest.Value  = "1";
                                addContractServices.Enabled = false;
                                isaddContractServices.Value = "1";
                            }
                        }
                        proAndOneTimeItem = quoteItemList.Where(_ => _.optional != 1).Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT || _.type_id == (int)QUOTE_ITEM_TYPE.DISCOUNT).ToList();
                        if (!IsPostBack)
                        {
                            if (proAndOneTimeItem != null && proAndOneTimeItem.Count > 0)
                            {
                                isIncludePO.Checked = true;
                            }
                            else
                            {
                                IncludePO.Value     = "1";
                                isIncludePO.Enabled = false;
                            }
                        }
                        shipItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional != 1).ToList();
                        if (!IsPostBack)
                        {
                            if (shipItem != null && shipItem.Count > 0)
                            {
                                isIncludeShip.Checked = true;
                            }
                            else
                            {
                                IncludeShip.Value     = "1";
                                isIncludeShip.Enabled = false;
                            }
                        }
                        degressionItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.DEGRESSION & _.optional != 1).ToList();
                        if (!IsPostBack)
                        {
                            if (degressionItem != null && degressionItem.Count > 0)
                            {
                                isIncludeCharges.Checked = true;
                            }
                            else
                            {
                                IncludeCharges.Value     = "1";
                                isIncludeCharges.Enabled = false;
                            }
                        }
                        jqueryCode.Value = ReturnJquery();
                    }
                    else
                    {
                        // activeproject.Enabled = false;
                        //isactiveproject.Value = "1";
                        addContractRequest.Enabled  = false;
                        isAddContractRequest.Value  = "1";
                        addContractServices.Enabled = false;
                        isaddContractServices.Value = "1";
                        IncludePO.Value             = "1";
                        isIncludePO.Enabled         = false;
                        IncludeShip.Value           = "1";
                        isIncludeShip.Enabled       = false;
                        IncludeCharges.Value        = "1";
                        isIncludeCharges.Enabled    = false;
                    }
                }
                else
                {
                    activeproject.Enabled       = false;
                    isactiveproject.Value       = "1";
                    addContractRequest.Enabled  = false;
                    isAddContractRequest.Value  = "1";
                    addContractServices.Enabled = false;
                    isaddContractServices.Value = "1";
                    IncludePO.Value             = "1";
                    isIncludePO.Enabled         = false;
                    IncludeShip.Value           = "1";
                    isIncludeShip.Enabled       = false;
                    IncludeCharges.Value        = "1";
                    isIncludeCharges.Enabled    = false;
                }
            }
            catch (Exception msg)
            {
                Response.End();
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId);
                var soid = Request.QueryString["id"];
                if (AuthBLL.GetUserSaleorderAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(soid)).CanEdit == false)
                {
                    Response.End();
                    return;
                }

                sale_order = new crm_sales_order_dal().GetSingleSalesOrderByWhere($" and id = {soid}");
                if (sale_order != null)
                {
                    sale_udfList      = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.SALES);
                    sale_udfValueList = new UserDefinedFieldsBLL().GetUdfValue(DicEnum.UDF_CATE.SALES, sale_order.id, sale_udfList);
                    opportunity       = new crm_opportunity_dal().GetOpportunityById(sale_order.opportunity_id);
                    if (!IsPostBack)
                    {
                        var contactList = new crm_contact_dal().GetContactByAccountId(opportunity.account_id);


                        #region  拉赋值
                        status_id.DataTextField  = "show";
                        status_id.DataValueField = "val";
                        status_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "sales_order_status").Value;
                        status_id.DataBind();
                        status_id.Items.Insert(0, new ListItem()
                        {
                            Value = "0", Text = "   ", Selected = true
                        });

                        owner_resource_id.DataTextField  = "show";
                        owner_resource_id.DataValueField = "val";
                        owner_resource_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value;
                        owner_resource_id.DataBind();
                        owner_resource_id.Items.Insert(0, new ListItem()
                        {
                            Value = "0", Text = "   ", Selected = true
                        });

                        // bill_country_id
                        bill_country_id.DataTextField  = "show";
                        bill_country_id.DataValueField = "val";
                        bill_country_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "country").Value;
                        bill_country_id.DataBind();
                        bill_country_id.Items.Insert(0, new ListItem()
                        {
                            Value = "0", Text = "   ", Selected = true
                        });
                        bill_country_id.SelectedValue = "1";

                        ship_country_id.DataTextField  = "show";
                        ship_country_id.DataValueField = "val";
                        ship_country_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "country").Value;
                        ship_country_id.DataBind();
                        ship_country_id.Items.Insert(0, new ListItem()
                        {
                            Value = "0", Text = "   ", Selected = true
                        });
                        ship_country_id.SelectedValue = "1";
                        // contact_id
                        contact_id.DataTextField  = "name";
                        contact_id.DataValueField = "id";
                        contact_id.DataSource     = contactList.Where(_ => _.is_active == 1).ToList();
                        contact_id.DataBind();
                        contact_id.Items.Insert(0, new ListItem()
                        {
                            Value = "0", Text = "   ", Selected = true
                        });
                        if (sale_order.contact_id != null)
                        {
                            contact_id.SelectedValue = sale_order.contact_id.ToString();
                        }

                        #endregion
                        billTo_use_account_address.Checked = sale_order.bill_to_use_account_address == 1;
                        shipTo_use_account_address.Checked = sale_order.ship_to_use_account_address == 1;
                        shipTo_use_bill_to_address.Checked = sale_order.ship_to_use_bill_to_address == 1;

                        status_id.SelectedValue         = sale_order.status_id.ToString();
                        owner_resource_id.SelectedValue = sale_order.owner_resource_id.ToString();
                    }
                }
                else
                {
                    Response.End();
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                thisBookMark  = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId);
                callBackFiled = Request.QueryString["callBackFiled"];

                var opportunity_id = Request.QueryString["opportunity_id"];
                if (!string.IsNullOrEmpty(opportunity_id))
                {
                    if (AuthBLL.GetUserOppAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(opportunity_id)).CanEdit == false)
                    {
                        Response.End();
                        return;
                    }

                    opportunity = new crm_opportunity_dal().GetOpportunityById(Convert.ToInt64(opportunity_id));
                }
                dic = new OpportunityBLL().GetField();

                #region 配置下拉框的数据源
                // 商机负责人
                resource_id.DataTextField  = "show";
                resource_id.DataValueField = "val";
                resource_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value;
                resource_id.DataBind();
                resource_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // 当前阶段
                stage_id.DataTextField  = "show";
                stage_id.DataValueField = "val";
                stage_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "opportunity_stage").Value;
                stage_id.DataBind();
                stage_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                stage_id.SelectedValue = ((int)OPPORTUNITY_STAGE.NEW_CLUE).ToString();
                // 感兴趣等级
                interest_degree_id.DataTextField  = "show";
                interest_degree_id.DataValueField = "val";
                interest_degree_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "opportunity_interest_degree").Value;
                interest_degree_id.DataBind();
                interest_degree_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // 商机来源
                source_id.DataTextField  = "show";
                source_id.DataValueField = "val";
                source_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "opportunity_source").Value;
                source_id.DataBind();
                source_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // 状态
                status_id.DataTextField  = "show";
                status_id.DataValueField = "val";
                status_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_status").Value;
                status_id.DataBind();
                status_id.SelectedValue = ((int)OPPORTUNITY_STATUS.ACTIVE).ToString();
                //status_id.Items.Insert(0, new ListItem() { Value = "0", Text = "   ", Selected = true });
                // 主要竞争对手
                competitor_id.DataTextField  = "show";
                competitor_id.DataValueField = "val";
                competitor_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "competition").Value;
                competitor_id.DataBind();
                competitor_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // 赢单原因
                win_reason_type_id.DataTextField  = "show";
                win_reason_type_id.DataValueField = "val";
                win_reason_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_win_reason_type").Value;
                win_reason_type_id.DataBind();
                win_reason_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // 丢单原因
                loss_reason_type_id.DataTextField  = "show";
                loss_reason_type_id.DataValueField = "val";
                loss_reason_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_loss_reason_type").Value;
                loss_reason_type_id.DataBind();
                loss_reason_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // 通知模板   --todo 需要过滤商机创建或编辑相关的通知模板
                //notify_tmpl_id.DataTextField = "show";
                //notify_tmpl_id.DataValueField = "val";
                //notify_tmpl_id.DataSource = dic.FirstOrDefault(_ => _.Key == "notify_tmpl").Value;
                //notify_tmpl_id.DataBind();
                //notify_tmpl_id.Items.Insert(0, new ListItem() { Value = "0", Text = "   ", Selected = true });


                var formTemplateList = new FormTemplateBLL().GetTemplateOpportunityByUser(GetLoginUserId());
                formTemplate.DataTextField  = "speed_code";
                formTemplate.DataValueField = "id";
                formTemplate.DataSource     = formTemplateList;
                formTemplate.DataBind();
                formTemplate.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                #endregion


                opportunity_udfList = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.OPPORTUNITY);
                if (opportunity != null)
                {
                    isAdd = false;

                    //company_udfList = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.COMPANY);
                }

                if (!isAdd)
                {
                    opportunity_udfValueList = new UserDefinedFieldsBLL().GetUdfValue(DicEnum.UDF_CATE.OPPORTUNITY, opportunity.id, opportunity_udfList);
                    if (!IsPostBack)
                    {
                        resource_id.SelectedValue         = opportunity.resource_id.ToString();
                        stage_id.SelectedValue            = opportunity.stage_id == null ? "0" : opportunity.stage_id.ToString();
                        interest_degree_id.SelectedValue  = opportunity.interest_degree_id == null ? "0" : opportunity.interest_degree_id.ToString();
                        source_id.SelectedValue           = opportunity.source_id == null ? "0" : opportunity.source_id.ToString();
                        status_id.SelectedValue           = opportunity.status_id == null ? "0" : opportunity.status_id.ToString();
                        competitor_id.SelectedValue       = opportunity.competitor_id == null ? "0" : opportunity.competitor_id.ToString();
                        win_reason_type_id.SelectedValue  = opportunity.win_reason_type_id == null ? "0" : opportunity.win_reason_type_id.ToString();
                        loss_reason_type_id.SelectedValue = opportunity.loss_reason_type_id == null ? "0" : opportunity.loss_reason_type_id.ToString();


                        is_use_quote.Checked = opportunity.use_quote == 1;
                    }
                }
                else
                {
                    //  联系人查看的时候穿过来客户ID,和联系人ID,联系人不能更改,只有更改客户才可以更改联系人
                    var contact_id = Request.QueryString["oppo_contact_id"];
                    if (!string.IsNullOrEmpty(contact_id))
                    {
                        contact = new ContactBLL().GetContact(Convert.ToInt64(contact_id));
                    }

                    var account_id = Request.QueryString["oppo_account_id"];
                    if (!string.IsNullOrEmpty(account_id))
                    {
                        account = new CompanyBLL().GetCompany(Convert.ToInt64(account_id));
                    }
                }
            }
            catch (Exception msg)
            {
                Response.End();
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                // todo - 商机的重新指派

                var sid = Request.QueryString["id"];
                if (AuthBLL.GetUserSaleorderAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(sid)).CanView == false)
                {
                    Response.End();
                    return;
                }
                thisBookMark = new IndexBLL().GetSingBook(Request.Url.LocalPath + "?id=" + sid, LoginUserId);

                type        = Request.QueryString["type"];
                sale_order  = new crm_sales_order_dal().GetSingleSale(long.Parse(sid));
                opportunity = new crm_opportunity_dal().GetOpportunityById(sale_order.opportunity_id);
                account     = new CompanyBLL().GetCompany(opportunity.account_id);
                quote       = new QuoteBLL().GetPrimaryQuote(opportunity.id);
                if (sale_order.contact_id != null)
                {
                    contact = new ContactBLL().GetContact((long)sale_order.contact_id);
                }
                switch (type)
                {
                case "activity":
                    actType          = "活动";
                    isShowLeft.Value = "1";
                    break;

                case "todo":
                    actType          = "待办";
                    iframeSrc        = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.TODOS + "&type=" + (int)QueryType.Todos + "&group=131&con676=" + sale_order.id + "&param1=saleorderId&param2=" + sale_order.id;
                    isShowLeft.Value = "1";
                    break;

                case "note":
                    actType          = "备注";
                    iframeSrc        = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.CRM_NOTE_SEARCH + "&type=" + (int)QueryType.CRMNote + "&group=129&con675=" + sale_order.id + "&param1=saleorderId&param2=" + sale_order.id;
                    isShowLeft.Value = "1";
                    break;

                case "ticket":
                    actType = "工单";
                    break;

                case "attachment":
                    actType   = "附件";
                    iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.SALES_ORDER_VIEW_ATTACHMENT + "&type=" + (int)QueryType.SalesOrderViewAttachment + "&con977=" + sale_order.id;
                    break;

                case "entry":
                    actType   = "报价项";
                    iframeSrc = "../QuoteItem/QuoteItemManage.aspx?isShow=1&quote_id=" + quote.id + "&isSaleOrder=1&sale_order_id=" + sale_order.id;
                    break;

                case "purchaseOrder":
                    actType = "采购订单";
                    break;

                default:
                    actType          = "活动";
                    type             = "activity";
                    isShowLeft.Value = "1";
                    break;
                }

                if (type.Equals("activity"))
                {
                    var typeList = new ActivityBLL().GetCRMActionType();
                    noteType.DataSource     = typeList;
                    noteType.DataTextField  = "name";
                    noteType.DataValueField = "id";
                    noteType.DataBind();
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId);
                tmplList     = new FormTemplateBLL().GetTmplByType((int)DicEnum.FORM_TMPL_TYPE.QUOTE, LoginUserId);
                var id = Request.QueryString["id"];
                dic = new QuoteBLL().GetField();
                #region  拉框配置数据源
                tax_region_id.DataValueField = "val";
                tax_region_id.DataTextField  = "show";
                tax_region_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "taxRegion").Value;
                tax_region_id.DataBind();
                tax_region_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                payment_term_id.DataValueField = "val";
                payment_term_id.DataTextField  = "show";
                payment_term_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "payment_term").Value;
                payment_term_id.DataBind();
                payment_term_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });


                payment_type_id.DataValueField = "val";
                payment_type_id.DataTextField  = "show";
                payment_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "payment_type").Value;
                payment_type_id.DataBind();
                payment_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                shipping_type_id.DataValueField = "val";
                shipping_type_id.DataTextField  = "show";
                shipping_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "payment_ship_type").Value;
                shipping_type_id.DataBind();
                shipping_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                quote_tmpl_id.DataValueField = "id";
                quote_tmpl_id.DataTextField  = "name";
                quote_tmpl_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "quote_tmpl").Value;
                quote_tmpl_id.DataBind();
                quote_tmpl_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                var prolist = new pro_project_dal().GetProjectList();
                // project_id
                //project_id.DataValueField = "id";
                //project_id.DataTextField = "name";
                //project_id.DataSource = prolist;
                //project_id.DataBind();
                //project_id.Items.Insert(0, new ListItem() { Value = "0", Text = "   ", Selected = true });
                #endregion

                if (!string.IsNullOrEmpty(id))
                {
                    if (AuthBLL.GetUserQuoteAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(id)).CanEdit == false)
                    {
                        Response.End();
                        return;
                    }
                    quote = new crm_quote_dal().GetQuote(Convert.ToInt64(id));
                    if (quote != null)
                    {
                        if (string.IsNullOrEmpty(Request.QueryString["copy"]))
                        {
                            isAdd = false;
                        }
                    }
                }
                else
                {
                    var opportunity_id = Request.QueryString["quote_opportunity_id"];
                    if (!string.IsNullOrEmpty(opportunity_id))
                    {
                        opportunity = new crm_opportunity_dal().GetOpportunityById(long.Parse(opportunity_id));
                        account     = new CompanyBLL().GetCompany(opportunity.account_id);
                    }
                }
                if (!IsPostBack)
                {
                    if (!isAdd)
                    {
                        account = new CompanyBLL().GetCompany(quote.account_id);
                        if (account != null)
                        {
                            tax_region_id.SelectedValue = account.tax_region_id != null?account.tax_region_id.ToString() : "0";

                            payment_term_id.SelectedValue = quote.payment_term_id != null?quote.payment_term_id.ToString() : "0";

                            payment_type_id.SelectedValue = quote.payment_type_id != null?quote.payment_type_id.ToString() : "0";   //shipping_type_id

                            shipping_type_id.SelectedValue = quote.shipping_type_id != null?quote.shipping_type_id.ToString() : "0";

                            quote_tmpl_id.SelectedValue = quote.quote_tmpl_id != null?quote.quote_tmpl_id.ToString() : "0";

                            //project_id.SelectedValue = quote.project_id!=null ?  quote.project_id.ToString() : "0";
                            BillLocation.Checked = quote.bill_to_location_id == quote.sold_to_location_id;
                            ShipLocation.Checked = quote.ship_to_location_id == quote.sold_to_location_id;
                        }
                        #region 记录浏览历史
                        var history = new sys_windows_history()
                        {
                            title = $"编辑报价:" + quote.name + " " + (account != null ? account.name : ""),
                            url   = Request.RawUrl,
                        };
                        new IndexBLL().BrowseHistory(history, LoginUserId);
                        #endregion
                    }
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Beispiel #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var id = Request.QueryString["id"];

                if (AuthBLL.GetUserOppAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(id)).CanView == false)
                {
                    Response.End();
                    return;
                }

                opportunity = new crm_opportunity_dal().GetOpportunityByOtherId(Convert.ToInt64(id));
                type        = Request.QueryString["type"];

                if (opportunity != null)
                {
                    dic       = new OpportunityBLL().GetField();
                    quoteList = new crm_quote_dal().GetQuoteByOpportunityId(opportunity.id);
                    account   = new CompanyBLL().GetCompany(opportunity.account_id);
                    if (opportunity.contact_id != null)
                    {
                        contact = new ContactBLL().GetContact((long)opportunity.contact_id);
                    }
                    thisBookMark = new IndexBLL().GetSingBook(Request.Url.LocalPath + "?id=" + opportunity.id, LoginUserId);



                    switch (type)    // 根据传过来的不同的类型,为页面中的iframe控件选择不同的src
                    {
                    case "todo":
                        iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.TODOS + "&type=" + (int)QueryType.Todos + "&group=112&con660=" + opportunity.id + "&param1=opportunityId&param2=" + opportunity.id;                                  // 待办
                        actType   = "待办";
                        break;

                    case "note":
                        iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.CRM_NOTE_SEARCH + "&type=" + (int)QueryType.CRMNote + "&group=110&con647=" + opportunity.id + "&param1=opportunityId&param2=" + opportunity.id;                                 // 备注
                        actType   = "备注";
                        break;

                    case "activity":
                        iframeSrc = "";                                  // 活动
                        actType   = "活动";
                        break;

                    case "ticket":
                        iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)EMT.DoneNOW.DTO.DicEnum.QUERY_CATE.MY_QUEUE_ACTIVE + "&type=" + (int)EMT.DoneNOW.DTO.QueryType.MY_QUEUE_ACTIVE + "&group=215&con5603=" + opportunity.id + "&param1=ShowPara";
                        actType   = "工单";
                        break;

                    case "quoteItem":
                        var oppoQuoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {opportunity.id} ");

                        if (oppoQuoteList != null && oppoQuoteList.Count > 0)
                        {
                            iframeSrc        = "../QuoteItem/QuoteItemManage?isShow=show&opportunity_id=" + opportunity.id; // 报价项
                            isAddQuote.Value = "0";
                        }
                        else
                        {
                            isAddQuote.Value = "1";
                            //ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>if(confirm('商机尚未创建报价,需要现在创建吗?')){window.open('../Quote/QuoteAddAndUpdate.aspx?quote_opportunity_id=" + opportunity.id + "', '" + (int)EMT.DoneNOW.DTO.OpenWindow.QuoteAdd + "', 'left=200,top=200,width=960,height=750', false);}</script>");
                            //Response.Write("<script>debugger;</script>");
                        }

                        actType = "报价项";
                        break;

                    case "att":
                        iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.OPPORTUNITY_VIEW_ATTACHMENT + "&type=" + (int)QueryType.OpportunityViewAttachment + "&con976=" + opportunity.id;
                        actType   = "附件";
                        break;

                    default:
                        iframeSrc = "";      // 默认
                        actType   = "活动";
                        type      = "activity";
                        break;
                    }
                    if (type == "activity" || type == "note" || type == "todo")
                    {
                        isHide.Value = "show";
                    }
                    if (type.Equals("activity"))
                    {
                        var typeList = new ActivityBLL().GetCRMActionType();
                        noteType.DataSource     = typeList;
                        noteType.DataTextField  = "name";
                        noteType.DataValueField = "id";
                        noteType.DataBind();
                    }
                }
                else
                {
                    Response.End();
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
        private void SyncSalesInvoice(List <contact> ContactList, DateTime InvoiceDate)
        {
            app_vat_group VatGroup = CurrentSession.Get_VAT_Group().Where(x => x.is_default).FirstOrDefault();

            foreach (contact Contact in ContactList)
            {
                try
                {
                    sales_invoice sales_invoice = new sales_invoice();
                    sales_invoice.id_contact = Contact.id_contact;
                    sales_invoice.contact    = Contact;

                    app_contract app_contract = ContactDB.app_contract.Where(x => x.id_contract == Contact.id_contract).FirstOrDefault();
                    sales_invoice.id_condition  = app_contract.id_condition;
                    sales_invoice.id_contract   = app_contract.id_contract;
                    sales_invoice.id_currencyfx = CurrentSession.CurrencyFX_Default.id_currencyfx;
                    sales_invoice.comment       = "Subscription";
                    sales_invoice.trans_date    = InvoiceDate;
                    sales_invoice.timestamp     = DateTime.Now;

                    if (Contact.contact_subscription.Count > 0)
                    {
                        foreach (contact_subscription contact_subscription in Contact.contact_subscription)
                        {
                            sales_invoice_detail sales_invoice_detail = null;

                            sales_invoice_detail = new sales_invoice_detail();
                            sales_invoice_detail.id_sales_invoice = sales_invoice.id_sales_invoice;
                            sales_invoice_detail.sales_invoice    = sales_invoice;
                            item item = ContactDB.items.Where(x => x.id_item == contact_subscription.id_item).FirstOrDefault();

                            if (item != null)
                            {
                                sales_invoice_detail.item             = item;
                                sales_invoice_detail.id_vat_group     = contact_subscription.id_vat_group > 0 ? contact_subscription.id_vat_group : VatGroup.id_vat_group;
                                sales_invoice_detail.id_item          = contact_subscription.id_item;
                                sales_invoice_detail.item_description = contact_subscription.item.name;
                            }
                            else
                            {
                                continue;
                            }

                            sales_invoice_detail.quantity      = contact_subscription.quantity;
                            sales_invoice_detail.UnitPrice_Vat = contact_subscription.UnitPrice_Vat;

                            sales_invoice.sales_invoice_detail.Add(sales_invoice_detail);
                        }

                        if (sales_invoice.sales_invoice_detail.Count > 0)
                        {
                            sales_invoice.State      = EntityState.Added;
                            sales_invoice.IsSelected = true;

                            crm_opportunity crm_opportunity = new crm_opportunity();
                            crm_opportunity.id_contact  = sales_invoice.id_contact;
                            crm_opportunity.id_currency = sales_invoice.id_currencyfx;
                            crm_opportunity.value       = sales_invoice.GrandTotal;

                            crm_opportunity.sales_invoice.Add(sales_invoice);
                            ContactDB.crm_opportunity.Add(crm_opportunity);
                            ContactDB.sales_invoice.Add(sales_invoice);
                            ContactDB.SaveChanges();
                            progBar.Value += 1;
                            // Dispatcher.BeginInvoke((Action)(() => { progBar.Value += 1; }));
                        }
                    }
                }
                catch (Exception)
                {
                    //  Dispatcher.BeginInvoke((Action)(() => { Contact.IsSelected = true; }));
                }
            }
        }
Beispiel #9
0
        protected List <crm_quote_item> serviceItem   = null; // 该报价下的服务报价项
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var quote_id = Request.QueryString["id"];
                quote = new QuoteBLL().GetQuote(long.Parse(quote_id));
                if (quote.is_primary_quote != 1) // 关闭报价只针对主报价
                {
                    Response.Write("<script>alert('关闭报价只针对主报价');window.close();</script>");
                }
                //if (quote.project_id == null)
                //{
                //    Response.Write("<script>alert('请关联项目后进行关闭报价操作');window.close();</script>");
                //}
                opportunity = new crm_opportunity_dal().GetOpportunityById(quote.opportunity_id);
                win_reason_type_id.DataTextField  = "show";
                win_reason_type_id.DataValueField = "val";
                win_reason_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_win_reason_type").Value;
                win_reason_type_id.DataBind();
                win_reason_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                win_reason_type_id.SelectedValue = opportunity.win_reason_type_id == null ? "0" : opportunity.win_reason_type_id.ToString();


                StringBuilder text     = new StringBuilder();
                var           costCode = new d_cost_code_dal().GetListCostCode((int)COST_CODE_CATE.MATERIAL_COST_CODE);
                text.Append($"<option value='0'>   </option>");
                if (costCode != null && costCode.Count > 0)
                {
                    foreach (var item in costCode)
                    {
                        text.Append($"<option value='{item.id}'>{item.name}</option>");
                    }
                }
                codeSelect.Value = text.ToString();
                var disSource   = "";
                var disCostCode = costCode.Where(_ => _.id == 37 || _.id == 43).ToList();
                if (disCostCode != null && disCostCode.Count > 0)
                {
                    foreach (var item in disCostCode)
                    {
                        disSource += $"<option value='{item.id}'>{item.name}</option>";
                    }
                }
                disCodeSelct.Value = disSource;


                quoteItemList = new crm_quote_item_dal().GetQuoteItems($"and quote_id = {quote.id}");
                quoteItemList = quoteItemList.Where(_ => _.optional == 0 && _.type_id != (int)QUOTE_ITEM_TYPE.COST && _.type_id != (int)QUOTE_ITEM_TYPE.SERVICE && _.type_id != (int)QUOTE_ITEM_TYPE.WORKING_HOURS).ToList();
                if (quoteItemList != null && quoteItemList.Count > 0)
                {
                    serviceItem = quoteItemList.Where(_ => _.type_id == (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.SERVICE || _.type_id == (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.START_COST).ToList();
                    if (serviceItem != null && serviceItem.Count > 0)
                    {
                        Response.Write("<script>alert('报价中包含服务/包、初始费用等,请使用关闭商机向导');window.close();</script>");
                    }

                    jqueryCode.Value = ReturnJquery();
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Beispiel #10
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (project != null)
            {
                toolBar             toolBar          = new cntrl.toolBar();
                List <project_task> project_taskLIST = project.project_task.Where(x => x.IsSelected).ToList();

                sales_order sales_order = new entity.sales_order();
                if (Generate_Budget)
                {
                    SalesBudgetDB SalesBudgetDB = new SalesBudgetDB();

                    sales_budget sales_budget = new entity.sales_budget();

                    sales_budget.id_contact = (int)project.id_contact;
                    sales_budget.contact    = SalesBudgetDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault();

                    sales_budget.id_project    = project.id_project;
                    sales_budget.id_condition  = (int)cbxCondition.SelectedValue;
                    sales_budget.id_contract   = (int)cbxContract.SelectedValue;
                    sales_budget.id_currencyfx = (int)cbxCurrency.SelectedValue;
                    sales_budget.comment       = "Project -> " + project.name;
                    sales_budget.trans_date    = DateTime.Now;

                    foreach (project_task _project_task in project_taskLIST)
                    {
                        sales_budget_detail sales_budget_detail = new sales_budget_detail();
                        sales_budget_detail.State            = EntityState.Added;
                        sales_budget_detail.id_sales_budget  = sales_budget.id_sales_budget;
                        sales_budget_detail.sales_budget     = sales_budget;
                        sales_budget_detail.id_item          = (int)_project_task.id_item;
                        sales_budget_detail.item_description = _project_task.item_description;

                        if (project.is_Executable)
                        {
                            sales_budget_detail.quantity = (decimal)_project_task.quantity_exe;
                        }
                        else
                        {
                            sales_budget_detail.quantity = (decimal)_project_task.quantity_est;
                        }


                        if (_project_task.unit_price_vat != null)
                        {
                            sales_budget_detail.UnitPrice_Vat = (decimal)_project_task.unit_price_vat;
                        }

                        sales_budget_detail.id_project_task = _project_task.id_project_task;
                        _project_task.IsSelected            = false;

                        sales_budget.sales_budget_detail.Add(sales_budget_detail);
                    }

                    sales_budget.State      = EntityState.Added;
                    sales_budget.IsSelected = true;
                    SalesBudgetDB.sales_budget.Add(sales_budget);
                    SalesBudgetDB.SaveChanges();
                }
                else
                {
                    //if (Generate_Budget)
                    //{
                    //    sales_order.id_sales_budget = sales_budget.id_sales_budget;
                    //}
                    if (SalesOrderDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault() != null)
                    {
                        sales_order.id_contact = (int)project.id_contact;
                        sales_order.contact    = SalesOrderDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault();
                    }
                    else
                    {
                        toolBar.msgWarning("Contact Not Found...");
                        return;
                    }

                    if (Generate_Invoice)
                    {
                        if (cbxDocument.SelectedValue != null)
                        {
                            sales_order.id_range = (int)cbxDocument.SelectedValue;
                        }
                        else
                        {
                            toolBar.msgWarning("Document Range Needed for Approval");
                            // return;
                        }
                    }
                    sales_order.id_project = project.id_project;

                    if (Convert.ToInt16(cbxCondition.SelectedValue) > 0)
                    {
                        sales_order.id_condition = (int)cbxCondition.SelectedValue;
                    }
                    else
                    {
                        toolBar.msgWarning("Condition Not Found...");
                        return;
                    }

                    if (Convert.ToInt16(cbxContract.SelectedValue) > 0)
                    {
                        sales_order.id_contract = (int)cbxContract.SelectedValue;
                    }
                    else
                    {
                        toolBar.msgWarning("Contract Not Found...");
                        return;
                    }

                    if (Convert.ToInt16(cbxCurrency.SelectedValue) > 0)
                    {
                        sales_order.id_currencyfx = (int)cbxCurrency.SelectedValue;
                    }
                    else
                    {
                        toolBar.msgWarning("Currency Not Found...");
                        return;
                    }

                    sales_order.comment = "Project -> " + project.name;

                    sales_order_detail sales_order_detail = null;

                    foreach (project_task _project_task in project_taskLIST)
                    {
                        if (_project_task.items.id_item_type == item.item_type.Task || _project_task.sales_detail == null)
                        {
                            sales_order_detail                = new sales_order_detail();
                            sales_order_detail.State          = EntityState.Added;
                            sales_order_detail.id_sales_order = sales_order.id_sales_order;
                            sales_order_detail.sales_order    = sales_order;
                            if (Convert.ToInt16(_project_task.id_item) > 0)
                            {
                                sales_order_detail.id_item = (int)_project_task.id_item;
                            }

                            sales_order_detail.item_description = _project_task.item_description;

                            if (project.is_Executable)
                            {
                                sales_order_detail.quantity = (decimal)_project_task.quantity_exe;
                            }
                            else
                            {
                                sales_order_detail.quantity = (decimal)_project_task.quantity_est;
                            }


                            if (_project_task.unit_price_vat != null)
                            {
                                sales_order_detail.UnitPrice_Vat = (decimal)_project_task.unit_price_vat;
                            }

                            sales_order_detail.id_project_task = _project_task.id_project_task;
                            _project_task.IsSelected           = false;
                            _project_task.sales_detail         = sales_order_detail;
                        }

                        if (sales_order_detail != null)
                        {
                            sales_order.sales_order_detail.Add(sales_order_detail);
                        }
                    }

                    if (sales_order.sales_order_detail.Count() > 0)
                    {
                        sales_order.State      = EntityState.Added;
                        sales_order.IsSelected = true;

                        SalesOrderDB.sales_order.Add(sales_order);
                        SalesOrderDB.SaveChanges();

                        if (Generate_Invoice)
                        {
                            SalesOrderDB.Approve();
                            sales_invoice sales_invoice = new entity.sales_invoice();

                            if (SalesOrderDB.app_document_range.Where(x => x.app_document.id_application == App.Names.SalesBudget).FirstOrDefault() != null)
                            {
                                sales_invoice.id_range = SalesOrderDB.app_document_range.Where(x => x.app_document.id_application == App.Names.SalesInvoice).FirstOrDefault().id_range;
                            }
                            sales_invoice.id_contact    = (int)project.id_contact;
                            sales_invoice.contact       = SalesOrderDB.contacts.Where(x => x.id_contact == (int)project.id_contact).FirstOrDefault();
                            sales_invoice.sales_order   = sales_order;
                            sales_invoice.id_project    = project.id_project;
                            sales_invoice.id_condition  = (int)cbxCondition.SelectedValue;
                            sales_invoice.id_contract   = (int)cbxContract.SelectedValue;
                            sales_invoice.id_currencyfx = (int)cbxCurrency.SelectedValue;
                            sales_invoice.comment       = "Project -> " + project.name;
                            sales_invoice.trans_date    = DateTime.Now;
                            sales_invoice_detail sales_invoice_detail = null;

                            foreach (project_task _project_task in project_taskLIST)
                            {
                                sales_invoice_detail                  = new sales_invoice_detail();
                                sales_invoice_detail.State            = EntityState.Added;
                                sales_invoice_detail.id_sales_invoice = sales_invoice.id_sales_invoice;
                                sales_invoice_detail.sales_invoice    = sales_invoice;
                                sales_invoice_detail.id_item          = (int)_project_task.id_item;
                                sales_invoice_detail.item_description = _project_task.item_description;

                                if (project.is_Executable)
                                {
                                    sales_invoice_detail.quantity = (decimal)_project_task.quantity_exe;
                                }
                                else
                                {
                                    sales_invoice_detail.quantity = (decimal)_project_task.quantity_est;
                                }

                                if (_project_task.unit_price_vat != null)
                                {
                                    sales_invoice_detail.UnitPrice_Vat = (decimal)_project_task.unit_price_vat;
                                }

                                sales_invoice_detail.id_project_task = _project_task.id_project_task;
                                _project_task.IsSelected             = false;

                                sales_invoice.sales_invoice_detail.Add(sales_invoice_detail);
                            }

                            sales_invoice.State      = EntityState.Added;
                            sales_invoice.IsSelected = true;
                            crm_opportunity crm_opportunity = sales_order.crm_opportunity;
                            crm_opportunity.sales_invoice.Add(sales_invoice);
                            SalesOrderDB.crm_opportunity.Attach(crm_opportunity);
                            SalesOrderDB.sales_invoice.Add(sales_invoice);
                        }
                    }
                }

                SalesOrderDB.SaveChanges();
                btnCancel_Click(null, null);
            }
        }
Beispiel #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var dic = new OpportunityBLL().GetField();
                #region  拉框赋值
                stage_id.DataTextField  = "show";
                stage_id.DataValueField = "val";
                stage_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "opportunity_stage").Value;
                stage_id.DataBind();


                resource_id.DataTextField  = "show";
                resource_id.DataValueField = "val";
                resource_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value;
                resource_id.DataBind();


                //opportunity_id.DataTextField = "name";
                //opportunity_id.DataValueField = "id";
                //opportunity_id.DataSource = new crm_opportunity_dal().FindOpHistoryByAccountId(opportunity.account_id);
                //opportunity_id.DataBind();

                loss_reason_type_id.DataTextField  = "show";
                loss_reason_type_id.DataValueField = "val";
                loss_reason_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_loss_reason_type").Value;
                loss_reason_type_id.DataBind();
                loss_reason_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // competition  competitor_id
                competitor_id.DataTextField  = "show";
                competitor_id.DataValueField = "val";
                competitor_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "competition").Value;
                competitor_id.DataBind();
                competitor_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                #endregion

                var account_id = Request.QueryString["account_id"];

                var opportunityId = Request.QueryString["id"];
                if (!string.IsNullOrEmpty(opportunityId))
                {
                    if (string.IsNullOrEmpty(account_id))
                    {
                        if (!IsPostBack)
                        {
                            opportunity_id.Enabled = false;
                        }
                    }
                    opportunity = new crm_opportunity_dal().GetOpportunityById(long.Parse(opportunityId));
                    if (opportunity != null)
                    {
                        account    = new CompanyBLL().GetCompany(opportunity.account_id);
                        account_id = account.id.ToString();
                        ownRes     = new UserResourceBLL().GetResourceById(opportunity.resource_id);
                    }
                }
                if (!string.IsNullOrEmpty(account_id))
                {
                    account = new CompanyBLL().GetCompany(long.Parse(account_id));
                    var oppoList = new crm_opportunity_dal().FindOpHistoryByAccountId(long.Parse(account_id));
                    if (oppoList != null && oppoList.Count > 0)
                    {
                        opportunity_id.DataTextField  = "name";
                        opportunity_id.DataValueField = "id";
                        opportunity_id.DataSource     = oppoList;
                        opportunity_id.DataBind();
                    }
                    else
                    {
                        Response.Write("<script>alert('该客户还没有商机!');window.close();</script>");
                    }
                    if (string.IsNullOrEmpty(opportunityId))
                    {
                        opportunity = oppoList[0];
                    }
                    opportunity_id.SelectedValue = opportunity.id.ToString();
                }
                if (opportunity == null)
                {
                    Response.End();
                }
                // 商机已经关闭,丢失提示信息
                if (!IsPostBack)
                {
                    if (opportunity.status_id == (int)OPPORTUNITY_STATUS.CLOSED)
                    {
                        Response.Write("<script>alert('商机已关闭,继续则以前创建的已确认计费项和合同不会受影响!');</script>");
                        Response.Write("<script>if(!confirm('本操作将会改变商机状态,相关的销售订单将被取消,是否继续?')){window.close();}</script>");
                    }
                }


                stage_id.SelectedValue       = opportunity.stage_id == null ? "0" : opportunity.stage_id.ToString();
                resource_id.SelectedValue    = opportunity.resource_id.ToString();
                opportunity_id.SelectedValue = opportunity.id.ToString();
                competitor_id.SelectedValue  = opportunity.competitor_id == null ? "0" : opportunity.competitor_id.ToString();
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Beispiel #12
0
        /// <summary>
        /// 插入报价
        /// </summary>
        /// <param name="quote"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Insert(crm_quote quote, long user_id)
        {
            if (quote.account_id == 0 || string.IsNullOrEmpty(quote.name) || (quote.contact_id == 0 && quote.opportunity_id == 0))
            {
                return(ERROR_CODE.PARAMS_ERROR);
            }
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {
                return(ERROR_CODE.USER_NOT_FIND);
            }



            #region 3.保存商机
            if (quote.opportunity_id == 0)  // 代表用户未选择商机,此时自动创建商机
            {
                var opportunity = new crm_opportunity()
                {
                    id                   = _dal.GetNextIdCom(),
                    name                 = quote.name,
                    account_id           = quote.account_id,
                    resource_id          = user_id,
                    stage_id             = (int)OPPORTUNITY_STAGE.NEW_CLUE, // todo 取到商机阶段中的最小值
                    status_id            = (int)OPPORTUNITY_STATUS.ACTIVE,
                    create_time          = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    projected_close_date = quote.projected_close_date,
                    use_quote            = 1,
                    one_time_cost        = 0,
                    one_time_revenue     = 0,
                    monthly_cost         = 0,
                    monthly_revenue      = 0,
                    quarterly_cost       = 0,
                    quarterly_revenue    = 0,
                    semi_annual_cost     = 0,
                    semi_annual_revenue  = 0,
                    yearly_cost          = 0,
                    yearly_revenue       = 0,
                    ext1                 = 0,
                    ext2                 = 0,
                    ext3                 = 0,
                    ext4                 = 0,
                    ext5                 = 0,
                    spread_value         = 0,
                    // create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    create_user_id = user_id,
                    update_user_id = user_id,
                };
                new crm_opportunity_dal().Insert(opportunity);
                new sys_oper_log_dal().Insert(new sys_oper_log()
                {
                    user_cate           = "用户",
                    user_id             = (int)user.id,
                    name                = user.name,
                    phone               = user.mobile == null ? "" : user.mobile,
                    oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.OPPORTUNITY,
                    oper_object_id      = opportunity.id,// 操作对象id
                    oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                    oper_description    = _dal.AddValue(opportunity),
                    remark              = "保存商机信息"
                });
                quote.opportunity_id = opportunity.id;
            }
            quote.is_primary_quote = 1;
            #endregion
            // 验证该商机下是否有报价,如果是第一个添加的报价,则设置成为主报价
            var quoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {quote.opportunity_id} ");
            if (quoteList != null && quoteList.Count > 0)
            {
                quote.is_primary_quote = null;
            }


            #region 1.保存报价
            quote.id               = _dal.GetNextIdCom();
            quote.create_time      = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote.update_time      = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote.create_user_id   = user_id;
            quote.update_user_id   = user_id;
            quote.payment_term_id  = quote.payment_term_id == 0 ? null : quote.payment_term_id;
            quote.payment_type_id  = quote.payment_type_id == 0 ? null : quote.payment_type_id;
            quote.shipping_type_id = quote.shipping_type_id == 0 ? null : quote.shipping_type_id;
            quote.tax_region_id    = quote.tax_region_id == 0 ? null : quote.tax_region_id;
            quote.quote_tmpl_id    = quote.quote_tmpl_id == 0 ? null : quote.quote_tmpl_id;
            quote.project_id       = quote.project_id == 0 ? null : quote.project_id;
            _dal.Insert(quote);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE,
                oper_object_id      = quote.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                oper_description    = _dal.AddValue(quote),
                remark              = "保存报价信息"
            });
            #endregion

            #region 2.保存通知
            #endregion

            #region 更新客户最后活动时间
            crm_account thisAccount = new CompanyBLL().GetCompany(quote.account_id);
            if (thisAccount != null)
            {
                thisAccount.last_activity_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); new CompanyBLL().EditAccount(thisAccount, user_id);
            }
            #endregion



            return(ERROR_CODE.SUCCESS);
        }