Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Internal Supply Chain, Visibility via 200 plus 3D Chart Reports - Part II

, 8 Oct 2009 CPOL
This article focuses on internal supply chain management systems visibility via chart reports, and provides assessment apparatus to manage and monitor activities spawned during business processes, hence paves the way for timely and precise business decisions.
InventorySys.zip
InventorySys
ISCMS.csproj.user
Warehouse
Control
RawMaterial
Properties
Settings.settings
Procurement
Control
Plant
Control
Order
Control
MasterFiles
Transporter
Control
Supplier
Control
Order
Control
List
Invoice
obj
Release
build.force
InventorySys.Control.ScheduleItem.resources
InventorySys.csproj.GenerateResource.Cache
InventorySys.Form1.resources
ISCMS.Control.About.resources
ISCMS.Control.ActivityBalloon.resources
ISCMS.Control.BarItem.resources
ISCMS.Control.GoodsBalloon.resources
ISCMS.Control.JobBalloon.resources
ISCMS.Control.JobStatusBalloon.resources
ISCMS.Control.RMInTransitBalloon.resources
ISCMS.Control.VacantBalloon.resources
ISCMS.csproj.GenerateResource.Cache
ISCMS.Dialog.Job.resources
ISCMS.Dialog.Rates.resources
ISCMS.Dialog.Transaction.resources
ISCMS.exe
ISCMS.MainForm.resources
ISCMS.pdb
ISCMS.Properties.Resources.resources
ResolveAssemblyReference.cache
TempPE
Properties.Resources.Designer.cs.dll
Refactor
Debug
InventorySys.Control.ScheduleItem.resources
InventorySys.csproj.GenerateResource.Cache
InventorySys.Form1.resources
ISCMS.Control.About.resources
ISCMS.Control.ActivityBalloon.resources
ISCMS.Control.BarItem.resources
ISCMS.Control.GoodsBalloon.resources
ISCMS.Control.JobBalloon.resources
ISCMS.Control.JobStatusBalloon.resources
ISCMS.Control.RMInTransitBalloon.resources
ISCMS.Control.VacantBalloon.resources
ISCMS.csproj.GenerateResource.Cache
ISCMS.Dialog.Job.resources
ISCMS.Dialog.Rates.resources
ISCMS.Dialog.Transaction.resources
ISCMS.exe
ISCMS.Invoice.PurchaseInvoice.resources
ISCMS.Invoice.SalesInvoiceList.resources
ISCMS.Main.BaseVisibility.resources
ISCMS.Main.Login.resources
ISCMS.Main.NonListBase.resources
ISCMS.MainForm.resources
ISCMS.MainForm2.resources
ISCMS.Manufacturing.EventList.resources
ISCMS.Manufacturing.JobList.resources
ISCMS.Manufacturing.Material.resources
ISCMS.MasterFiles.Base.resources
ISCMS.MasterFiles.Carrier.resources
ISCMS.MasterFiles.Client.resources
ISCMS.MasterFiles.Goods.resources
ISCMS.MasterFiles.Invoice.resources
ISCMS.MasterFiles.Order.resources
ISCMS.MasterFiles.Supplier.resources
ISCMS.MasterFiles.Transporter.resources
ISCMS.Order.PurchaseOrderList.resources
ISCMS.Order.SalesOrderList.resources
ISCMS.pdb
ISCMS.Plant.Event.resources
ISCMS.Plant.Panoramic.resources
ISCMS.Plant.PurchaseOrderConversion.resources
ISCMS.Plant.SalesOrderConversion.resources
ISCMS.Procurement.EventList.resources
ISCMS.Properties.Resources.resources
ISCMS.Warehouse.EventList.resources
ResolveAssemblyReference.cache
TempPE
Main.DataSet.nodeDataset.designer.cs.dll
Main.DataSet.TreeNodeDS.designer.cs.dll
Main.DataSetNS.nodeDataset.designer.cs.dll
Main.DataSetNS.TreeNodeDS.designer.cs.dll
Properties.Resources.Designer.cs.dll
Refactor
Control
Goods
Control
Employee
Control
Client
Control
Carrier
Control
Manufacturing
Control
Main
DataSetNS
nodeDataset.xsc
nodeDataset.xss
nodeDataset.xsx
TreeNodeDS.xsc
TreeNodeDS.xss
TreeNodeDS.xsx
ChartDialog
Jobs
Invoice
Control
Dialog
DataAccess
Order
Invoice
Control
bin
Debug
Hasan.dll
Inv.mdb
System.Windows.Forms.DataVisualization.Design.dll
System.Windows.Forms.DataVisualization.dll
ISCMS.vshost.exe
Utilities
ActivityLegend
ChartDataTableHelper
DigitalFilter
HistogramChartHelper
PieCollectedDataHelper
RangeSpliceChartHelper
SampleMain
SixSigma
SpikeRemoval
ISCMS.suo
Release.zip
Release
Inv.mdb
System.Web.DataVisualization.Design.dll
System.Windows.Forms.DataVisualization.Design.dll
System.Windows.Forms.DataVisualization.dll
ISCMS.exe
ISCMS.pdb
Hasan.dll
Hasan.pdb
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ISCMS.Dialog
{
    public partial class Transaction : Hasan.FormCustom
    {
        ISCMS.MainForm mainFrom;
        Job jobForm;
        public int Transaction_Status_ID;
        public int Transaction_Type_ID;
        bool Is_Raw_Material;
        bool Is_Job;
        int Job_ID;
        bool Is_Non_Cost;

        public Transaction()
        {
            InitializeComponent();
        }

        public Transaction(ISCMS.MainForm form, int transaction_Status_ID, int transaction_Type_ID, bool is_Raw_Material)
        {
            InitializeComponent();
            mainFrom = form;
            Transaction_Status_ID = transaction_Status_ID;
            Transaction_Type_ID = transaction_Type_ID;
            Is_Raw_Material = is_Raw_Material;

            if( Is_Raw_Material )
                combGoods.InitSort(MainForm.dsData, "Goods", "Name", "Goods_ID", 3, " Is_Raw_Material ", " Name ASC ");
            else
                combGoods.InitSort(MainForm.dsData, "Goods", "Name", "Goods_ID", 3, " Is_Raw_Material = False or Is_Dual ", " Name ASC  ");

            // no cost
            if (
                (Transaction_Type_ID == 2 && Transaction_Status_ID == 5 && Is_Raw_Material)
                || (Transaction_Type_ID == 1 && Transaction_Status_ID == 2 && !Is_Raw_Material)
                || (Transaction_Type_ID == 1 && Transaction_Status_ID == 1 && !Is_Raw_Material )
                || (Transaction_Type_ID == 1 && Transaction_Status_ID == 3 && !Is_Raw_Material )
                )
            {
                txtCost.Enabled = false;
                btnCost.Enabled = false;
                btnCost.Visible = false;
                Is_Non_Cost = true;
            }
            else
            {
                txtCost.Enabled = true;
                btnCost.Enabled = true;
                btnCost.Visible = true;
                Is_Non_Cost = false;
            }

            this.SetStyle(ControlStyles.UserPaint |
              ControlStyles.AllPaintingInWmPaint |
              ControlStyles.ResizeRedraw |
              ControlStyles.ContainerControl |
              ControlStyles.OptimizedDoubleBuffer |
              ControlStyles.SupportsTransparentBackColor
              , true);
        }


        public Transaction(ISCMS.MainForm form, int transaction_Status_ID, int transaction_Type_ID, bool is_Raw_Material,
            bool is_Job, int job_ID):this( form,transaction_Status_ID,transaction_Type_ID,is_Raw_Material)
        {
            Is_Job = is_Job;
            Job_ID = job_ID;
        }

        public Transaction(ISCMS.MainForm form, int transaction_Status_ID, int transaction_Type_ID, bool is_Raw_Material,
            bool is_Job, int job_ID, Job m_JobFrom,string start_Date)
            : this(form, transaction_Status_ID, transaction_Type_ID, is_Raw_Material)
        {
            Is_Job = is_Job;
            Job_ID = job_ID;
            jobForm = m_JobFrom;
            Date.Value = DateTime.Parse(start_Date);
            if (Is_Job)
            {
                Date.Enabled = false;
                Time.Enabled = false;
            }
        }

        void Current_Stock()
        {
            ISCMS.DataAccess.Access ac = new ISCMS.DataAccess.Access();
            System.Data.DataSet ds = ac.CheckGoodsAvailability(Date.Value.ToShortDateString(), Convert.ToInt32(combGoods.SelectedValue));
            DataRow[] rows = ds.Tables[0].Select();
            string str = "";
            if (Is_Raw_Material)
            {
                if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                {
                    str = " CS = 0, TS = 0, RS = 0";
                }
                else
                {
                    // current stock
                    str += " CS = " + Convert.ToString(Convert.ToInt32(rows[0]["Incomming_Current"]??0)
                                                - Convert.ToInt32(rows[0]["Outgoing_Finished"] ?? 0)
                                                - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                                                - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0)
                                                - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0)) + ", ";

                    // In transit stock
                    str += " TS = " + Convert.ToString(Convert.ToInt32(rows[0]["Incomming_Expected"] ?? 0)) + ", ";

                    // Reserve stock
                    str += " RS = " + Convert.ToString(Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)) + ", ";
                }
            }
            else
            {
                if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                {
                    str = " CS = 0, RS = 0, PP = 0, MP = 0";
                }
                else
                {
                    // current stock
                    str += " CS = " + Convert.ToString(Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_Sold"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0)) + ", ";

                    // Pending phase
                    str += " TS = " + Convert.ToString(Convert.ToInt32(rows[0]["Incomming_Expected"] ?? 0)) + ", ";

                    // Reserve stock
                    str += " RS = " + Convert.ToString(Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)) + ", ";

                    // Manufacturing Phase
                    str += " MP = " + Convert.ToString(Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0)) + ", ";

                }

            }
            lblCurrentStock.Text = str;
            
            lblCurrent_Per_Unit_Cost.Text = " Current Rate " +  
               string.Format("{0:c}", ac.GetCurrentCost(Convert.ToInt32(combGoods.SelectedValue),
               Is_Raw_Material,Date.Value.ToShortDateString()) );
            
        }

        int GetGoodsUnit(DataRow[] rows)
        {
            if (Is_Raw_Material)
            {
                #region
                
                if (Transaction_Type_ID == 2)
                {

                    if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                    {
                        return 0;
                    }


                    // Outgoing Expected
                    if (Transaction_Type_ID == 2 && Transaction_Status_ID == 2)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0) + Convert.ToInt32(rows[0]["Incomming_Expected"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                         - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0)
                         + Convert.ToInt32(rows[0]["Incomming_Expected"] ?? 0);
                    }

                    // outgoing InProcess
                    if (Transaction_Type_ID == 2 && Transaction_Status_ID == 3)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                         - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }

                    // outgoing Waste
                    if (Transaction_Type_ID == 2 && Transaction_Status_ID == 6)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                        - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }
                }



                if (Transaction_Type_ID == 1)
                {

                    if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                    {
                        return 0;
                    }


                    // Incomming current
                    if (Transaction_Type_ID == 1 && Transaction_Status_ID == 1)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_Finished"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0);
                    }

                    // Incomming expected
                    if (Transaction_Type_ID == 1 && Transaction_Status_ID == 2)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_Finished"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0)
                                            - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0);
                    }
                }
                #endregion
            }
            else
            {
                if (Transaction_Type_ID == 2)
                {
                    if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                    {
                        return 0;
                    }

                    // Outgoing Expected
                    if (Transaction_Type_ID == 2 && Transaction_Status_ID == 2)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                         - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0)
                         + Convert.ToInt32(rows[0]["Incomming_Expected"] ?? 0);
                    }

                    // Sale
                    if (Transaction_Type_ID == 2 && Transaction_Status_ID == 4)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                         - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }

                    // outgoing InProcess
                    if (Transaction_Type_ID == 2 && Transaction_Status_ID == 3)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                         - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }

                    // outgoing Waste
                    if (Transaction_Type_ID == 2 && Transaction_Status_ID == 6)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                        - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0) - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }
                }

                if (Transaction_Type_ID == 1)
                {
                    if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                    {
                        return 0;
                    }

                    // Incomming current
                    if (Transaction_Type_ID == 1 && Transaction_Status_ID == 1)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0)
                            + Convert.ToInt32(rows[0]["Incomming_Sold"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_Sold"] ?? 0)
                            - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }

                    // Incomming Sold
                    if (Transaction_Type_ID == 1 && Transaction_Status_ID == 1)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0)
                             + Convert.ToInt32(rows[0]["Incomming_Sold"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Sold"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }

                    // Incomming finised good job pending
                    if (Transaction_Type_ID == 1 && Transaction_Status_ID == 2)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Sold"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }

                    // Incomming finised good in production
                    if (Transaction_Type_ID == 1 && Transaction_Status_ID == 3)
                    {
                        return Convert.ToInt32(rows[0]["Incomming_Current"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_InProcess"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Expected"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Sold"] ?? 0)
                             - Convert.ToInt32(rows[0]["Outgoing_Waste"] ?? 0);
                    }
                }
            }
            return 0;
        }



        private void Save_Click(object sender, EventArgs e)
        {
            Save.Enabled = false;
            Cancel.Enabled = false;

            string sUnit_Cost = lblPerUnitCost.Text.Replace("$", "").Replace(",", "");
            sUnit_Cost = sUnit_Cost.Remove(sUnit_Cost.IndexOf("per"));


       
            if (Convert.ToInt32(combGoods.SelectedValue) == 0)
            {
                lblGoodsError.Visible = true;
                Save.Enabled = true;
                Cancel.Enabled = true;
                combGoods.Focus();
                return;
            }

            if ( txtQuantity.Text.Trim().Length == 0)
            {
                lblErrorQuantity.Visible = true;
                Save.Enabled = true;
                Cancel.Enabled = true;
                txtQuantity.Focus();
                return;
            }

            if (Convert.ToInt32(txtQuantity.Text) == 0)
            {
                lblErrorQuantity.Visible = true;
                Save.Enabled = true;
                Cancel.Enabled = true;
                txtQuantity.Focus();
                return;
            }

            if (Convert.ToInt32( txtCost.Text_AsDouble ) == 0 && !Is_Non_Cost )
            {
                lblErrorCost.Visible = true;
                Save.Enabled = true;
                Cancel.Enabled = true;
                txtCost.Focus();
                return;
            }

            if ( txtComments.Text.Trim().Length <  3 )
            {
                lblErrorComments.Visible = true;
                Save.Enabled = true;
                Cancel.Enabled = true;
                txtComments.Focus();
                return;
            }
            
            string sDate = Date.Value.ToShortDateString() + "  " + Time.Value.ToShortTimeString();
            ISCMS.DataAccess.Access ac = new ISCMS.DataAccess.Access();
            System.Data.DataSet ds = ac.CheckGoodsAvailability(Date.Value.ToShortDateString(), Convert.ToInt32(combGoods.SelectedValue));
            DataRow[] rows = ds.Tables[0].Select();
            int Goods_UnitSoldIntrapolate = 0;
            int Goods_UnitIntrapolate = 0;

            if (Is_Raw_Material)
            {
                if (Transaction_Type_ID == 2)
                {
                    if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                    {
                        Hasan.CMessageBox.ShowBox("Current stock level is  0 could not process the request", ( int )  Hasan.CMessageBox.Type.Error);
                        Save.Enabled = true;
                        Cancel.Enabled = true;
                        return;
                    }
                }
                Goods_UnitIntrapolate = GetGoodsUnit(rows);
            }
            else
            {
                // sales return 
                if (Transaction_Type_ID == 1 && Transaction_Status_ID == 4)
                {
                    if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                    {
                        Hasan.CMessageBox.ShowBox("There is no net sales till this date, there could not be sales return as well", (int)Hasan.CMessageBox.Type.Error);
                        Save.Enabled = true;
                        Cancel.Enabled = true;
                        return;
                    }
                    else
                    {
                        Goods_UnitSoldIntrapolate = Convert.ToInt32(rows[0]["Outgoing_Sold"] ?? 0) - Convert.ToInt32(rows[0]["Incomming_Sold"] ?? 0);
                        if (Goods_UnitSoldIntrapolate == 0)
                        {
                            Hasan.CMessageBox.ShowBox("There is no net sales till this date, there could not be sales return as well", (int)Hasan.CMessageBox.Type.Error);
                            Save.Enabled = true;
                            Cancel.Enabled = true;
                            return;
                        }
                    }
                }
                else
                {
                    Goods_UnitIntrapolate = GetGoodsUnit(rows);
                }
            }
           
            ds = ac.CheckGoodsAvailabilityExtrapolate(Date.Value.ToShortDateString(), Convert.ToInt32(combGoods.SelectedValue));
            rows = ds.Tables[0].Select();
            int Goods_UnitExtrapolate = GetGoodsUnit(rows);
            int Goods_UnitSoldExtrapolate = 0;


            #region sales
            if ((Transaction_Type_ID == 2 && Transaction_Status_ID == 2) ||
               (Transaction_Type_ID == 1 && Transaction_Status_ID == 4)
               )
            {
                if (rows.Length == 0 || rows[0]["Incomming_Current"].ToString().Length == 0)
                {
                    Goods_UnitSoldExtrapolate = 0;
                }
                else
                {
                    Goods_UnitSoldExtrapolate = Convert.ToInt32(rows[0]["Outgoing_Sold"]) - Convert.ToInt32(rows[0]["Incomming_Sold"]);
                }
            }
            #endregion

           if ( (Transaction_Type_ID == 2 && Transaction_Status_ID == 2) ||
               (Transaction_Type_ID == 1 && Transaction_Status_ID == 4)
               )
           {
               // incomming sold
               if (Transaction_Type_ID == 1 && Transaction_Status_ID == 4)
               {
                   if (Goods_UnitSoldIntrapolate < Convert.ToInt32(txtQuantity.Text))
                   {
                       Hasan.CMessageBox.ShowBox(" unit sold " + Goods_UnitSoldIntrapolate.ToString() + " and sales return is " + txtQuantity.Text + "  could not process it", (int)Hasan.CMessageBox.Type.Error);
                       Save.Enabled = true;
                       Cancel.Enabled = true;
                       return;
                   }

                   if (Goods_UnitSoldExtrapolate < Convert.ToInt32(txtQuantity.Text) && Goods_UnitSoldExtrapolate != 0)
                   {
                       Hasan.CMessageBox.ShowBox("There is " + combGoods.Text+ " transition in upcoming dates that show unavailable of desire stock", (int)Hasan.CMessageBox.Type.Error);
                       Save.Enabled = true;
                       Cancel.Enabled = true;
                       return;
                   }
               }
           }
           else
           {
               if (Transaction_Type_ID == 2)
               {
                   if ((Goods_UnitIntrapolate - Convert.ToInt32(txtQuantity.Text)) < 0)
                   {
                       Hasan.CMessageBox.ShowBox("Current stock level is " + Goods_UnitIntrapolate.ToString() + " could not process the request", (int)Hasan.CMessageBox.Type.Error);
                       Save.Enabled = true;
                       Cancel.Enabled = true;
                       return;
                   }

                   if (    ( Goods_UnitIntrapolate + Goods_UnitExtrapolate )  < Convert.ToInt32(txtQuantity.Text) && Goods_UnitExtrapolate != 0)
                   {
                       Hasan.CMessageBox.ShowBox("There is " + combGoods.Text + " transition in upcoming dates that show unavailable of desire stock", (int)Hasan.CMessageBox.Type.Error);
                       Save.Enabled = true;
                       Cancel.Enabled = true;
                       return;
                   }
               }
           }



           string str = "";

           float currentCost =  ac.GetCurrentCost(Convert.ToInt32(combGoods.SelectedValue),
               Is_Raw_Material,Date.Value.ToShortDateString());
            if( currentCost == 0 )
                currentCost = Convert.ToSingle(sUnit_Cost);

            if (Is_Job)
            {
                jobForm.dsTransaction.Tables["tblTransaction"].Rows.Add(new object[] { Convert.ToInt32(combGoods.SelectedValue),Is_Raw_Material, sDate, 0, Transaction_Status_ID, Transaction_Type_ID,Is_Job,0,
                    Convert.ToInt32(txtQuantity.Text),txtComments.Text,0,true,
                    (int)txtCost.Text_AsDouble, Convert.ToSingle(sUnit_Cost),currentCost});
                jobForm.ReloadGoods();

                if (Is_Raw_Material)
                {
                    str = Hasan.CMessageBoxContinueOk.ShowBox("Transition has been saved\n to continue press continue otherwise Done", (int)Hasan.CMessageBox.Type.Done);
                }
                else
                {
                    str = "Ok";
                }
            }
            else
            {
                ac.InsertTransaction(Convert.ToInt32(combGoods.SelectedValue), Is_Raw_Material, sDate,
                    1, Transaction_Status_ID, Transaction_Type_ID, Is_Job, Job_ID, 
                    Convert.ToInt32(txtQuantity.Text), txtComments.Text, 0, true,
                    (int)txtCost.Text_AsDouble, Convert.ToSingle(sUnit_Cost), currentCost);
                str = Hasan.CMessageBoxContinueOk.ShowBox("Transition has been saved\n to continue press continue otherwise Done", (int)Hasan.CMessageBox.Type.Done); 
            }

            if (str == "Continue")
            {
                Transaction_Load(new object(), new EventArgs());
                ResetForm();
                Save.Enabled = true;
                Cancel.Enabled = true;
                return;
            }
            else
            {
                //mainFrom.Load_Click(new object(), new EventArgs());
                this.Close();
            }
        }


        void ResetForm()
        {
            combGoods.SelectedIndex = 0;
            txtQuantity.Text = "0";
            txtCost.Text = string.Format("{0:c}",0);
            lblUnit.Text = "Qty.";
            lblPerUnitCost.Text = "per/unit cost";
            //Date.Value = DateTime.Now;
            //Time.Value = DateTime.Now;
            txtComments.Text = "";
        }




        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Transaction_Load(object sender, EventArgs e)
        {

   
            if (Is_Raw_Material)
            {
                lblFinishedGoodsfLabel1.Visible = false;
                lblFinishedGoodsLabel2.Visible = false;
                lblRawMaterialLabel.Visible = true;

                // Expected Raw Material
                if (Transaction_Type_ID == 1 && Transaction_Status_ID == 2)
                {
                    Header.Text = "Raw Material in transit";
                    Job_ID = 0;
                    Is_Job = false;
                    Header.BackColor = Color.Orange;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.Orange;
                }

                // Receiving Raw Material
                if (Transaction_Type_ID == 1 && Transaction_Status_ID == 1)
                {
                    Header.Text = "Raw Material Stock received";
                    Job_ID = 0;
                    Is_Job = false;
                    Header.BackColor = Color.Green;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.Green;

                }

                // Reserved Raw Material
                if (Transaction_Type_ID == 2 && Transaction_Status_ID == 2)
                {
                    Header.Text = "Reserve stock for Pending Phase";
                    Is_Job = true;
                    Header.BackColor = Color.DarkBlue;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.DarkBlue;
                }

                // In Process Raw Material
                if (Transaction_Type_ID == 2 && Transaction_Status_ID == 3)
                {
                    Header.Text = "Dispatch Stock for manufactureing Phase";
                    Is_Job = true;
                    Header.BackColor = Color.Yellow;
                    Header.ForeColor = Color.Black;
                    this.BackColor = Color.Yellow;
                }

                // Finished Raw Material
                if (Transaction_Type_ID == 2 && Transaction_Status_ID == 5)
                {
                    Header.Text = "Raw Material Consumed to Produce finished goods";
                    Is_Job = true;
                    Header.BackColor = Color.Black;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.Black;
                }

                // Wasted Raw Material
                if (Transaction_Type_ID == 2 && Transaction_Status_ID == 6)
                {
                    Header.Text = "Dispatch Wasted Raw Material";
                    Job_ID = 0;
                    Is_Job = false;
                    Header.BackColor = Color.Red;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.Red;
                }
            }
            else
            {
                lblFinishedGoodsfLabel1.Visible = true;
                lblFinishedGoodsLabel2.Visible = true;
                lblRawMaterialLabel.Visible = false;

                // Expected Finished Product
                if (Transaction_Type_ID == 1 && Transaction_Status_ID == 2)
                {
                    Header.Text = "Finished Goods in transit";
                    Is_Job = true;
                    Header.BackColor = Color.Orange;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.Orange;
                }

                // Current Finished Product
                if (Transaction_Type_ID == 1 && Transaction_Status_ID == 1)
                {
                    Header.Text = "Current Stock";
                    Is_Job = true;
                    Header.BackColor = Color.Green;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.Green;
                }

                // In Process Finished Goods
                if (Transaction_Type_ID == 1 && Transaction_Status_ID == 3)
                {
                    Header.Text = "Finished Goods in production";
                    Is_Job = true;
                    Header.BackColor = Color.Yellow;
                    Header.ForeColor = Color.Black;
                    this.BackColor = Color.Yellow;
                }

                // Sales Return
                if (Transaction_Type_ID == 1 && Transaction_Status_ID == 4)
                {
                    Header.Text = "Sales Return";
                    Job_ID = 0;
                    Is_Job = false;
                    Header.BackColor = Color.DarkBlue;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.DarkBlue;
                }

                // Outgoing expected
                if (Transaction_Type_ID == 2 && Transaction_Status_ID == 2)
                {
                    Header.Text = "Finished Goods Reserve for Dispatch";
                    Job_ID = 0;
                    Is_Job = false;
                    Header.BackColor = Color.DimGray;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.DimGray;
                }

                


                // Sold Finished Product
                if (Transaction_Type_ID == 2 && Transaction_Status_ID == 4)
                {
                    Header.Text = "Finished Goods Dispatch for sale";
                    Job_ID = 0;
                    Is_Job = false;
                    Header.BackColor = Color.RoyalBlue;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.RoyalBlue;
                }

                // Wasted Finished Product
                if (Transaction_Type_ID == 2 && Transaction_Status_ID == 6)
                {
                    Header.Text = "Dispatch Wasted Finished Goods";
                    Job_ID = 0;
                    Is_Job = false;
                    Header.BackColor = Color.Red;
                    Header.ForeColor = Color.White;
                    this.BackColor = Color.Red;
                }
            }

            this.combGoods.SelectedIndexChanged += new System.EventHandler(this.combGoods_SelectedIndexChanged);
        }

        
        private void combGoods_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Convert.ToInt32(combGoods.SelectedValue) != 0)
            {
                string unit_ID = MainForm.dsData.Tables["Goods"].Select("Goods_ID = " + combGoods.SelectedValue.ToString())[0]["Goods_Unit_ID"].ToString();
                lblUnit.Text = MainForm.dsData.Tables["Goods_Unit"].Select(" Goods_Unit_ID = " + unit_ID)[0]["Goods_Unit_Name"].ToString();  // 
                lblGoodsError.Visible = false;
            }
            else
            {
                lblGoodsError.Visible = true;
                combGoods.Focus();
            }
            Current_Stock();
        }

        private void txtQuantity_TextChanged(object sender, EventArgs e)
        {
            lblErrorQuantity.Visible = false;
            lblErrorCost.Visible = false;
            if (txtQuantity.Text.Trim().Length == 0)
                txtQuantity.Text = "0";
            lblPerUnitCost.Text = string.Format("{0:c}", Math.Round(txtCost.Text_AsDouble / Convert.ToInt32(txtQuantity.Text), 2)) + " per/" + lblUnit.Text;
        }

        public void CalculateCost()
        {
            string sUnit_Cost = lblPerUnitCost.Text.Replace("$", "").Replace(",", "");
            sUnit_Cost = sUnit_Cost.Remove(sUnit_Cost.IndexOf("per"));
            txtCost.Text = Convert.ToString(Convert.ToSingle(sUnit_Cost) * Convert.ToInt32(txtQuantity.Text));
        }

        private void txtComments_TextChanged(object sender, EventArgs e)
        {
            lblErrorComments.Visible = false;
        }

        private void Date_ValueChanged(object sender, EventArgs e)
        {
            Current_Stock();
        }

        private void btnCost_Click(object sender, EventArgs e)
        {
            ISCMS.Dialog.Rates dl = new Rates( Convert.ToInt32(combGoods.SelectedValue),this );
            dl.ShowDialog();
        }

        private void Transaction_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Escape)
            {
                this.Close();
                return;
            }
        }
      
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hasan Hyder
Software Developer
Pakistan Pakistan
No Biography provided
Group type: Organisation

29 members

Follow on   Google+

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 8 Oct 2009
Article Copyright 2009 by Hasan Hyder
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid