Пример #1
0
        public JsonResult BatchCommand(string PageName, string CommandName, inputParameter[][][][] records)
        {
            Page         Info = PDAL.FindPage(PageName);
            BatchCommand B    = null;

            for (int i = 0; i < Info.BatchCommands.Count; i++)
            {
                if (Info.BatchCommands[i].name == CommandName)
                {
                    B = Info.BatchCommands[i];
                    break;
                }
            }
            ScallerResult Res = new ScallerResult();

            PDALSect.AccessResult DoAccess = PDALSect.GetCheckPer(B.PerKey, PageName, null);
            if (DoAccess == PDALSect.AccessResult.AccessDenied)
            {
                Res.code    = 403;
                Res.Message = "شما اجازه دسترسی به این قسمت را ندارید";
                return(Json(Res));
            }
            if (DoAccess == PDALSect.AccessResult.ReLogin)
            {
                Res.code    = 401;
                Res.Message = "نیاز به ورود مجدد می باشد";
                return(Json(Res));
            }
            SqlConnection Con = PDAL.GetConnection();

            if (Con.State != ConnectionState.Open)
            {
                Con.Open();
            }
            string[] scallerValues = new string[records.Length];


            SqlTransaction Tran = Con.BeginTransaction();

            try
            {
                for (int k = 0; k < records.Length; k++)
                {
                    Command Com = B.Commands[k];
                    List <inputParameter> initValues = new List <inputParameter>();

                    for (int q = 0; q < Com.Parameters.Count; q++)
                    {
                        if (Com.Parameters[q].sourceType == "Session")
                        {
                            inputParameter ix = new inputParameter();
                            ix.key   = Com.Parameters[q].name;
                            ix.value = PDAL.GetSession(Com.Parameters[q].sourceTypeParameter);

                            initValues.Add(ix);
                        }
                        if (Com.Parameters[q].sourceType == "SpecValue")
                        {
                            inputParameter ix = new inputParameter();
                            ix.key   = Com.Parameters[q].name;
                            ix.value = PDAL.GetSpecValue(Com.Parameters[q].sourceTypeParameter);

                            initValues.Add(ix);
                        }
                        if (Com.Parameters[q].sourceType == "ScallerValues")
                        {
                            inputParameter ix = new inputParameter();
                            ix.key   = Com.Parameters[q].name;
                            ix.value = scallerValues[int.Parse(Com.Parameters[q].sourceTypeParameter)];

                            initValues.Add(ix);
                        }
                    }


                    for (int k2 = 0; k2 < records[k].Length; k2++)
                    {
                        PDAL.ConvertValuesBatch(Info, Com, records[k][k2]);

                        if (Com.DBCommand.StartsWith("$") == false)
                        {
                            for (int k3 = 1; k3 < records[k][k2].Length; k3++)
                            {
                                List <inputParameter> par = new List <inputParameter>();
                                par.AddRange(initValues);
                                par.AddRange(records[k][k2][k3]);
                                scallerValues[k] = PDAL.ExecScallerWithConnection(ref Com.DBCommand, par, Con, Tran);
                            }
                        }
                        else
                        {
                            for (int k3 = 1; k3 < records[k][k2].Length; k3++)
                            {
                                List <inputParameter> par = new List <inputParameter>();
                                par.AddRange(initValues);
                                par.AddRange(records[k][k2][k3]);
                                scallerValues[k] = CustomScaler(Com.DBCommand, PageName, par.ToArray());
                            }
                        }
                    }
                }
                Tran.Commit();
                Res.code    = 0;
                Res.Message = "با موفقیت انجام شد";
            }
            catch (Exception ex)
            {
                Tran.Rollback();
                Res.code    = 500;
                Res.Message = "خطا در انجام عملیات" + "<br />" + ex.Message;
            }

            if (Con.State != ConnectionState.Closed)
            {
                Con.Close();
            }
            return(Json(Res));
            //ConvertNullToEmpty(Parameters);

            //PDAL.ConvertValues(Info, Parameters);
            //ScallerResult Res = new ScallerResult();
            //bool DoAccess = PDALSect.GetCheckPer(Info.PerKey, PageName, Parameters);
            //PDAL.InitServerSideParametersForSubmit(PageName, ref Parameters);
            //string error = PDAL.ValidateAndSetDefaultValue(Info, Parameters);

            //if (DoAccess == false)
            //{
            //    Res.code = 403;
            //    Res.Message = "شما اجازه دسترسی به این قسمت را ندارید";
            //    return Json(Res);

            //}
            //if (error != "")
            //{
            //    Res.code = 200;
            //    Res.Message = error;
            //    return Json(Res);

            //}


            //try
            //{


            //    Res.code = 0;
            //    Res.Message = "با موفقیت انجام شد";
            //    Res.retrunValue = PDAL.ExecScaller(Info.DBCommand, PDAL.SkipParameters(Info, Parameters));

            //}
            //catch (SqlException Ex)
            //{

            //    Res.code = 300;
            //    Res.Message = "خطایی رخ داد:" + Ex.ErrorCode.ToString() + ":" + Ex.Message;

            //}
            //catch (Exception Ex)
            //{
            //    Res.code = 500;
            //    Res.Message = "خطایی رخ داد:" + Ex.Message;

            //}
            //return Json(Res);
        }