C# 输出日期为SQL / ISO字符串YYYY-MM-DD

Console.WriteLine(DateTime.Now.GetDateTimeFormats()[5]);

C# Direktzugriff auf Comos

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Plt;
using Comos.Wrapper;

namespace Comos.Visualization
{
    public class ForTesting
    {
        public void testEins(Comos.Wrapper.Task task)
        {
            //Task t = task.GetSubTasks()[0];
            //t.GetPlannedWorkingHours(null,System.DateTime.Now);
            //t.setWorkloadXmlString(Tools.WorkloadXmlGenerator.generateSampleWorkloadXml());
            //Tools.ProjectTraversalAlgorithms.preOrderTaskTraversal(task, setWorkloadXmlString);

            
           /* WrapperDebug.WriteLine("testEins");
            WrapperDebug.WriteLine((task.GetComosObject().XMLString));
            task.GetComosObject().XMLString = "<ueberWrapper>ddd</ueberWrapper>";
            task.GetComosObject().spec("SYS.US").XMLString = "<ueberWrapper>ddd</ueberWrapper>";
            //WrapperDebug.WriteLine(task.GetComosObject()
            * */
        }


        public static void calledWhenStarting(IComosDDevice device, IComosDWorkset workset)
        {
            Task task = new Task(device.SystemUID());
            Tools.ProjectTraversalAlgorithms.preOrderTaskTraversal(task, visitorGetPlannedWhTest);
           

            //listAllUsers(workset);
        }

        private static void listAllUsers(IComosDWorkset workset)
        {
            IComosDOwnCollection allUsers = workset.GetAllUsers();
            new ComosObjectCollection<User>(allUsers);

            for (int i = 1; i <= allUsers.Count(); i++)
            {
             //   IComosDSpecification spec = (IComosDSpecification)allUsers.Item(i);
             //   IComosBaseObject lObject = (IComosBaseObject)spec.LinkObject;
                //ODER
                IComosDDevice dev = (IComosDDevice)allUsers.Item(i);
                Console.WriteLine(dev.Name);
               

            }

            //return new ComosObjectCollection<User>(resourceColl);
            /*
            foreach (IComosDDevice device in allUsers)
            {
                Wrapper.User user = (User)ComosObjectFactory.Create(device);
                //WrapperDebug(user.Name);
            }
            */
        }

        public void setWorkload(Comos.Wrapper.Task task)
        {
            //task.GetSp
        }


        /// <summary>
        /// Used as visitor (GoF Pattern) for ProjectTraversalAlgorithms.preOrderTaskTraversal 
        /// </summary>
        /// <param name="t"></param>
        private void myTaskVisitor(Task t)
        {
            WrapperDebug.WriteLine(t.Name);
            Tools.WorkloadXmlGenerator.generateSampleWorkloadXml();
        }

        /// <summary>
        /// Used as visitor (GoF Pattern) for ProjectTraversalAlgorithms.preOrderTaskTraversal 
        /// </summary>
        /// <param name="t"></param>
        private void setWorkloadXmlString(Task t)
        {
            t.setWorkloadXmlString(Tools.WorkloadXmlGenerator.generateSampleWorkloadXml());         
        }

        /// <summary>
        /// Testing Method
        /// Prints the planned workload for Users and all days of this task
        /// </summary>
        /// <param name="t">the Task that is visited</param>
        private static void visitorGetPlannedWhTest(Task t)
        {
            foreach (User u in t.OwnResources)
            {
                WrapperDebug.WriteLine("planned workload: "+ t.Name + ":  "+ u.Name +" worked " + t.GetPlannedWorkingHours(u,new DateTime(2008,5,8,10,10,10,10)) +" hours on " +" on " + (new DateTime(2008,5,8,10,10,10,10)).ToShortDateString());
            }

        }


        public static void comosDirekt(){



              IComosDWorkset workset = null;

         Comos.Wrapper.Task wrapperProject = null;
         Comos.Wrapper.Task wrapperTask = null;
         Comos.Wrapper.Task wrapperWorkflow = null;
         Comos.Wrapper.Milestone wrapperMilestone = null;
         Comos.Wrapper.Role wrapperRole = null;
         Comos.Wrapper.User wrapperUser = null;
         Comos.Wrapper.Document wrapperDocument = null;        
         Comos.Wrapper.Task wrapperProcess = null;
         Comos.Wrapper.ComosObjectSubstitute wrapperComosObjectSubstitute = null;

        #region Konstanten

         const string PATH_TO_DB = @"Z:\ComosT6\T6DevelopmentDB\Comos.mdb";
         const string PROJECT_NAME = "SO1";
         const int WORKING_LAYER_ID = 236;
         const string PROJECT_UID = "A2C2073YIX";
                
         const string A_PROJECT_UID = "A2C2073YIX";
         const string A_TASK_UID = "A2C7452SBI";
         const string A_MASSTASK_UID = "A2C745JQBI";
         const string A_WORKFLOW_UID = "A2C745XCBI";
         const string A_ACTIVITY_UID = "A2C7460EBI";
         const string A_MILESTONE_UID = "A2C745BOBI";
         const string A_ROLE_UID = "A2AUCH72UG";
         const string A_USER_UID = "A20SMTGIAY";
         const string A_DOCUMENT_UID = "A2C5IWJ2HF";
         const string A_NO_WRAPPER_UID = "A2B93VJ0TN";

        #endregion




   
            IComosDProject project = null;

            System.Console.WriteLine("Connecting to COMOS DB...");

            string username = System.Environment.UserName.ToUpper();
            /*
            try
            {
                System.Console.WriteLine("Getting Comos object...");
                workset = (IComosDWorkset)Marshal.GetActiveObject("Comos");
            }
            catch
            {
                System.Console.WriteLine("Getting Comos Object failed.");
            }
            */
            if (workset == null)
            {
                System.Console.WriteLine("Trying to create Comos object...");
                workset = (IComosDWorkset)Activator.CreateInstance(Type.GetTypeFromProgID("Comos"));
            }

            if (workset != null)
            {
                if (workset.Init("", "", PATH_TO_DB))  //TODO: Handle Exceptions
                {
                    if (workset.GetAllUsers() != null)
                    {

                        if (workset.GetAllUsers().Item(username) != null)
                        {
                            workset.SetCurrentUser(workset.GetAllUsers().Item(username));
                            System.Console.WriteLine("User " + username + " logged in.");

                        }
                        else
                        {
                            throw new ApplicationException("User " + username + " doesn't exist.");
                        }

                        if (workset.GetAllProjects() != null)
                        {
                            if (workset.GetAllProjects().ItemExist(PROJECT_NAME))
                            {
                                project = (IComosDProject)workset.GetAllProjects().Item(PROJECT_NAME);
                                System.Console.WriteLine("Setting working layer to " + WORKING_LAYER_ID + ".");
                                IComosDWorkingOverlay workingLayer = project.GetWorkingOverlay(WORKING_LAYER_ID);
                                if (workingLayer == null)
                                {
                                    throw new ApplicationException("The working layer with ID " + WORKING_LAYER_ID + " doesn't exist.");
                                }
                                workset.SetCurrentProject(project);
                                project.CurrentWorkingOverlay = workingLayer;
                                //IComosDCDevice projectDevice = project.GetCDeviceBySystemFullname(projectFullName, 1);
                                //IComosDDevice projectDevice = project.GetObjectByPathFullName(
                                IComosDDevice projectDevice = workset.LoadObjectByType(ComosSystemTypes.SystemTypeDevice, PROJECT_UID) as IComosDDevice;

                                if (projectDevice == null)
                                {
                                    throw new ApplicationException("Getting the project device failed. Check the device UID string.");
                                }
                                System.Console.WriteLine("Project " + PROJECT_NAME + " loaded.");

                                Comos.Wrapper.ComosObjectSubstitute.Init(workset);
                                wrapperTask = new Comos.Wrapper.Task("A2CDOWCK78");
                                Console.WriteLine(wrapperTask.Name);
                            }
                            else
                            {
                                throw new ApplicationException("ProjectName " + PROJECT_NAME + " doesn't exist.");
                            }
                        }
                    }
                }
            }
            else
            {
                throw new ApplicationException("Workset is still NULL!");
            }
        }
    
    }
}

C# NUnit测试

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Comos.Visualization.UnitTesting
{
    [TestFixture]
    public class WorkloadTesting
    {
        [Test]
        public void initTest()
        {           
            Assert.IsNotNull(new Object());
        }
    }
}

C# 访问Visual Studio资源

Console.WriteLine(TestingGround.Properties.Resources.workload);

C# 饼干

public class Cookie
    {
        public Cookie()
        {

        }

        public void Set(string name, string value, DateTime expires)
        {
            HttpCookie cookie = new HttpCookie(name);
            cookie.Value = value;
            cookie.Expires = expires;
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        public string Get(string name)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[name];

            if (cookie != null)
                return cookie.Value;
            else
                return String.Empty;
        }

        public void Delete(string name)
        {
            HttpCookie cookie = new HttpCookie(name);
            cookie.Expires = DateTime.Now.AddDays(-1d);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
    }

C# 是文件夹

/// <summary>
/// Returns true if the given file path is a folder.
/// </summary>
/// <param name="Path">File path</param>
/// <returns>True if a folder</returns>
public bool IsFolder(string path)
{
    return ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory);
}

C# 多视图

<asp:MultiView ID="mvName" runat="server" ActiveViewIndex="0">
<asp:View ID="vwName1" runat="server">

</asp:View>
<asp:View ID="vwName2" runat="server">

</asp:View>
</asp:MultiView>

C# LinkBut​​ton的

<asp:LinkButton ID="lbSortTitle" runat="server" Text="Title" OnClick="lbSort_Click" />

<asp:LinkButton ID="lblSortAuthor" runat="server" Text="Author" OnClick="lbSort_Click" />

    protected void lbSort_Click(object sender, EventArgs e)
    {
        LinkButton lb = (LinkButton)sender;
        lb.Text
    }

C# 中继器

<asp:Repeater ID="rptItems" runat="server" OnItemDataBound="rptItems_DataBound">
	<ItemTemplate>
			<div><asp:Literal runat="server" ID="litName" /></div>
			<div><%# Eval("Name") %></div>
	</ItemTemplate>
	<AlternatingItemTemplate>
	</AlternatingItemTemplate>
</asp:Repeater>

protected void Page_Load(object sender, EventArgs e)
{
	DateTable dtResults = new DataTable();
	
	//limit results
	if (intMaxResults > 0) 
	{
		PagedDataSource objPds = new PagedDataSource();
		objPds.DataSource = dtResults.DefaultView;
		objPds.AllowPaging = true;
		objPds.PageSize = mintMaxItems;
		objPds.CurrentPageIndex = 0;
		rptItems.DataSource = objPds;
		rptItems.DataBind();
	}
	//bind all results
	else
	{
		rptItems.DataSource = dtResults;
		rptItems.DataBind();
	}
}

protected void rptItems_DataBound(Object Sender, RepeaterItemEventArgs e)
{
	if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
	{
	        DataRowView drv = (DataRowView)e.Item.DataItem;

		string strName = drv["Name"].ToString();

		((Literal)e.Item.FindControl("litName")).Text = strName;
	}
}

C# 字符串格式

Short Time: {0:t}

Short Date: {0:d}

Currency: {0:c}