Example #1
0
        public printDO(DataRow row, M_V4_printDO f)
        {
            InitializeComponent();
            this.c      = new DbConnect();
            this.parent = f;
            if (row.Table.Columns.Count < 3)
            {
                return;
            }
            if (row["Type_Of_Sale"].ToString() == "0")
            {
                label3.Visible       = false;
                label5.Visible       = false;
                label6.Visible       = false;
                this.label7.Location = new System.Drawing.Point(268, 48);
            }
            // Load default firm details
            DataTable dt10 = c.runQuery("SELECT * FROM Defaults WHERE Default_Type= 'Print' and default_name = 'Default Print Type'");
            string    default_print_type_id = dt10.Rows[0]["Default_Value"].ToString();

            DataTable dt_printTypes = c.runQuery("select * from Print_Types where Print_Type_ID=" + default_print_type_id);

            if (dt_printTypes == null)
            {
                c.WarningBox("Print->Default Print Type is set as " + default_print_type_id + ", not found in Default Print_Type_IDs Table, " +
                             "defaulting to first entry in Print_Types table");
                dt_printTypes = c.runQuery("select * from Print_Types");
            }
            for (int j = 0; j < dt_printTypes.Columns.Count - 1; j++)
            {
                firmDetails[dt_printTypes.Columns[j].ColumnName] = dt_printTypes.Rows[0][j].ToString();
            }

            this.type                     = int.Parse(row["Type_Of_Sale"].ToString());
            this.donoTextbox.Text         = row["Sale_DO_No"].ToString();
            this.saleDateTextbox.Text     = row["Date_Of_Sale"].ToString().Substring(0, 10);
            this.customerNameTextbox.Text = row["Customer"].ToString();
            this.qualityTextbox.Text      = row["Quality"].ToString();
            this.label3.Text              = firmDetails["Firm_Name"];
            this.label5.Text              = firmDetails["Address"];
            float sale_rate  = float.Parse(row["Sale_Rate"].ToString());
            float net_weight = float.Parse(row["Net_Weight"].ToString());

            //this.amountTextbox.Text = (sale_rate * net_weight).ToString("F2");
            //this.netwtTextbox.Text = net_weight.ToString("F3");
            this.rateTB.Text = sale_rate.ToString("F2");

            //string[] carton_nos = c.csvToArray(row["Carton_No_Arr"].ToString());
            //string cartonfisc = row["Carton_Fiscal_Year"].ToString();
            string    table = row["Tablename"].ToString();
            DataTable dt    = new DataTable();

            dt.Columns.Add("Sl No");
            dt.Columns.Add("Carton No.");
            dt.Columns.Add("Shade");
            dt.Columns.Add("Net Wt.");
            dt.Columns.Add("Rate");
            float     net_wt = 0F, net_rate = 0F;
            DataTable cartons = new DataTable();

            if (table == "Carton")
            {
                cartons = c.getTableData("Carton", "*", "TS_Voucher_ID=" + row["Voucher_ID"].ToString() + " AND Date_Of_Sale IS Not Null");
            }
            else
            {
                cartons = c.getTableData("Carton_Produced", "*", "Sales_Voucher_ID=" + row["Voucher_ID"].ToString());
            }
            for (int i = 0; i < cartons.Rows.Count; i++)
            {
                DataRow dtemp  = cartons.Rows[i];
                string  colour = "Gray";
                if (table != "Carton")
                {
                    colour = dtemp["Colour"].ToString();
                }
                net_wt += float.Parse(dtemp["Net_Weight"].ToString());
                float rate = (float.Parse(dtemp["Net_Weight"].ToString()) * float.Parse(row["Sale_Rate"].ToString()));
                net_rate += rate;
                dt.Rows.Add(i + 1, dtemp["Carton_No"].ToString(), colour, dtemp["Net_Weight"].ToString(), rate.ToString("F2"));
            }

            dt.Rows.Add("", "", "Net Weight", net_wt.ToString("F3"), net_rate.ToString("F2"));
            dataGridView1.DataSource             = dt;
            dataGridView1.Columns["Sl No"].Width = 60;
            c.auto_adjust_dgv(dataGridView1);
            dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White;
            dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;
            dataGridView1.Columns.Cast <DataGridViewColumn>().ToList().ForEach(t => t.SortMode = DataGridViewColumnSortMode.NotSortable);
            dataGridView1.Columns["Sl NO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            c.set_dgv_column_sort_state(dataGridView1, DataGridViewColumnSortMode.NotSortable);
            this.where = "Voucher_ID=" + int.Parse(row["Voucher_ID"].ToString()) + "";

            this.label3.Text = firmDetails["Firm_Name"];
            this.label5.Text = firmDetails["Address"];
            this.label6.Text = "(GSTIN No. " + firmDetails["GSTIN"] + ")";
            PrinterSettings ps = new PrinterSettings();

            printDocument1.PrinterSettings = ps;
            IEnumerable <PaperSize> paperSizes = ps.PaperSizes.Cast <PaperSize>();
            PaperSize sizeA4 = paperSizes.First <PaperSize>(size => size.Kind == PaperKind.A4); // setting paper size to A4 size

            printDocument1.DefaultPageSettings.PaperSize = sizeA4;
        }
 private void button3_Click(object sender, EventArgs e)
 {
     M_V4_printDO f = new M_V4_printDO();
     Global.background.show_form(f);
 }