示例#1
0
文件: Main.cs 项目: radtek/InfoPos
        public Result Txn500099(ClientInfo ci, RequestInfo ri, DbConnections db, ref Log lg)
        {
            Result res = new Result();
            string sql;

            DataTable saleDB;
            DataTable valueDB;
            Hashtable ids = new Hashtable();
            RebateID  id;
            int       index = 0;

            try
            {
                gRebateMaster.Init(db);
                gRebateFormula.Init(db);

                #region [ Гэрээний дугаар орж ирсэн бол rebate ID-г авах ]

                long contractno = Static.ToLong(ri.ReceivedParam[0]);
                if (contractno != 0)
                {
                    sql = "select rebateid, loyalid, pointid from ContractMain where contractNo=:1";
                    res = db.ExecuteQuery("core", sql, enumCommandType.SELECT, "Txn50000x", contractno);

                    if (res.ResultNo != 0)
                    {
                        return(res);
                    }
                    if (res.Data == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Гэрээний мэдээлэл уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0] == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Гэрээний мэдээлэл уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0].Rows.Count > 0)
                    {
                        id          = new RebateID();
                        id.rebateid = Static.ToLong(res.Data.Tables[0].Rows[0][0]);
                        id.loyalid  = Static.ToLong(res.Data.Tables[0].Rows[0][1]);
                        id.pointid  = Static.ToLong(res.Data.Tables[0].Rows[0][2]);
                        ids.Add(index, id);
                    }
                }
                #endregion
                #region [ Захиалгын дугаар орж ирсэн бол rebate ID-г авах ]
                long orderno = Static.ToLong(ri.ReceivedParam[1]);
                if (orderno != 0)
                {
                    sql = "select rebateid, loyalid, pointid from Orders where OrderNo=:1";
                    res = db.ExecuteQuery("core", sql, enumCommandType.SELECT, "Txn50000x", orderno);

                    if (res.ResultNo != 0)
                    {
                        return(res);
                    }
                    if (res.Data == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Захиалгын уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0] == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Захиалгын уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0].Rows.Count > 0)
                    {
                        id          = new RebateID();
                        id.rebateid = Static.ToLong(res.Data.Tables[0].Rows[0][0]);
                        id.loyalid  = Static.ToLong(res.Data.Tables[0].Rows[0][1]);
                        id.pointid  = Static.ToLong(res.Data.Tables[0].Rows[0][2]);
                        ids.Add(index, id);
                    }
                }
                #endregion
                #region [ Хүсэлт дээрээс Rebate ID-г авах ]
                if (contractno == 0 && orderno == 0)
                {
                    long rebateid = 0;
                    long loyalid  = 0;
                    long pointid  = 0;
                    if (Static.ToLong(ri.ReceivedParam[2]) != 0)
                    {
                        rebateid = Static.ToLong(ri.ReceivedParam[2]);
                    }
                    else
                    {
                        rebateid = 0;
                    }

                    if (Static.ToLong(ri.ReceivedParam[3]) != 0)
                    {
                        loyalid = Static.ToLong(ri.ReceivedParam[3]);
                    }
                    else
                    {
                        loyalid = 0;
                    }
                    if (Static.ToLong(ri.ReceivedParam[4]) != 0)
                    {
                        pointid = Static.ToLong(ri.ReceivedParam[4]);
                    }
                    else
                    {
                        pointid = 0;
                    }
                    if (!(loyalid == 0 && loyalid == 0 && pointid == 0))
                    {
                        id          = new RebateID();
                        id.rebateid = rebateid;
                        id.loyalid  = loyalid;
                        id.pointid  = pointid;
                        ids.Add(index, id);
                    }
                }
                #endregion
                #region [ Sale, Value DataTable-уудыг унших ]

                if (ri.ReceivedParam[5] != null)
                {
                    DataTable productlist = (DataTable)ri.ReceivedParam[5];
                    saleDB = new DataTable();
                    saleDB.Columns.Add("CUSTOMERNO", typeof(long));
                    saleDB.Columns.Add("PRODTYPE", typeof(int));
                    saleDB.Columns.Add("PRODNO", typeof(string));
                    saleDB.Columns.Add("PRICE", typeof(decimal));
                    saleDB.Columns.Add("QUANTITY", typeof(long));
                    saleDB.Columns.Add("SALESPRICE", typeof(decimal));

                    foreach (DataRow dr in productlist.Rows)
                    {
                        if (Static.ToInt(dr["FLAG"]) != 3)
                        {
                            DataRow drow = saleDB.NewRow();
                            drow["CUSTOMERNO"] = dr["CUSTOMERNO"];
                            drow["PRODTYPE"]   = dr["PRODTYPE"];
                            drow["PRODNO"]     = dr["PRODCODE"];
                            drow["PRICE"]      = dr["PRICE"];
                            drow["QUANTITY"]   = dr["QUANTITY"];
                            drow["SALESPRICE"] = dr["PRICE"];
                            saleDB.Rows.Add(drow);
                        }
                    }
                }
                else
                {
                    res.ResultNo   = 9110015;
                    res.ResultDesc = "Борлуулалтын мэдээлэл орж ирээгүй байна.";
                    return(res);
                }
                if (ri.ReceivedParam[6] != null)
                {
                    valueDB = (DataTable)(ri.ReceivedParam[6]);
                }
                else
                {
                    res.ResultNo   = 9110015;
                    res.ResultDesc = "Нэмэлт мэдээлэл орж ирээгүй байна.";
                    return(res);
                }
                #endregion
                #region [ Rebate ID байхгүй бол Macro ажиллуулж RebateID-нуудыг авах ]
                if (ids.Count == 0)
                {
                    tmptrankey = InsertTmpDatas(db, saleDB, valueDB);
                    if (tmptrankey == 0)
                    {
                        res.ResultNo   = 1;
                        res.ResultDesc = "Temporary бааз руу оруулахад алдаа гарлаа";
                        return(res);
                    }

                    foreach (object obj in gRebateFormula.RebateFormulas.Keys)
                    {
                        RebateFormula formula = (RebateFormula)gRebateFormula.RebateFormulas[obj];
                        if (formula.Status == 0 && (formula.BeginDate <= DateTime.Now && formula.EndDate >= DateTime.Now))
                        {
                            sql = formula.SQL;
                            if (sql.Trim() != "")
                            {
                                object[] resdb = ProcessPLSQL(db, tmptrankey, formula.SQL);
                                if (resdb == null)
                                {
                                    res.ResultNo   = 1;
                                    res.ResultDesc = "PL SQL-ийг ажиллуулахад алдаа гарлаа";
                                    return(res);
                                }
                                if (resdb.Count() > 0)
                                {
                                    if (Static.ToLong(resdb[0]) != 0 || Static.ToLong(resdb[1]) != 0 || Static.ToLong(resdb[2]) != 0)
                                    {
                                        id          = new RebateID();
                                        id.rebateid = Static.ToLong(resdb[0]);
                                        id.loyalid  = Static.ToLong(resdb[1]);
                                        id.pointid  = Static.ToLong(resdb[2]);
                                        ids.Add(index, id);
                                        index += 1;
                                    }
                                }
                                else
                                {
                                    //id = new RebateID();
                                    //id.rebateid = 0;
                                    //id.loyalid = 0;
                                    //id.pointid = 0;
                                    //ids.Add(index, id);
                                    //index += 1;
                                }
                            }
                        }
                    }
                }
                #endregion

                #region [ Calculation ]
                object[] resData = new object[ids.Count];
                object[] oneresData;
                index = 0;
                foreach (object obj in ids.Keys)
                {
                    id             = (RebateID)ids[obj];
                    oneresData     = GetCalcResult(id, saleDB);
                    resData[index] = oneresData;
                    index++;
                }
                res.Param    = resData;
                res.ResultNo = 0;
                #endregion

                return(res);
            }
            catch (Exception ex)
            {
                res.ResultNo   = 9110002;
                res.ResultDesc = "Програм руу нэвтрэхэд алдаа гарлаа" + ex.Message;
                EServ.Shared.Static.WriteToLogFile("Error.log", ex.Message + ex.Source + ex.StackTrace);
                return(res);
            }
            return(res);
        }
示例#2
0
文件: Main.cs 项目: radtek/InfoPos
        private object[] GetCalcResult(RebateID id, DataTable saleDB)
        {
            object[]  res = new object[7];
            DataRow   row;
            decimal   saleprice = 0;
            int       saletype  = 0;
            decimal   point     = 0;
            DataTable loyalDB   = null;

            //saleDB нь хөнгөлсөн дүн оруулах баганатайгаа хамт ирэх ёстой гэж үзнэ.
            //
            #region [ Хөнгөлөлт ]
            if (id.rebateid != 0)
            {
                // Хөнгөлсөн бараанууд дээр үнэ тогтоох процесс
                for (int i = 0; i < saleDB.Rows.Count; i++)
                {
                    row       = saleDB.Rows[i];
                    saleprice = GetPrice(row, gRebateMaster, id.rebateid);
                    saleDB.Rows[i]["SALESPRICE"] = saleprice;
                }
                // Үлдсэн бараанууд дээр нийтэд нь үнэ тогтоох
                saleprice = GetOtherPrice(gRebateMaster, id.rebateid, ref saletype);
                if (saleprice != 0)
                {
                    for (int i = 0; i < saleDB.Rows.Count; i++)
                    {
                        row = saleDB.Rows[i];
                        if (!ProductInRebate(gRebateMaster, id.rebateid, Static.ToInt(row["ProdType"]), Static.ToStr(row["ProdNo"])))
                        {
                            switch (saletype)
                            {
                            case 1:
                                saleDB.Rows[i]["SALESPRICE"] = Math.Round(Static.ToDecimal(saleDB.Rows[i]["Price"]) * saleprice / 100);
                                break;

                            case 0:
                                saleDB.Rows[i]["SALESPRICE"] = saleprice;
                                break;
                            }
                        }
                    }
                }
            }
            res[0] = saleDB;
            #endregion

            #region [ Урамшуулал ]
            if (id.loyalid != 0)
            {
                loyalDB = GetLoyalProduts(id.loyalid);
            }
            #endregion

            #region [ Оноо ]
            point = 0;
            if (id.pointid != 0)
            {
                RebateMaster rebate;
                foreach (Object obj in gRebateMaster.RebateMasters.Keys)
                {
                    rebate = (RebateMaster)gRebateMaster.RebateMasters[obj];
                    if (rebate.MasterID == id.pointid && rebate.MasterType == 2)
                    {
                        point = rebate.CalcAmount;
                    }
                }
            }
            #endregion

            res[0] = saleDB.Copy();
            res[1] = loyalDB;
            res[2] = point;
            res[3] = id.rebateid;
            res[4] = id.loyalid;
            res[5] = id.pointid;
            res[6] = RebateName;

            return(res);
        }