自动编号字段

时间:2017-12-20 10:13:03

标签: c# plugins dynamics-crm dynamics-crm-online

我想在帐户实体上创建自动编号插件。如果帐户名称= Morgan Stanely然后帐号= MORG00001,如果帐户名= Morgan Motor,则帐号= MORG00002,如果帐户名是ABC Tech,则帐号应为ABCT00001。

如果已经存在具有相同4个字符的accont名称,则AccountNumber将获取帐户名称的前4个字符并附加4个零并将其递增1。

方法名称: newaccounname()

我写的代码:

    public void updaterecord(EntityCollection account)
    {
        int totalrecords = account.Entities.Count;
        string[] name = new string[totalrecords];
        string append = "0000";
        string value = "1";
        int number = int.Parse(value);

        string[] accountnumber = new string[totalrecords];
        for (int i = 0; i < totalrecords; i++)
        {
            ////check the accountname and take first 4 characters from it.

            name[i] = account.Entities[i].Attributes["name"].ToString();
            string partialstring = name[i].Substring(0, 4);
            if (entity.Attributes.Contains("accountnumber") == false)
            {

                string anumber = string.Concat(partialstring, append, value);
                entity.Attributes.Add("accountnumber", anumber.ToString());
            }
            else if (entity.Attributes.Contains("accountnumber") == true)
            {
                newaccountname(account);
            }

        }
    }
    public void newaccountname(EntityCollection account)
    {
        int totalrecords = account.Entities.Count;
        string[] name = new string[totalrecords];
        string[] accountnumber = new string[totalrecords];
        for (int i = 0; i < totalrecords; i++)
        {
            string accountNumber = entity.GetAttributeValue<string>("accountnumber");
            accountnumber[i] = account.Entities[i].Attributes["accountnumber"].ToString();
            name[i] = account.Entities[i].Attributes["name"].ToString();
            string paccountnumber = accountnumber[i].Substring(0, 4);
            if(name[i] == paccountnumber)
            {
                //
            }
        }


    }
}

1 个答案:

答案 0 :(得分:1)

好吧,我不会为你解决测验:),但这里有一些提示

  • 您需要先从名称中删除所有空格

  • 你需要比较你所拥有的名字中的4个字符(之后 仅删除空间中的每个字符的4个字符 列出所以当你比较“MORG00001”和“摩根汽车”时你就是 将“MORG”与“MORG”进行比较,在这种情况下给你的确是

  • 计算您拥有的“MORG”数量和新帐户 [First4Letters] [0000] [COUNT + 1]