Example #1
0
        public void DeleteRoute(RateRouting r)
        {
            var rlist = GetRateRoutings(elt_account_number, customer_org_num, rate_type);
            var route = from c in rlist where c.ID == r.ID select c;

            rlist.Remove(route.First());
            PesisteRateRouting(rlist);
            //rlist = GetRateRoutings(elt_account_number, customer_org_num, rate_type);
            //SaveRateInfo(rlist);
        }
Example #2
0
        public void DeleteRate(int rateId, int routeid)
        {
            RateRouting route = GetRouting(routeid);
            var         rate  = (from c in route.Rates where c.RateID == rateId select c).First();

            route.Rates.Remove(rate);
            var rlist = GetRateRoutings(elt_account_number, customer_org_num, rate_type);

            PesisteRateRouting(rlist);
        }
Example #3
0
        private void PersistModelForAgentBuyingRate(RateTable model)
        {
            RateManagementBL   bl     = new RateManagementBL();
            List <RateRouting> routes = bl.GetRateRoutings(int.Parse(GetCurrentELTUser().elt_account_number), model.AgentAccount, Convert.ToInt32(RateType.AgentBuyingRate));

            foreach (var view_route in model.RateRoutes)
            {
                RateRouting routing = new RateRouting();
                int         count   = (from c in routes where c.ID == view_route.RouteID select c).Count();
                if (count > 0)
                {
                    routing = (from c in routes where c.ID == view_route.RouteID select c).Single();
                }
                else
                {
                    routes.Add(routing);
                }
                foreach (var view_row in view_route.Rows)
                {
                    var rate = (from c in routing.Rates where c.RateID == view_row.Id select c).Single();
                    routing.agent_org_account_number = int.Parse(view_route.HeaderRow.RateHeaderColumns[0].Value);
                    routing.AgentOrgName             = view_route.HeaderRow.RateHeaderColumns[0].Text;
                    routing.Origin = view_route.HeaderRow.RateHeaderColumns[1].Text;
                    routing.Dest   = view_route.HeaderRow.RateHeaderColumns[2].Text;
                    routing.Unit   = view_route.HeaderRow.RateHeaderColumns[3].Value;

                    for (int i = 0; i < view_row.Columns.Count; i++)
                    {
                        if (view_row.Columns[i].WeightBreakValueTag == "CarrierCode")
                        {
                            rate.CarrierCode = view_row.Columns[i].Value;
                        }

                        if (view_row.Columns[i].WeightBreakValueTag == "Share")
                        {
                            rate.Share = view_row.Columns[i].Text;
                        }

                        if (i >= AppConstants.AgentBuyingRateDataColumnStartIndex)
                        {
                            for (int k = 0; k < rate.RateDefinitionColums.Count; k++)
                            {
                                if (view_row.Columns[i].WeightBreakValueTag == rate.RateDefinitionColums[k].Value)
                                {
                                    rate.RateDefinitionColums[k].Rate = view_row.Columns[i].Text;
                                }
                            }
                        }
                    }
                }
            }


            bl.PesisteRateRouting(routes);
        }
Example #4
0
        public void UpdateRate(Rate rate, int routeid)
        {
            RateRouting route        = GetRouting(routeid);
            var         rateOriginal = (from c in route.Rates where c.RateID == rate.RateID select c).First();

            route.Rates.Remove(rateOriginal);
            route.Rates.Add(rate);
            var rlist = GetRateRoutings(elt_account_number, customer_org_num, rate_type);

            PesisteRateRouting(rlist);
        }
Example #5
0
        private static Rate GenerateEmptyRateAndCreateHeaderText(RateRouting routing, RateHeaderRow HeaderRow)
        {
            Rate emptyRate = new Rate();

            emptyRate.CarrierCode = "-1";
            int ratedef_id         = 1;
            RateDefinitionColum wb = new RateDefinitionColum();
            int HeaderStartIndex   = 0;
            int HeaderRowCount     = 0;

            if (HeaderRow.RateType == RateType.CustomerSellingRate)
            {
                HeaderStartIndex = AppConstants.CustomerSellingRateHeaderColumnStartIndex;
                HeaderRowCount   = AppConstants.CustomerSellingRateDataColumnCount;
            }
            else if (HeaderRow.RateType == RateType.AirLineBuyingRate)
            {
                HeaderStartIndex = AppConstants.AirLineBuyingRateHeaderColumnStartIndex;
                HeaderRowCount   = AppConstants.AirLineBuyingRateDataColumnCount;
            }
            else if (HeaderRow.RateType == RateType.AgentBuyingRate)
            {
                HeaderStartIndex = AppConstants.AgentBuyingRateHeaderColumnStartIndex;
                HeaderRowCount   = AppConstants.AgentBuyingRateDataColumnCount;
            }
            else if (HeaderRow.RateType == RateType.IATARate)
            {
                HeaderStartIndex = AppConstants.IATARateHeaderColumnStartIndex;
                HeaderRowCount   = AppConstants.CustomerSellingRateDataColumnCount;
            }
            bool ValueExist = false;

            for (int i = HeaderStartIndex; i < HeaderRowCount - 1; i++)
            {
                if (HeaderRow.RateHeaderColumns[i].Value != null && HeaderRow.RateHeaderColumns[i].Value != "")
                {
                    ValueExist = true;
                    emptyRate.RateDefinitionColums.Add(new RateDefinitionColum()
                    {
                        Value = HeaderRow.RateHeaderColumns[i].Value, Rate = "", ID = ratedef_id++
                    });
                }
            }
            if (!ValueExist)
            {
                throw new Exception("At least one Rate Break shoud exist!");
            }
            RateManagementBL bl = new RateManagementBL();

            bl.GetNextRateID();
            emptyRate.RateID  = bl.GetNextRateID();
            emptyRate.RouteID = routing.ID;
            return(emptyRate);
        }
Example #6
0
        public void InsertRate(Rate rate, int routeid)
        {
            RateRouting route = GetRouting(routeid);
            int         newId = GetNextRateID();

            rate.RateID = newId;
            route.Rates.Add(rate);
            var rlist    = GetRateRoutings(elt_account_number, customer_org_num, rate_type);
            var original = (from c in rlist where c.ID == routeid select c).First();

            rlist.Remove(original);
            rlist.Add(route);
            PesisteRateRouting(rlist);
        }
Example #7
0
        public int InsertRoute(RateRouting routinng)
        {
            var rlist = GetRateRoutings(elt_account_number, customer_org_num, rate_type);

            if (rlist.Count > 0)
            {
                routinng.ID = rlist.OrderByDescending(r => r.ID).First().ID + 1;
            }
            else
            {
                routinng.ID = 1;
            }
            rlist.Add(routinng);
            PesisteRateRouting(rlist);
            return(routinng.ID);
        }
Example #8
0
        private DataTable GetDynamicColumsForRoute(RateRouting route, DataTable dt)
        {
            var rate = route.Rates[0];

            if (rate.RateDefinitionColums != null)
            {
                RefreshWeightBreakText(rate.RateDefinitionColums);
            }
            rate.RateDefinitionColums = rate.RateDefinitionColums.OrderBy(r => r.Value).ToList();
            foreach (var brk in rate.RateDefinitionColums)
            {
                dt.Columns.Add(brk.Value, typeof(string)).Caption = brk.Caption;
            }

            return(dt);
        }
Example #9
0
        private static void PrepRouteList(List <RateRouting> list, List <FlattenRateItem> rawList)
        {
            var           o       = rawList.GroupBy(c => c.origin_port).Select(group => group.First());
            List <string> Origins = (from c in o select c.origin_port).ToList();

            var           d       = rawList.GroupBy(c => c.dest_port).Select(group => group.First());
            List <string> Destins = (from c in d select c.dest_port).ToList();

            var           u     = rawList.GroupBy(c => c.kg_lb).Select(group => group.First());
            List <string> Units = (from c in u select c.kg_lb).ToList();

            foreach (var unit in Units)
            {
                foreach (var s1 in Origins)
                {
                    foreach (var s2 in Destins)
                    {
                        RateRouting route = new RateRouting();

                        route.elt_account_number = rawList[0].elt_account_number;
                        route.Origin             = s1;
                        route.Dest = s2;
                        route.Unit = unit;
                        list.Add(route);
                    }
                }
            }


            foreach (var route in list)
            {
                var customer = from c in rawList where c.customer_no > 0 && c.dest_port == route.Dest && c.origin_port == route.Origin && c.kg_lb == route.Unit select c;
                if (customer.Count() > 0)
                {
                    route.customer_org_account_number = customer.First().customer_no;
                    route.CustomerOrgName             = customer.First().dba_name;
                }
                var agent = from c in rawList where c.customer_no > 0 && c.dest_port == route.Dest && c.origin_port == route.Origin && c.kg_lb == route.Unit select c;
                if (agent.Count() > 0)
                {
                    route.agent_org_account_number = agent.First().customer_no;
                    route.AgentOrgName             = agent.First().dba_name;
                }
            }
        }
Example #10
0
        public ActionResult RateTable(RateTable model)
        {
            RateManagementBL bl = new RateManagementBL();

            if (!string.IsNullOrEmpty(Request["ActionParam"]))
            {
                if (Convert.ToString(Request["ActionParam"]) == "SaveAll")
                {
                    List <RateRouting> rRList = null;
                    PersistViewModel(model);
                    rRList = bl.GetRateRoutingFromSession((int)model.RateType);
                    bool isValid = true;

                    //모든 타입에 저장시 보아야할 것은 중복된  carrier code 이다.
                    foreach (var r in rRList)
                    {
                        foreach (var rate in r.Rates)
                        {
                            var count = from c in r.Rates where c.CarrierCode == rate.CarrierCode select c;
                            if (count.Count() > 1)
                            {
                                MsgText = "Duplicate Carrier Code exists. Save failed!";
                                isValid = false;
                                break;
                            }
                        }
                        if (!isValid)
                        {
                            break;
                        }
                    }



                    if (isValid)
                    {
                        MsgText = "Rate table saved successfully!";
                        try
                        {
                            bl.SaveRateInfo(rRList);
                        }
                        catch (Exception ex)
                        {
                            MsgText = ex.Message;
                        }
                    }
                }
                if (Convert.ToString(Request["ActionParam"]) == "CancelAddRoute")
                {
                    model.ClientAction = "CancelAddRoute";
                }
                if (Convert.ToString(Request["ActionParam"]) == "SaveRoute")
                {
                    var HeaderRow = model.RateRoutes[0].HeaderRow;
                    SetMissingDropDownTextForRateHeaderRow(HeaderRow);
                    RateRouting routing = new RateRouting();
                    try
                    {
                        GetNewRouteInfoFromView(model, routing);
                        bl.InsertRoute(routing);
                    }
                    catch (Exception ex)
                    {
                        model.ShouldOpenAddRoute = true;
                        MsgText = ex.Message;
                    }
                }
                if (Convert.ToString(Request["ActionParam"]) == "AddRoute")
                {
                    PersistViewModel(model);
                    int       newRateId = bl.GetNewRoutingID();
                    RateRoute RateRoute = new RateRoute(model.RateType)
                    {
                        RouteID = newRateId, Mode = RateRouteMode.Add
                    };
                    model.RateRoutes.Clear();
                    model.RateRoutes.Add(RateRoute);
                    model.ClientAction = "AddRoute";
                    return(View(model));
                }
                if (Convert.ToString(Request["ActionParam"]) == "AddCarrier")
                {
                    PersistViewModel(model);
                    int       AddCarrierRouteID = model.AddCarrierRouteID;
                    RateRoute target            = (from c in model.RateRoutes where c.RouteID == AddCarrierRouteID select c).Single();
                    var       routing           = bl.GetRouting(target.RouteID);
                    var       emptyRate         = GenerateEmptyRateAndCreateHeaderText(routing, target.HeaderRow);
                    routing.Rates.Add(emptyRate);
                }
                if (Convert.ToString(Request["ActionParam"]) == "DeleteCarrier")
                {
                    PersistViewModel(model);
                    int       DeleteCarrierRouteID = model.DeleteCarrierRouteID;
                    int       DeleteCarrierID      = model.DeleteCarrierID;
                    RateRoute target_route         = (from c in model.RateRoutes where c.RouteID == DeleteCarrierRouteID select c).Single();
                    RateRow   target_row           = (from c in target_route.Rows where c.Id == DeleteCarrierID select c).Single();
                    var       routing = bl.GetRouting(target_route.RouteID);
                    if (routing.Rates.Count == 1)
                    {
                        bl.DeleteRoute(routing);
                    }
                    else
                    {
                        var rate = (from c in routing.Rates where c.RateID == DeleteCarrierID select c).Single();
                        bl.DeleteRate(DeleteCarrierID, DeleteCarrierRouteID);
                    }
                }
            }

            SetVariablesToSession(model);

            if (model.IsInit == "Init")
            {
                model.IsInit = "";
                bl.ClearRateRoutings();
            }

            if (model.RateType == RateType.CustomerSellingRate)
            {
                GetCustomerSellingRate(model);
            }
            if (model.RateType == RateType.AgentBuyingRate)
            {
                GetAgentBuyingRate(model);
            }
            if (model.RateType == RateType.IATARate)
            {
                GetIATARate(model);
            }
            if (model.RateType == RateType.AirLineBuyingRate)
            {
                GetAirlineBuyingRate(model);
            }

            model.Message = MsgText;

            return(View(model));
        }
Example #11
0
        private void GetNewRouteInfoFromView(RateTable model, RateRouting routing)
        {
            RateManagementBL bl = new RateManagementBL();
            var rRList          = bl.GetRateRoutingFromSession((int)model.RateType);

            RateHeaderRow HeaderRow = model.RateRoutes[0].HeaderRow;

            try
            {
                if (model.RateType == RateType.CustomerSellingRate)
                {
                    //Check if 같은 customer , 같은 destination 그리고 같은 orgin 그리고 같은 Unit 이 있는지 보라.

                    routing.customer_org_account_number = int.Parse(HeaderRow.RateHeaderColumns[0].Value);
                    routing.CustomerOrgName             = HeaderRow.RateHeaderColumns[0].Text;
                    routing.Origin             = HeaderRow.RateHeaderColumns[1].Value;
                    routing.Dest               = HeaderRow.RateHeaderColumns[2].Value;
                    routing.elt_account_number = int.Parse(GetCurrentELTUser().elt_account_number);
                    routing.Unit               = HeaderRow.RateHeaderColumns[3].Value;
                    routing.UnitText           = HeaderRow.RateHeaderColumns[3].Text;

                    if (routing.Origin == routing.Dest)
                    {
                        throw new Exception("Destination cannot be the same as the Origination!");
                    }

                    var exists = from c in rRList where c.Dest == routing.Dest && c.Origin == routing.Dest && c.Unit == routing.Unit && c.customer_org_account_number == routing.customer_org_account_number select c;
                    if (exists.Count() > 0)
                    {
                        throw new Exception("Same route exists!");
                    }

                    Rate emptyRate = GenerateEmptyRateAndCreateHeaderText(routing, HeaderRow);
                    routing.Rates.Add(emptyRate);
                }
                if (model.RateType == RateType.AgentBuyingRate)
                {
                    //Check if 같은 agent, 같은 destination 그리고 같은 orgin 그리고 같은 Unit 이 있는지 보라.
                    routing.agent_org_account_number = int.Parse(HeaderRow.RateHeaderColumns[0].Value);
                    routing.AgentOrgName             = HeaderRow.RateHeaderColumns[0].Text;
                    routing.Origin             = HeaderRow.RateHeaderColumns[1].Value;
                    routing.Dest               = HeaderRow.RateHeaderColumns[2].Value;
                    routing.elt_account_number = int.Parse(GetCurrentELTUser().elt_account_number);
                    routing.Unit               = HeaderRow.RateHeaderColumns[3].Value;
                    routing.UnitText           = HeaderRow.RateHeaderColumns[3].Text;
                    var exists = from c in rRList where c.Dest == routing.Dest && c.Origin == routing.Dest && c.Unit == routing.Unit && c.agent_org_account_number == routing.agent_org_account_number select c;
                    if (exists.Count() > 0)
                    {
                        throw new Exception("Same route exists!");
                    }
                    if (routing.Origin == routing.Dest)
                    {
                        throw new Exception("Destination cannot be the same as the Origination!");
                    }
                    Rate emptyRate = GenerateEmptyRateAndCreateHeaderText(routing, HeaderRow);
                    routing.Rates.Add(emptyRate);
                }

                if (model.RateType == RateType.AirLineBuyingRate)
                {
                    //Check if  같은 destination 그리고 같은 orgin 그리고 같은 Unit 이 있는지 보라.

                    routing.Origin             = HeaderRow.RateHeaderColumns[0].Value;
                    routing.Dest               = HeaderRow.RateHeaderColumns[1].Value;
                    routing.elt_account_number = int.Parse(GetCurrentELTUser().elt_account_number);
                    routing.Unit               = HeaderRow.RateHeaderColumns[2].Value;
                    routing.UnitText           = HeaderRow.RateHeaderColumns[2].Text;

                    var exists = from c in rRList where c.Dest == routing.Dest && c.Origin == routing.Dest && c.Unit == routing.Unit select c;
                    if (exists.Count() > 0)
                    {
                        throw new Exception("Same route exists!");
                    }
                    if (routing.Origin == routing.Dest)
                    {
                        throw new Exception("Destination cannot be the same as the Origination!");
                    }

                    Rate emptyRate = GenerateEmptyRateAndCreateHeaderText(routing, HeaderRow);
                    routing.Rates.Add(emptyRate);
                }

                if (model.RateType == RateType.IATARate)
                {
                    //Check if  같은 destination 그리고 같은 orgin 그리고 같은 Unit 이 있는지 보라.
                    routing.Origin             = HeaderRow.RateHeaderColumns[0].Value;
                    routing.Dest               = HeaderRow.RateHeaderColumns[1].Value;
                    routing.elt_account_number = int.Parse(GetCurrentELTUser().elt_account_number);
                    routing.Unit               = HeaderRow.RateHeaderColumns[2].Value;
                    routing.UnitText           = HeaderRow.RateHeaderColumns[2].Text;

                    var exists = from c in rRList where c.Dest == routing.Dest && c.Origin == routing.Dest && c.Unit == routing.Unit select c;
                    if (exists.Count() > 0)
                    {
                        throw new Exception("Same route exists!");
                    }
                    if (routing.Origin == routing.Dest)
                    {
                        throw new Exception("Destination cannot be the same as the Origination!");
                    }
                    Rate emptyRate = GenerateEmptyRateAndCreateHeaderText(routing, HeaderRow);
                    routing.Rates.Add(emptyRate);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #12
0
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        if (ComboOrigin.SelectedItem == null)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "nonum", "alert('Origin is required!');", true);
            return;
        }
        if (ComboDestination.SelectedItem == null)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "nonum", "alert('Destination is required!');", true);
            return;
        }
        RateRouting routing = new RateRouting();

        routing.Origin   = ComboOrigin.SelectedItem.Value.ToString();
        routing.Dest     = ComboDestination.SelectedItem.Value.ToString();
        routing.Unit     = ddlUnit.SelectedItem.Value.ToString();
        routing.UnitText = ddlUnit.SelectedItem.Text.ToString();
        List <RateRouting> list = bl.GetRateRoutings(elt_account_number, customer_org_num, rate_type);
        var exist = from c in list where c.Origin == routing.Origin && c.Dest == routing.Dest && c.Unit == routing.Unit select c;

        if (exist.Count() > 0)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "reroute", "alert('Route already exists!');", true);
            return;
        }
        if (rate_type == 4)
        {
            routing.customer_org_account_number = int.Parse(ComboCompanyList.SelectedItem.Value.ToString());
            ClientProfileBL ClientProfileBL = new ClientProfileBL();
            routing.CustomerOrgName = ClientProfileBL.GetClient(elt_account_number, routing.customer_org_account_number).dba_name;
        }
        else if (rate_type == 1)
        {
            routing.agent_org_account_number = int.Parse(ComboCompanyList.SelectedItem.Value.ToString());
            ClientProfileBL ClientProfileBL = new ClientProfileBL();
            routing.AgentOrgName = ClientProfileBL.GetClient(elt_account_number, routing.customer_org_account_number).dba_name;
        }

        Rate defaultRate = new Rate();

        defaultRate.RateID  = bl.GetNextRateID();
        defaultRate.RouteID = routing.ID;
        defaultRate.Share   = "0";
        routing.Rates.Add(defaultRate);
        int null_count = 0;

        for (int i = 0; i < GridBreak.Rows.Count; i++)
        {
            var text = ((TextBox)GridBreak.Rows[i].Cells[1].Controls[1]).Text;
            if (string.IsNullOrEmpty(text))
            {
                null_count++;
                continue;
            }
            if (!ELT.COMMON.Util.IsNumber(text))
            {
                List <RateDefinitionColum> wb = ExtractBreaksFromGridBreak();
                GridBreak.DataSource = wb;
                GridBreak.DataBind();
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "nonum", "alert('Range should be a number!');", true);

                return;
            }
            defaultRate.RateDefinitionColums.Add(new RateDefinitionColum()
            {
                ID = i, Caption = text, Value = text
            });
        }
        if (null_count == GridBreak.Rows.Count)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "noelem", "alert('At least one Range Start is required!');", true);
            return;
        }
        var count = defaultRate.RateDefinitionColums.GroupBy(w => w.Caption).Select(x => x.Count() > 1).FirstOrDefault();

        if (count)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "samenum", "alert('You cannot have duplicate Ranage Start!');", true);
            return;
        }
        int routeid = bl.InsertRoute(routing);

        GridMaster.DataBind();
        ResetGridBreak();
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "CloseNewRouting", "CloseNewRouting();", true);
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "SaveBreaks", "redirectBack();", true);
    }