示例#1
0
        public IActionResult Create([FromBody] LightItem lightItem)
        {
            if (lightItem == null)
            {
                return(BadRequest());
            }

            if (lightItem.WakeUpTime == DateTime.MinValue)
            {
                lightItem.WakeUpTime = _context.LightItems.Last().WakeUpTime;
            }

            if (lightItem.SleepTime == DateTime.MinValue)
            {
                lightItem.SleepTime = _context.LightItems.Last().SleepTime;
            }

            _context.LightItems.Add(lightItem);
            _context.SaveChanges();

            new DebugWriter().Write(string.Format("Created Lightitem with ID: {0}", lightItem.Id));

            try
            {
                _hub.Clients.All.InvokeAsync("UpdateSpecific", "MorningSun", lightItem.Command, lightItem);
            }
            catch (Exception e)
            {
                new DebugWriter().Write(e.Message);
            }

            return(CreatedAtRoute("GetLight", new { id = lightItem.Id }, lightItem));
        }
示例#2
0
    public void DeleteLight(LightItem light)
    {
        int deleteindex = orthogons.IndexOf(light);

        for (int i = deleteindex + 1; i < orthogons.Count; i++)
        {
            orthogons[i].transform.position = new Vector3(orthogons[i].transform.position.x, orthogons[i].transform.position.y + 130);
        }

        //try
        //{
        //    ((LightItem)orthogons[deleteindex - 1]).ShowMyconfig();
        //}
        //catch (Exception)
        //{


        //}
        light.transform.parent.GetComponent <RectTransform>().sizeDelta = new Vector2(light.transform.parent.GetComponent <RectTransform>().sizeDelta.x, light.transform.parent.GetComponent <RectTransform>().sizeDelta.y - 130);
        OrthogonBase temp = orthogons[deleteindex];

        orthogons.Remove(orthogons[deleteindex]);
        lineManger.LineList[((LightItem)temp).LineIndex].active = false;
        temp.Delete();
        //if (copyTemp ==light )
        //{
        //    copyTemp
        //}
        if (copyTemp != null)
        {
            copyTemp.Delete();
        }

        animCount--;
    }
示例#3
0
        public void SetUp()
        {
            _li = new LightItem
            {
                Command    = "What",
                WakeUpTime = DateTime.Parse("2018-03-02 08:00"),
                SleepTime  = DateTime.Parse("2018-03-02 20:00"),
                IsRun      = true,
                IsOn       = true
            };
            _li2 = new LightItem
            {
                Command    = "When",
                WakeUpTime = DateTime.Parse("2018-03-02 08:00"),
                SleepTime  = DateTime.Parse("2018-03-02 20:00"),
                IsRun      = true,
                IsOn       = true
            };

            _hub = Substitute.For <IHubContext <DevicesHub> >();

            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            _options = new DbContextOptionsBuilder <FwpsDbContext>()
                       .UseSqlite(_connection)
                       .EnableSensitiveDataLogging()
                       .Options;
        }
示例#4
0
        public IActionResult Update(long id, [FromBody] LightItem lightItem)
        {
            if (lightItem == null || lightItem.Id != id)
            {
                return(BadRequest());
            }

            var light = _context.LightItems.FirstOrDefault(o => o.Id == id);

            if (light == null)
            {
                return(NotFound());
            }

            light.IsRun            = lightItem.IsRun;
            light.LastModifiedDate = DateTime.Now;
            light.Command          = lightItem.Command;
            if (lightItem.SleepTime != DateTime.MinValue && lightItem.WakeUpTime != DateTime.MinValue)
            {
                light.SleepTime  = lightItem.SleepTime;
                light.WakeUpTime = lightItem.WakeUpTime;
            }

            _context.LightItems.Update(light);
            _context.SaveChanges();
            return(new NoContentResult());
        }
示例#5
0
        private void lvItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvItems.SelectedItems.Count == 0)
            {
                return;
            }
            LightItem _item = lvItems.SelectedItems[0].Tag as LightItem;

            if (_item == null)
            {
                return;
            }
            txtItemNumber.Text     = _item.ItemNumber;
            txtBatchNumber.Text    = _item.BatchNumber;
            txtSerialNumber.Text   = _item.SerialNumber;
            cboGender.SelectedItem = _item.Gender;
            cboSize.SelectedItem   = _item.Size;
            txtBrand.Text          = _item.Brand;
            txtColor.Text          = _item.Color;

            if (!_item.ExpiryDate.Equals(DateTime.MinValue))
            {
                dpExpiryDate.Value = _item.ExpiryDate;
            }
        }
示例#6
0
    private void LightRemoved(SceneLight layer)
    {
        LightItem item = lights[layer];

        lights.Remove(layer);
        item.gameObject.SetActive(false);
        Destroy(item.gameObject);
    }
        public ExtraInformation(LightItem light)
        {
            // you could get more info for your record from the db
            // but here we just get some random numbers
            var rnd = new Random();

            this._extraDoubleField  = rnd.NextDouble();
            this._extraIntegerField = rnd.Next();
        }
示例#8
0
    private void LightAdded(SceneLight light)
    {
        GameObject go = Instantiate(lightItemPrefab, contentHolder.transform);

        go.name = light.name;
        LightItem item = go.GetComponent <LightItem>();

        item.Light = light;
        item.SetToggleIcon();
        lights.Add(light, item);
    }
        /////////////////////////////////////////////////
        /// Handler function for when MorningSun turns off
        /////////////////////////////////////////////////
        private void LightIsOff(string message)
        {
            Console.WriteLine("Morning Sun: Received \"off\" from module");
            Console.WriteLine(message);
            //Send message to DB that light is now on
            LightItem lightItem = new LightItem()
            {
                Command = "TurnedOff", IsOn = false
            };

            _connector.PostItem("Light/", JsonConvert.SerializeObject(lightItem));
        }
示例#10
0
            public void UpdateLastTimeVisible(Component_Light light)
            {
                var item = GetItem(light);

                if (item == null)
                {
                    item       = new LightItem();
                    item.light = light;
                    lightItems.Add(item);
                }

                item.lastTimeVisible = Time.Current;
            }
示例#11
0
        public void Update_LightItemNull_ExpectedResult_BadRequest()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc = new LightController(_context, _hub);

                LightItem _li3 = null;

                IActionResult result = _lc.Update(4, _li3);

                Assert.IsInstanceOf <BadRequestResult>(result);
            }
        }
示例#12
0
    public LightItem Copy(LightItem item)
    {
        GameObject obj = new GameObject("CopyTemp");

        obj.SetActive(false);
        obj.AddComponent <LightItem>();
        LightItem temp = obj.GetComponent <LightItem>();

        temp.mydata    = item.mydata;
        temp.points    = item.points;
        temp.LineIndex = -1;

        return(temp);
    }
示例#13
0
        private ListViewItem GetItem(string item_number, string item_name)
        {
            LightItem _obj = Globals.Sheet2.GetItem(item_number);

            _obj.ItemName = item_name;

            ListViewItem _item = new ListViewItem(item_number);

            _item.SubItems.Add(item_name);
            _item.SubItems.Add(_obj.BatchNumber);
            _item.SubItems.Add(_obj.SerialNumber);
            _item.SubItems.Add(_obj.ExpiryDate.ToString("yyyy-MMM-dd"));
            _item.Tag = _obj;
            return(_item);
        }
示例#14
0
        public void SetUp()
        {
            _command    = "Whatcommand";
            _wakeUpTime = DateTime.Parse("2018-04-12 08:40:35");
            _sleepTime  = DateTime.Parse("2018-04-12 22:40:35");
            _isOn       = true;
            _isRun      = false;

            _uut = new LightItem()
            {
                Command    = _command,
                WakeUpTime = _wakeUpTime,
                SleepTime  = _sleepTime,
                IsOn       = _isOn,
                IsRun      = _isRun
            };
        }
示例#15
0
    // Use this for initialization
    void Start()
    {
        change      = Camera.main.GetComponent <CursorChange>();
        parent      = transform.parent.GetComponent <RectTransform>();
        parentLight = parent.GetComponent <LightItem>();
        parentLight.points.Add(GetComponent <PointItem>());
        button = GetComponent <Button>();
        button.onClick.AddListener(ShowConfig);
        ChangeIndex();

        if (isStart)
        {
            data.currentTime = parentLight.mydata.start;
        }
        else
        {
            data.currentTime = parentLight.mydata.start + transform.position.x - (parent.position.x - parent.sizeDelta.x / 2);
        }



        if (isStart || isEnd)
        {
            if (!parentLight.iscopy)
            {
                transform.position = new Vector3(GetComponent <PointItem>().transform.position.x, GetComponent <PointItem>().transform.position.y - 50);
            }
            else
            {
                transform.position = new Vector3(GetComponent <PointItem>().transform.position.x, GetComponent <PointItem>().transform.position.y);
            }
        }

        data.num = (transform.localPosition.y + 50) / 100 * Globaldata.LIGHT;
        if (data.num <= 0)
        {
            data.num = 0;
        }
        Globaldata.Global.DrawLine(parentLight.posTran);
        Globaldata.Global.SortePoint(parentLight.points);

        if (!isStart && !isEnd)
        {
            ShowConfig();
        }
    }
示例#16
0
        public IActionResult Create([FromBody] LightItem lightItem)
        {
            if (lightItem == null)
            {
                return(BadRequest());
            }



            _context.LightItems.Add(lightItem);
            _context.SaveChanges();

            Console.WriteLine("Created Lightitem with ID: {0}", lightItem.Id);


            return(CreatedAtRoute("GetLight", new { id = lightItem.Id }, lightItem));
        }
示例#17
0
    public void CopyPoint()
    {
        LightItem temp = (LightItem)Globaldata.Global.copyTemp;


        for (int i = 0; i < temp.points.Count; i++)
        {
            GameObject temp1 = Globaldata.Global.CopyLoadItemPoint(transform, "Item/PointItem", temp.points[i].transform.localPosition);
            temp1.GetComponent <PointItem>().isStart = temp.points[i].isStart;
            temp1.GetComponent <PointItem>().isEnd   = temp.points[i].isEnd;
            temp1.GetComponent <PointItem>().data    = temp.points[i].data;
            posTran.Add(temp1.transform);
        }

        Globaldata.Global.DrawLine(posTran);
        Globaldata.Global.SortePoint(points);
    }
示例#18
0
    public void RunactionLight()
    {
        while (!quite)
        {
            try
            {
                if (senddata.Length < Globaldata.Global.orthogons.Count)
                {
                    senddata = new float[Globaldata.Global.orthogons.Count];
                }
                for (int i = 0; i < Globaldata.Global.orthogons.Count; i++)
                {
                    try
                    {
                        LightItem temp = (LightItem)Globaldata.Global.orthogons[i];
                        if (temp != null && temp.isPlay)
                        {
                            if (senddata[i] != temp.getLightnum())
                            {
                                //Debug.Log(temp.mydata.index + "index" + temp.getLightnum());
                                senddata[i] = temp.getLightnum();
                                Dmxmanager.GetDmx().ChoseContralLight(temp.mydata.index, temp.getLightnum());
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                if (!Globaldata.Global.Isrun)
                {
                    for (int i = 0; i < senddata.Length; i++)
                    {
                        senddata[i] = 0;
                    }
                }

                Thread.Sleep(200);
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
            }
        }
    }
示例#19
0
    public LightItem GetLight(LightItem item)
    {
        LightItem temp = new LightItem();

        temp.mydata.start          = item.mydata.start;
        temp.mydata.end            = item.mydata.end;
        temp.mydata.duration       = item.mydata.duration;
        temp.mydata.extent         = item.mydata.extent;
        temp.mydata.audioname      = item.mydata.audioname;
        temp.mydata.audiopath      = item.mydata.audiopath;
        temp.mydata.index          = item.mydata.index;
        temp.mydata.dmxPort        = item.mydata.dmxPort;
        temp.mydata.lightDegreemin = item.mydata.lightDegreemin;
        temp.mydata.lightDegreemax = item.mydata.lightDegreemax;
        temp.mydata.videoName      = item.mydata.videoName;
        temp.mydata.videoPath      = item.mydata.videoPath;
        temp.mydata.type           = item.mydata.type;
        return(temp);
    }
        /////////////////////////////////////////////////
        /// Handler function for when the Web Api requests
        /// to set the timers on MorningSun
        /////////////////////////////////////////////////
        private static void UpdateTime(string message)
        {
            Console.WriteLine("Morning Sun: Asked to update timers");
            WebApiConnector connector = new WebApiConnector();
            //Get latest lightObject from database
            string    json  = connector.GetItem("Light/Newest");
            LightItem light = JsonConvert.DeserializeObject <LightItem>(json);

            //Find time for next sleep time
            TimeSpan timeToTurnOff = light.SleepTime - DateTime.Now;
            TimeSpan timeToTurnOn  = light.WakeUpTime - DateTime.Now;

            // Increment TimeSpan by one day until the day matches with current day
            while (timeToTurnOff < TimeSpan.Zero)
            {
                timeToTurnOff = timeToTurnOff + TimeSpan.FromDays(1);
            }

            while (timeToTurnOn < TimeSpan.Zero)
            {
                timeToTurnOn = timeToTurnOn + TimeSpan.FromDays(1);
            }

            Console.WriteLine("Morning Sun: Timer for wakeup is now in: {0} hours", timeToTurnOn.TotalHours);
            Console.WriteLine("Morning Sun: Timer for sleep is now in: {0} hours", timeToTurnOff.TotalHours);

            //Set up timer for automatic sleep
            _sleepTimer?.Dispose();
            _wakeUpTimer?.Dispose();

            _sleepTimer           = new System.Timers.Timer(timeToTurnOff.TotalMilliseconds);
            _sleepTimer.Elapsed  += Sleep;
            _sleepTimer.AutoReset = false;
            _sleepTimer.Start();


            _wakeUpTimer           = new System.Timers.Timer(timeToTurnOn.TotalMilliseconds);
            _wakeUpTimer.Elapsed  += WakeUp;
            _wakeUpTimer.AutoReset = false;
            _wakeUpTimer.Start();
        }
示例#21
0
        private void btnRecord_Click(object sender, EventArgs e)
        {
            if (lvItems.SelectedItems.Count > 0)
            {
                ListViewItem lstItem = lvItems.SelectedItems[0];
                object       tag     = lstItem.Tag;
                if (tag == null)
                {
                    return;
                }

                LightItem _item = tag as LightItem;
                if (_item == null)
                {
                    return;
                }

                bool oldSheet2Locked = Globals.Sheet2.Locked;
                Globals.Sheet2.Locked = false;

                _item.BatchNumber  = txtBatchNumber.Text;
                _item.SerialNumber = txtSerialNumber.Text;
                _item.ExpiryDate   = dpExpiryDate.Value;
                _item.Gender       = (LightItem.ItemGender)cboGender.SelectedItem;
                _item.Size         = (LightItem.ItemSize)cboSize.SelectedItem;
                _item.Brand        = txtBrand.Text;
                _item.Color        = txtColor.Text;

                Globals.Sheet2.RecordItem(_item);

                lstItem.SubItems[1].Text = _item.ItemName;
                lstItem.SubItems[2].Text = _item.BatchNumber;
                lstItem.SubItems[3].Text = _item.SerialNumber;
                lstItem.SubItems[4].Text = _item.ExpiryDate.ToString("yyyy-MMM-dd");

                Globals.Sheet2.Locked = oldSheet2Locked;
            }
        }
示例#22
0
        public override GameObject CreateGameObject(ReferenceData referenceData, Transform parent = null)
        {
            var gameObject = base.CreateGameObject(referenceData, parent);

            // Remove the Item component if it can't be picked up
            if (data.Flags.HasFlag(LightFlags.CanCarry))
            {
                LightItem.Create(gameObject, this, referenceData);
                //var ownerData = new OwnerData(referenceData.Owner, referenceData.Global, referenceData.Faction, referenceData.Rank);
                //var component = gameObject.AddComponent<LightItem>();
                //component.Initialize(this, referenceData.Quantity, ownerData, referenceData.Health == -1 ? data.Time : referenceData.Health);
            }

            // Add light component if not negative, as negative lights are not supported in Unity
            if (!data.Flags.HasFlag(LightFlags.Negative))
            {
                AddLightComponent(gameObject);
            }

            // Add sound component if needed
            sound?.AddAudioSource(gameObject, true, true);

            return(gameObject);
        }
        ////!!!!
        ///// <summary>Computes the convex hull of a polygon, in clockwise order in a Y-up
        ///// coordinate system (counterclockwise in a Y-down coordinate system).</summary>
        ///// <remarks>Uses the Monotone Chain algorithm, a.k.a. Andrew's Algorithm.</remarks>
        //public static List<Vector2> ComputeConvexHull( IEnumerable<Vector2> points )
        //{
        //	var list = new List<Vector2>( points );
        //	return ComputeConvexHull( list, true );
        //}
        //public static List<Vector2> ComputeConvexHull( List<Vector2> points, bool sortInPlace )//= false )
        //{
        //	if( !sortInPlace )
        //		points = new List<Vector2>( points );

        //	points.Sort( ( a, b ) => a.X == b.X ? a.Y.CompareTo( b.Y ) : ( a.X > b.X ? 1 : -1 ) );

        //	// Importantly, DList provides O(1) insertion at beginning and end
        //	List<Vector2> hull = new List<Vector2>();
        //	int L = 0, U = 0; // size of lower and upper hulls

        //	// Builds a hull such that the output polygon starts at the leftmost point.
        //	for( int i = points.Count - 1; i >= 0; i-- )
        //	{
        //		Vector2 p = points[ i ], p1;

        //		// build lower hull (at end of output list)
        //		while( L >= 2 && ( p1 = hull.Last ).Sub( hull[ hull.Count - 2 ] ).Cross( p.Sub( p1 ) ) >= 0 )
        //		{
        //			hull.RemoveAt( hull.Count - 1 );
        //			L--;
        //		}
        //		hull.PushLast( p );
        //		L++;

        //		// build upper hull (at beginning of output list)
        //		while( U >= 2 && ( p1 = hull.First ).Sub( hull[ 1 ] ).Cross( p.Sub( p1 ) ) <= 0 )
        //		{
        //			hull.RemoveAt( 0 );
        //			U--;
        //		}
        //		if( U != 0 ) // share the point added above, except in the first iteration
        //			hull.PushFirst( p );
        //		U++;
        //	}
        //	hull.RemoveAt( hull.Count - 1 );
        //	return hull;
        //}

        void GetDirectionalLightShadowsCascadeHullPlanes(ViewportRenderingContext context, LightItem lightItem, int cascadeIndex, out Plane[] planes, out Bounds bounds)
        {
            var cornerPoints = GetDirectionalLightShadowsCameraCornerPoints(context, cascadeIndex);

            var inputVertices = new List <Vector3>(cornerPoints.Length * 2);

            inputVertices.AddRange(cornerPoints);
            foreach (var point in cornerPoints)
            {
                inputVertices.Add(point - lightItem.data.Rotation.ToQuaternion().GetForward() * ShadowDirectionalLightExtrusionDistance);
            }

            var projectMatrix   = lightItem.data.Rotation.ToQuaternion().GetInverse();
            var unprojectMatrix = lightItem.data.Rotation.ToQuaternion();

            var projected2D = new Vector2[cornerPoints.Length];

            for (int n = 0; n < projected2D.Length; n++)
            {
                var p = projectMatrix * cornerPoints[n];
                projected2D[n] = new Vector2(p.Y, p.Z);
            }

            var convex = MathAlgorithms.GetConvexByPoints(projected2D);

            var planesList = new List <Plane>(convex.Count);

            for (int n = 0; n < convex.Count; n++)
            {
                var p1 = convex[n];
                var p2 = convex[(n + 1) % convex.Count];

                var u1 = unprojectMatrix * new Vector3(0, p1.X, p1.Y);
                var u2 = unprojectMatrix * new Vector3(0, p2.X, p2.Y);
                var u3 = unprojectMatrix * new Vector3(1, p2.X, p2.Y);

                planesList.Add(Plane.FromPoints(u1, u3, u2));
            }
            planes = planesList.ToArray();

            ////!!!!глючит
            //ConvexHullAlgorithm.Create( inputVertices.ToArray(), out planes );

            bounds = Bounds.Cleared;
            foreach (var p in inputVertices)
            {
                bounds.Add(p);
            }
        }
示例#24
0
    public void LastPause()
    {
        //List<float> times = new List<float>();
        //List<int> indexs = new List<int>();

        //for (int i = 0; i < pauseTime.Count; i++)
        //{
        //    if (pauseTime[i].time * 100 < Globaldata.global.second)
        //    {
        //        float temptime = Globaldata.global.second - pauseTime[i].time * 100;
        //        times.Add(temptime);
        //        indexs.Add(i);
        //    }

        //}
        //if (times.Count > 0)
        //{
        //    float min = times.Min();
        //    int index = times.IndexOf(min);
        //    TimerManager.Manager.ResultPause();
        //    for (int i = index; i < pauseTime.Count; i++)
        //    {
        //        pauseTime[i].StartPlay();
        //    }

        //    Globaldata.global.second = pauseTime[index].time * 100;
        //}
        if (Current != -1 && isPause && Current != 0)
        {
            //if (isPause)
            //{
            StorePause();
            TimerManager.Manager.ResultPause();

            for (int i = Current; i < pauseTime.Count; i++)
            {
                pauseTime[i].StartPlay();
            }
            Current -= 1;
            if (Current < 0)
            {
                Current = 0;
            }
            Globaldata.global.second = pauseTime[Current].time * 100;



            for (int i = 0; i < orthogons.Count; i++)
            {
                try
                {
                    LightItem temp = (LightItem)orthogons[i];
                    if (temp.points[0].data.currentTime >= Globaldata.global.second)
                    {
                        temp.StartPlay();
                    }
                    else if (temp.points[temp.points.Count - 1].data.currentTime > Globaldata.global.second)
                    {
                        int index = -1;
                        for (int j = 0; j < temp.points.Count; j++)
                        {
                            if (temp.points[j].data.currentTime > Globaldata.global.second)
                            {
                                index = j;
                                break;
                            }
                        }
                        temp.StartPlay(index);
                    }
                }
                catch (Exception)
                {
                    AudioItem temp = (AudioItem)orthogons[i];
                    if (temp.mydata.start + temp.nowPlayTime * 100 >= Globaldata.global.second)
                    {
                        temp.StartPlay();
                    }
                }
            }
            for (int i = 0; i < orthogons.Count; i++)
            {
                try
                {
                    ((LightItem)orthogons[i]).mydata = Clone(pauseTime[Current].pauseData[i].data);
                    LightItem light = ((LightItem)orthogons[i]);
                    if (pauseTime[Current].pauseData.Count > 0)
                    {
                        light.lightDegree = Clone(pauseTime[Current].pauseData[i].currentLight);
                    }
                }
                catch (Exception)
                {
                    ((AudioItem)orthogons[i]).mydata = Clone(pauseTime[Current].pauseData[i].data);
                    AudioItem audio = ((AudioItem)orthogons[i]);
                    if (pauseTime[Current].pauseData.Count > 0)
                    {
                        float time = pauseTime[Current].pauseData[i].currentLight;
                        audio.nowPlayTime = Clone(time);
                    }
                }
            }

            //}
            //else
            //{
            //    TimerManager.Manager.ResultPause();
            //    for (int i = Current; i < pauseTime.Count; i++)
            //    {
            //        pauseTime[i].StartPlay();
            //    }

            //    Globaldata.global.second = pauseTime[Current].time * 100;
            //    Current -= 1;
            //}
        }
    }
        private void PopulateData(Excel.Worksheet ws)
        {
            Sheet1 sh1 = Globals.Sheet1;
            Sheet2 sh2 = Globals.Sheet2;

            int year_from = int.Parse(txtFromYear.Text);
            int year_to   = int.Parse(txtToYear.Text);

            int    SaleAmountColIndex        = 0;
            int    CostOfSalesAmountColIndex = 0;
            int    GrossProfitColIndex       = 0;
            int    ProfitMarginColIndex      = 0;
            double TotalSaleAmount           = 0;
            double TotalCostOfSalesAmount    = 0;
            double TotalGrossProfit          = 0;
            double TotalProfitMargin         = 0;

            bool oldSh2Locked = sh2.Locked;

            sh2.Locked = false;

            Excel.Range cell = null;

            Accountant _obj = AccountantPool.Instance.CurrentAccountant;

            IList <Item> items = _obj.ItemMgr.List();

            int columnIndex = 1;
            int rowOffset   = 7;

            if (chkItemNumber.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Item #";
                cell.Font.Bold = true;
            }
            if (chkItemName.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Name";
                cell.Font.Bold = true;
            }
            if (chkBatchNumber.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Batch #";
                cell.Font.Bold = true;
            }
            if (chkSerialNumber.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Serial #";
                cell.Font.Bold = true;
            }
            if (chkExpiryDate.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Expiry Date";
                cell.Font.Bold = true;
            }
            if (chkBrand.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Brand";
                cell.Font.Bold = true;
            }
            if (chkColor.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Color";
                cell.Font.Bold = true;
            }
            if (chkGender.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Gender";
                cell.Font.Bold = true;
            }
            if (chkSize.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Size";
                cell.Font.Bold = true;
            }

            if (chkSaleAmount.Checked)
            {
                SaleAmountColIndex = columnIndex;
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Sales";
                cell.Font.Bold = true;
            }
            if (chkCostOfSalesAmount.Checked)
            {
                CostOfSalesAmountColIndex = columnIndex;
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Cost of Sales";
                cell.Font.Bold = true;
            }
            if (chkGrossProfit.Checked)
            {
                GrossProfitColIndex = columnIndex;
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Gross Profit";
                cell.Font.Bold = true;
            }
            if (chkProfitMargin.Checked)
            {
                ProfitMarginColIndex = columnIndex;
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "%Margin";
                cell.Font.Bold = true;
            }

            if (chkUnitsSold.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Units Sold";
                cell.Font.Bold = true;
            }
            if (chkAverageCost.Checked)
            {
                cell           = ws.Cells[rowOffset, columnIndex++] as Excel.Range;
                cell.Value2    = "Average Cost";
                cell.Font.Bold = true;
            }

            int totalColCount = columnIndex - 1;

            ws.get_Range(ws.Cells[1, 1], ws.Cells[1, totalColCount]).Merge(missing);
            cell = ws.Cells[1, 1] as Excel.Range;
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell.Font.Bold           = true;
            cell.Value2 = _obj.DataFileInformationMgr.Company.CompanyName;

            ws.get_Range(ws.Cells[2, 1], ws.Cells[2, totalColCount]).Merge(missing);
            cell = ws.Cells[2, 1] as Excel.Range;
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell.Font.Italic         = true;
            cell.RowHeight           = 48;
            cell.Value2 = _obj.DataFileInformationMgr.Company.Address;

            ws.get_Range(ws.Cells[3, 1], ws.Cells[3, totalColCount]).Merge(missing);
            cell = ws.Cells[3, 1] as Excel.Range;
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell.Font.Bold           = true;
            cell.Value2 = "Analyse Sales [Item]";

            ws.get_Range(ws.Cells[4, 1], ws.Cells[4, totalColCount]).Merge(missing);
            cell = ws.Cells[4, 1] as Excel.Range;
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            cell.Font.Bold           = true;
            if (year_from == year_to)
            {
                cell.Value2 = string.Format("{0}", year_from);
            }
            else
            {
                cell.Value2 = string.Format("{0} - {1}", year_from, year_to);
            }

            ws.get_Range(ws.Cells[5, 1], ws.Cells[5, totalColCount]).Merge(missing);
            cell = ws.Cells[5, 1] as Excel.Range;
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
            cell.Font.Bold           = true;
            cell.Value2 = DateTime.Now.ToString("yyyy-MMM-dd");

            ws.get_Range(ws.Cells[6, 1], ws.Cells[6, totalColCount]).Merge(missing);
            cell = ws.Cells[6, 1] as Excel.Range;
            cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
            cell.Font.Bold           = true;
            cell.Value2 = DateTime.Now.ToString("HH:mm:ss");

            rowOffset++;

            int itemCount = items.Count;

            for (int i = 0; i < itemCount; ++i)
            {
                columnIndex = 1;

                LightItem _lght = sh2.GetItem(items[i].ItemNumber);

                if (chkItemNumber.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = items[i].ItemNumber;
                }

                if (chkItemName.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = items[i].ItemName;
                }

                if (chkBatchNumber.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _lght.BatchNumber;
                }

                if (chkSerialNumber.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _lght.SerialNumber;
                }

                if (chkExpiryDate.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _lght.ExpiryDate.ToString("yyyy-MMM-dd");
                }

                if (chkBrand.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _lght.Brand;
                }

                if (chkColor.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _lght.Color;
                }

                if (chkGender.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _lght.Gender.ToString();
                }

                if (chkSize.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _lght.Size.ToString();
                }



                List <ItemSalesHistory> itemSalesHistories = _obj.ItemSalesHistoryMgr.List(items[i].ItemID, year_from, year_to);
                double SaleAmount = 0;
                if (chkSaleAmount.Checked || chkGrossProfit.Checked)
                {
                    foreach (ItemSalesHistory history in itemSalesHistories)
                    {
                        SaleAmount += history.SaleAmount;
                    }

                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _obj.CurrencyMgr.Format(SaleAmount);
                }

                double CostOfSalesAmount = 0;
                if (chkCostOfSalesAmount.Checked || chkGrossProfit.Checked)
                {
                    foreach (ItemSalesHistory history in itemSalesHistories)
                    {
                        CostOfSalesAmount += history.CostOfSalesAmount;
                    }

                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _obj.CurrencyMgr.Format(CostOfSalesAmount);
                }

                double GrossProfit = SaleAmount - CostOfSalesAmount;
                if (chkGrossProfit.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _obj.CurrencyMgr.Format(GrossProfit);
                }

                double margin = 0;
                if (SaleAmount != 0)
                {
                    margin = GrossProfit * 100 / SaleAmount;
                }
                if (chkProfitMargin.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _obj.CurrencyMgr.FormatPercent(margin);
                }

                if (chkUnitsSold.Checked)
                {
                    double UnitsSold = 0;
                    foreach (ItemSalesHistory history in itemSalesHistories)
                    {
                        UnitsSold += history.UnitsSold;
                    }

                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = UnitsSold.ToString();
                }

                if (chkAverageCost.Checked)
                {
                    cell        = ws.Cells[i + rowOffset, columnIndex++] as Excel.Range;
                    cell.Value2 = _obj.CurrencyMgr.Format(items[i].PositiveAverageCost);
                }

                TotalSaleAmount        += SaleAmount;
                TotalProfitMargin      += margin;
                TotalGrossProfit       += GrossProfit;
                TotalCostOfSalesAmount += CostOfSalesAmount;
            }

            if (chkSaleAmount.Checked)
            {
                cell        = ws.Cells[itemCount + rowOffset, SaleAmountColIndex] as Excel.Range;
                cell.Value2 = _obj.CurrencyMgr.Format(TotalSaleAmount / itemCount);
            }
            if (chkCostOfSalesAmount.Checked)
            {
                cell        = ws.Cells[itemCount + rowOffset, CostOfSalesAmountColIndex] as Excel.Range;
                cell.Value2 = _obj.CurrencyMgr.Format(TotalCostOfSalesAmount / itemCount);
            }
            if (chkProfitMargin.Checked)
            {
                cell        = ws.Cells[itemCount + rowOffset, ProfitMarginColIndex] as Excel.Range;
                cell.Value2 = _obj.CurrencyMgr.FormatPercent(TotalProfitMargin / itemCount);
            }
            if (chkGrossProfit.Checked)
            {
                cell        = ws.Cells[itemCount + rowOffset, GrossProfitColIndex] as Excel.Range;
                cell.Value2 = _obj.CurrencyMgr.Format(TotalGrossProfit / itemCount);
            }


            ws.UsedRange.Columns.AutoFit();

            sh2.Locked = oldSh2Locked;
        }