Exemple #1
0
        public static void ValidateArrayElement1()
        {
            Stopwatch sp = new Stopwatch();

            sp.Start();               //开始计时
            Random rand     = new Random();
            Int32  maxValue = 120000; //元素最大值,是一个假定值

            Int32 length = 70000;     // A,B的长度

            Int32[]   A = new Int32[length];
            Int32[]   B = new Int32[length];
            Boolean[] C = new Boolean[length];
            //随机初始化A,B数组
            for (int i = 0; i < length; i++)
            {
                A[i] = rand.Next(maxValue);
                B[i] = rand.Next(maxValue);
            }
            //循环A,验证是否存在,将C对应位置标记为true
            for (int i = 0; i < A.Length; i++)
            {
                if (B.Contains(A[i]))
                {
                    C[i] = true;
                }
            }
            sp.Stop();
            Console.WriteLine(sp.ElapsedMilliseconds);
        }
Exemple #2
0
    public static void UpdateParty()
    {
        PLAYER[] member = FF9StateSystem.Common.FF9.party.member;
        Int32[]  source = new Int32[]
        {
            3,
            4,
            5,
            6,
            9,
            10,
            11,
            12
        };
        Int32[] source2 = new Int32[]
        {
            0,
            1,
            2,
            7,
            8,
            13
        };
        Int32 num  = 0;
        Int32 num2 = 0;

        for (Int32 i = 0; i < 4; i++)
        {
            if (member[i] != null)
            {
                Byte serial_no = member[i].info.serial_no;
                if (source.Contains((Int32)serial_no))
                {
                    num++;
                }
                if (source2.Contains((Int32)serial_no))
                {
                    num2++;
                }
            }
        }
        Debug.Log(String.Concat(new Object[]
        {
            "femaleCount = ",
            num,
            ", maleCount = ",
            num2
        }));
        if (num == 4)
        {
            AchievementManager.ReportAchievement(AcheivementKey.PartyWomen, 1);
        }
        if (num2 == 4)
        {
            AchievementManager.ReportAchievement(AcheivementKey.PartyMen, 1);
        }
    }
        public JsonResult clientList()
        {
            var Id_clientes_holding = new Int32[] { 1, 3009, 2002, 4008, 10024, 3008, };

            var clientList = (from c in _db.Cliente where c.estado == "1" && !Id_clientes_holding.Contains(c.id_cliente)
                              select new { c.id_cliente, c.Nom_cor_emp }).OrderBy(x => x.Nom_cor_emp).ToList();

            return(Json(new { data = clientList, JsonRequestBehavior.AllowGet }));
        }
Exemple #4
0
        public void Native_Int32()
        {
            Int32 value = 1;
            var   arr   = new Int32[] { 2, 3 };

            if (arr.Contains(value))
            {
                throw new ArgumentException();
            }
        }
        public JsonResult GetPolicyList(string lang = null, PoliciesRequestType type = PoliciesRequestType.All)
        {
            string outputFormat = _workContext.GetContext().HttpContext.Request.Headers["OutputFormat"];
            IEnumerable <PolicyTextInfoPart> policies = _policyServices.GetPolicies(lang);

            var orchardUsersSettings    = _orchardServices.WorkContext.CurrentSite.As <UserRegistrationSettingsPart>();
            var registrationPoliciesIds = new Int32[0];

            if (orchardUsersSettings.PolicyTextReferences.Contains("{All}"))
            {
                registrationPoliciesIds = policies.Select(x => x.Id).ToArray();
            }
            else
            {
                registrationPoliciesIds = orchardUsersSettings.PolicyTextReferences.Select(x => Convert.ToInt32(x.Replace("{", "").Replace("}", ""))).ToArray();
            }

            if (type == PoliciesRequestType.ForRegistration)
            {
                policies = policies.Where(x => registrationPoliciesIds.Contains(x.Id));
            }
            else if (type == PoliciesRequestType.NotForRegistration)
            {
                policies = policies.Where(x => !registrationPoliciesIds.Contains(x.Id));
            }

            var jsonResult = "";

            if (String.Equals(outputFormat, "LMNV", StringComparison.OrdinalIgnoreCase))
            {
                jsonResult = _policyServices.PoliciesLMNVSerialization(policies);
            }
            else
            {
                jsonResult = _policyServices.PoliciesPureJsonSerialization(policies);
            }

            var serializer = new JavaScriptSerializer();

            return(Json(serializer.DeserializeObject(jsonResult), JsonRequestBehavior.AllowGet));
        }
        public void Constructor_ShouldHydrateCalculatedTerms()
        {
            // Arrange.
            var seedTerms = new Int32[] { 0, 1, 2 };

            // Act.
            var target = new SimulatedInfiniteSequence(seedTerms);

            // Assert.
            target.CalculatedTermCount.Should().Be(3);
            target.ToArray(0, 3).Should().OnlyContain(term => seedTerms.Contains(term));
        }
        public JsonResult getClients()
        {
            var Id_clientes_holding = new Int32[] { 1, 3009, 2002, 4008, 10024, 3008, };

            var client = (from c in _db.Cliente where c.estado == "1" && !Id_clientes_holding.Contains(c.id_cliente)
                          select new
            {
                id_clie = c.id_cliente,
                rut_clie = c.RUT,
                nom_clie = c.nom_emp,
                dir_clie = c.Direccion,
                nom_corto = c.Nom_cor_emp
            }).OrderBy(x => x.nom_corto).ToList();

            return(Json(new { data = client }, JsonRequestBehavior.AllowGet));
        }
Exemple #8
0
 private static void SetDefaultShader(GameObject go)
 {
     foreach (Object obj in go.transform)
     {
         Transform transform = (Transform)obj;
         if (battlebg.getBbgAttr(transform.name) == 0)
         {
             battlebg.SetMaterailShader(transform.gameObject, "PSX/BattleMap_Plus");
         }
         else if (battlebg.getBbgAttr(transform.name) == 2)
         {
             battlebg.SetMaterailShader(transform.gameObject, "PSX/BattleMap_Ground");
         }
         else if (battlebg.getBbgAttr(transform.name) == 4)
         {
             battlebg.SetMaterailShader(transform.gameObject, "PSX/BattleMap_Minus");
         }
         else if (battlebg.getBbgAttr(transform.name) == 8)
         {
             battlebg.SetMaterailShader(transform.gameObject, "PSX/BattleMap_Sky");
             Int32[] source = new Int32[]
             {
                 1,
                 2,
                 12,
                 109,
                 119,
                 68,
                 69,
                 60,
                 53,
                 49,
                 90,
                 20,
                 77,
                 125,
                 141,
                 95
             };
             if (!source.Contains(battlebg.nf_BbgNumber))
             {
                 transform.localScale = new Vector3(1.01f, 1.01f, 1.01f);
             }
         }
     }
 }
Exemple #9
0
        public static int [] RandomRaffle()
        {
            int[]  rand    = new Int32[neededNumbers];
            Random randnum = new Random();

            for (int i = 0; i < neededNumbers; i++)
            {
                //gera um número aleatório n tal que 1<=n<61
                int temp = randnum.Next(1, 61);
                //se o número aleatório já está contido no vetor
                if (rand.Contains(temp))
                {
                    //decrementa (na pratica isso serve pra manter o i inalterado, eu decremento por que ele vai ser incrementado após o continue)
                    i--;
                    //e recomeça
                    continue;
                }
                else
                {
                    rand[i] = temp;
                }
            }
            return(rand);
        }
Exemple #10
0
        public static void export2Excel(string heading1, string heading2, string heading3, DataGridView dgv, ListView lvcolumns)
        {
            Microsoft.Office.Interop.Excel._Application excel     = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel._Workbook    workbook  = excel.Workbooks.Add(Type.Missing);
            Microsoft.Office.Interop.Excel._Worksheet   worksheet = null;
            //excel.Windows.Application.ActiveWindow.DisplayGridlines = false;
            //excel.ScreenUpdating = false;
            try
            {
                worksheet = workbook.ActiveSheet;
                worksheet.Columns.ColumnWidth = 20;

                ////worksheet.Cells.HorizontalAlignment = ContentAlignment.MiddleCenter;

                worksheet.Columns.WrapText = true;
                worksheet.Cells[1, 1]      = heading1;
                worksheet.Cells[2, 1]      = heading2;
                worksheet.Cells.Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                ////worksheet.get_Range("A1", "B2").HorizontalAlignment = ContentAlignment.MiddleLeft;
                ////worksheet.get_Range("A1", "B2").Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
                worksheet.get_Range("A1", "B2").WrapText   = false;
                worksheet.get_Range("A1", "B2").Font.Bold  = true;
                worksheet.get_Range("A1", "B2").Font.Size  = 15;
                worksheet.get_Range("A1", "B2").Font.Color = Color.SeaGreen;
                string[] detail = { };
                if (heading3.Length != 0)
                {
                    detail = heading3.Split(Main.delimiter2);
                }
                int k = 3;
                for (int i = 0; i < detail.Length; i++)
                {
                    try
                    {
                        DateTime temp;
                        string   str1 = detail[i].Substring(0, detail[i].IndexOf(Main.delimiter1));
                        string   str2 = detail[i].Substring(detail[i].IndexOf(Main.delimiter1) + 1);

                        worksheet.Cells[k, 1] = str1;
                        if (DateTime.TryParse(str2, out temp))
                        {
                            worksheet.Cells[k, 2] = (Convert.ToDateTime(str2)).Date;
                        }
                        else
                        {
                            worksheet.Cells[k, 2] = str2;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("export2Excel() : ERROR in header String format");
                    }
                    k++;
                }
                worksheet.Name = heading1;
                int      col = 0;
                DateTime dt;
                //---------16/10/2017
                int[] tArray    = new Int32[dgv.ColumnCount];
                int   colCount  = 0;
                int   colNumber = 0;
                foreach (ListViewItem itemRow in lvcolumns.Items)
                {
                    if (itemRow.Checked)
                    {
                        int cNumber = dgv.Columns.IndexOf(dgv.Columns[itemRow.SubItems[3].Text]);
                        tArray[colNumber] = cNumber;
                        colNumber++;
                    }
                    colCount++;
                }
                for (int i = colNumber; i < tArray.Length; i++)
                {
                    tArray[i] = -1;
                }
                //int row = 3;
                int row = k;
                //print heading
                //Boolean flip = true;
                for (int i = 0; i < colNumber; i++)
                {
                    int cNumber = tArray[i];
                    worksheet.Cells[row, i + 1] = dgv.Columns[cNumber].HeaderText;
                    worksheet.Cells[row, i + 1].Interior.Color = Color.Orange;
                }
                row++;
                //Using Range
                int a = 0;
                object[,] data = new object[dgv.Rows.Count, dgv.Columns.Count];
                foreach (DataGridViewRow rw in dgv.Rows)
                {
                    int b = 0;
                    foreach (DataGridViewCell c in rw.Cells)
                    {
                        if (tArray.Contains(c.ColumnIndex))
                        {
                            data[a, b] = c.Value;
                            b++;
                        }
                    }
                    a++;
                }
                worksheet.Range[worksheet.Cells[row, 1], worksheet.Cells[dgv.Rows.Count + k, dgv.Columns.Count]].value = data;
                int lastrow    = worksheet.UsedRange.Rows.Count;
                int lastcolumn = worksheet.UsedRange.Columns.Count;
                Microsoft.Office.Interop.Excel.Range           rng    = worksheet.Range[worksheet.Cells[row, 1], worksheet.Cells[lastrow, lastcolumn]];
                Microsoft.Office.Interop.Excel.FormatCondition format = rng.Rows.FormatConditions.
                                                                        Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlExpression,
                                                                            Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlEqual, "=MOD(ROW(),2)=0");
                format.Interior.Color = Microsoft.Office.Interop.Excel.XlRgbColor.rgbLightGreen;
                Microsoft.Office.Interop.Excel.Range rangeData = excel.Range[worksheet.Cells[row, 1], worksheet.Cells[lastrow, lastcolumn]];
                rangeData.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                Microsoft.Office.Interop.Excel.Range rangeHead = excel.Range[worksheet.Cells[row - 1, 1], worksheet.Cells[row - 1, lastcolumn]];
                rangeHead.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                //-----------
                //excel.ScreenUpdating = false;
                SaveFileDialog saveDialog = new SaveFileDialog();
                ////saveDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
                saveDialog.Filter          = "Excel files (*.xlsx)|*.xlsx";
                saveDialog.FilterIndex     = 2;
                saveDialog.OverwritePrompt = false;
                if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    workbook.SaveAs(saveDialog.FileName);
                    MessageBox.Show("Export Successful");
                }
                workbook.Close(false, Type.Missing, Type.Missing);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Export Failed");
            }
        }
        public Robot(Matrix <double> h, Matrix <double> p, Int32[] joint_type, double[] joint_lower_limit = default(double[]), double[] joint_upper_limit = default(double[]), double[] joint_vel_limit = default(double[]), double[] joint_acc_limit = default(double[]), Matrix <double>[] m = default(Matrix <double>[]),
                     Matrix <double> r_tool = default(Matrix <double>), Vector <double> p_tool = default(Vector <double>), string[] joint_names = default(string[]), string root_link_name = default(string), string tip_link_name = default(string))
        {
            Int32[] joint_types = new Int32[] { 0, 1, 2, 3 };
            IEnumerable <Vector <double> > splicer = h.EnumerateColumns();

            bool AlmostEquals(double val1, double val2)
            {
                if (Math.Abs(val1 - val2) < (Math.Pow(10, -8)))
                {
                    return(true);
                }
                return(false);
            }

            foreach (Vector <double> column in splicer)
            {
                if (!(AlmostEquals(column.L2Norm(), 1)))
                {
                    throw new ArgumentException(String.Format("Matrix H is not Acceptable"));
                }
            }
            for (int i = 0; i < joint_type.Length; i++)
            {
                if (!(joint_types.Contains(joint_type[i])))
                {
                    throw new ArgumentException(String.Format("Joint types contains incorrect values"));
                }
            }
            if (h.RowCount != 3)
            {
                throw new ArgumentException(String.Format("Matrix H is not Acceptable"));
            }
            if (p.RowCount != 3)
            {
                throw new ArgumentException(String.Format("Matrix P is not Acceptable"));
            }
            if (h.ColumnCount + 1 != p.ColumnCount || h.ColumnCount != joint_type.Length)
            {
                throw new ArgumentException(String.Format("Matrix Dimensions are not Acceptable"));
            }
            if (joint_lower_limit != null && joint_upper_limit != null)
            {
                if (joint_lower_limit.Length != joint_type.Length || joint_type.Length != joint_upper_limit.Length)
                {
                    throw new ArgumentException(String.Format("Joint Limits not Acceptable"));
                }
                Joint_upper_limit = joint_upper_limit;
                Joint_lower_limit = joint_lower_limit;
            }
            else
            {
                Joint_lower_limit = null;
                Joint_upper_limit = null;
            }
            if (joint_vel_limit != null)
            {
                if (joint_vel_limit.Length != joint_type.Length)
                {
                    throw new ArgumentException(String.Format("Joint Velocities not Acceptable"));
                }
                Joint_vel_limit = joint_vel_limit;
            }
            else
            {
                Joint_vel_limit = null;
            }
            if (joint_acc_limit != null)
            {
                if (joint_acc_limit.Length != joint_type.Length)
                {
                    throw new ArgumentException(String.Format("Joint Accelerations not Acceptable"));
                }
                Joint_acc_limit = joint_acc_limit;
            }
            else
            {
                Joint_acc_limit = null;
            }
            if (m != null)
            {
                if (m.Length != H.ColumnCount)
                {
                    throw new ArgumentException(String.Format("Inertia Matrices not Acceptable"));
                }
                for (int i = 0; i < m.Length; i++)
                {
                    if (m[i].ColumnCount != 6 || m[i].RowCount != 6)
                    {
                        throw new ArgumentException(String.Format("Inertia Matrices not Acceptable"));
                    }
                }
                M = m;
            }
            else
            {
                M = null;
            }
            if (r_tool != null && p_tool != null)
            {
                R_tool = r_tool;
                P_tool = p_tool;
            }
            else
            {
                R_tool = null;
                P_tool = null;
            }
            H          = h;
            P          = p;
            Joint_type = joint_type;
            if (joint_names != null)
            {
                if (joint_names.Length != joint_type.Length)
                {
                    throw new ArgumentException(String.Format("Joint Names not Acceptable"));
                }
                Joint_names = joint_names;
            }
            else
            {
                Joint_names = null;
            }
            Root_link_name = root_link_name;
            Tip_link_name  = tip_link_name;
        }