private void FRecord_Load(object sender, EventArgs e)
        {
            #region Defining variables controls
            diContBillsMand = new Dictionary <Control, ErrorProvider>();

            diContBillsNum = new Dictionary <Control, string>();
            dataSet        = new DataSet();
            #endregion

            #region Collecting numeric controls
            diContBillsNum.Add(txtBillNo, "Int");
            diContBillsNum.Add(txtStatical, "Decimal");
            diContBillsNum.Add(txtAmount, "Decimal");
            #endregion

            #region Collecting compulsory controls
            diContBillsMand.Add(txtBillNo, errProBillNo);
            diContBillsMand.Add(cbParty, errProParty);
            diContBillsMand.Add(txtStatical, errProStatical);
            diContBillsMand.Add(txtAmount, errProTotal);
            #endregion

            #region Setting up UI
            toolStripContainer1.Dock = DockStyle.Fill;
            dgvConsignments.Dock     = DockStyle.Bottom;

            datePickerBill.CustomFormat = "dd/MM/yyyy";

            txtStatical.TextAlign = txtAmount.TextAlign = HorizontalAlignment.Right;

            dgvConsignments.ReadOnly = true;

            dgvConsignments.ContextMenuStrip = contextAttachConsignment;

            _tsmiAttachConsignment        = new ToolStripMenuItem("Attach Consignment");
            _tsmiAttachConsignment.Click += _tsmiAttachConsignment_Click;

            contextAttachConsignment.Items.Add(_tsmiAttachConsignment);

            datePickerBill.Format = DateTimePickerFormat.Custom;

            this.WindowState = FormWindowState.Maximized;

            //  Starts Sets properties for panel controls that adds CNs to a Bill

            _uiManager.setBackColor(toolStripContainer1.ContentPanel.Controls, Color.Transparent);

            dgvConsignments.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            dgvConsignments.AllowUserToAddRows  = false;

            DataGridViewImageColumn dgvic = new DataGridViewImageColumn();
            dgvic.DisplayIndex = 0;
            dgvic.Icon         = new System.Drawing.Icon(Directory.GetCurrentDirectory().Replace(@"bin\Debug", @"pictures\ico_remove.ico"));
            dgvConsignments.Columns.Add(dgvic);

            lblBillNo.Focus();
            #endregion

            #region Setting up data
            txtBillNo.Text        = DBAccess.GetMaxNext("BillNo", "Bills", "max").ToString();
            cbParty.DisplayMember = "Name";
            cbParty.ValueMember   = "PartyID";
            cbParty.DataSource    = DBAccess.GetKeyValueDataTable("PartyID", "Name", "Parties");
            #endregion
        }
        private void FormNewConsignment_Load(object sender, EventArgs e)
        {
            #region  Setting up UI
            RB_IC_Value.Checked = true;
            P_IC.Dock           = DockStyle.Fill;
            DTP_IC.Format       = DateTimePickerFormat.Custom;
            DTP_IC.Text         = DateTime.Now.ToShortDateString();
            DTP_IC.CustomFormat = "dd/MM/yyyy";

            TB_IC_No.MaxLength      = TB_IC_Packages.MaxLength = 10;
            TB_IC_Amount.MaxLength  = TB_IC_Rate.MaxLength = TB_IC_Weight.MaxLength = 13;
            TB_IC_Inv.MaxLength     = 20;
            TB_IC_Vehicle.MaxLength = 20;
            TB_IC_Desc.MaxLength    = 500;
            TB_IC_Amount.TextAlign  = TB_IC_Packages.TextAlign = TB_IC_Rate.TextAlign = TB_IC_Weight.TextAlign = HorizontalAlignment.Right;

            //cbConsignor.DropDownStyle = ComboBoxStyle.DropDown;

            _uiManager.setBackColor(P_IC.Controls, Color.Transparent);
            #endregion

            #region Setting up data
            TB_IC_No.Text = DBAccess.GetMaxNext("ConsignmentNo", "Consignments", "max").ToString();

            DataTable dt = DBAccess.GetKeyValueDataTable("CityID", "City", "Cities");
            dt.Rows.InsertAt(dt.NewRow(), 0);
            dt.Rows[0]["CityId"] = 0;
            dt.Rows[0]["City"]   = "--select--";
            cbFrom.DisplayMember = cbTo.DisplayMember = "City";
            cbFrom.ValueMember   = cbTo.ValueMember = "CityID";
            //  Sometimes it gives ArgumentException at the time of binding DisplayMember to data source, which is why I am assigning them before Data source.
            cbFrom.DataSource = dt;
            cbTo.DataSource   = dt.Copy();
            dt = null;

            dt = DBAccess.GetKeyValueDataTable("PartyID", "Name", "Parties");
            dt.Rows.InsertAt(dt.NewRow(), 0);
            dt.Rows[0]["PartyID"]     = 0;
            dt.Rows[0]["Name"]        = "--select--";
            cbConsignor.DisplayMember = cbConsignee.DisplayMember = "Name";
            cbConsignor.ValueMember   = cbConsignee.ValueMember = "PartyID";
            cbConsignor.DataSource    = dt;
            cbConsignee.DataSource    = dt.Copy();
            dt = null;
            #endregion

            #region Collecting numeric controls
            diContConsignmentsNum.Add(TB_IC_No, "Int");
            diContConsignmentsNum.Add(TB_IC_Packages, "Int");
            diContConsignmentsNum.Add(TB_IC_Weight, "Decimal");
            diContConsignmentsNum.Add(TB_IC_Rate, "Decimal");
            diContConsignmentsNum.Add(TB_IC_Amount, "Decimal");
            #endregion

            #region Collecting compulsory controls
            diContConsignmentsMand.Add(TB_IC_No, EP_IC_No);
            diContConsignmentsMand.Add(cbConsignor, EP_IC_Signor);
            diContConsignmentsMand.Add(cbConsignee, EP_IC_Signee);
            diContConsignmentsMand.Add(cbFrom, EP_IC_Signee);
            diContConsignmentsMand.Add(cbTo, EP_IC_To);
            diContConsignmentsMand.Add(TB_IC_Weight, EP_IC_Weight);
            #endregion

            TB_IC_No.Focus();

            TB_IC_Amount.Enabled = false;
        }