Friday, 6 July 2012

At a time multiple data inserted in a single field using Data Table

    private DataTable GetTableData()
        {
            string NumberingType = "";
            bool fyear;


            DataTable dt = new DataTable();
            if (RadNumbering.Checked == true)
            {
                NumberingType = "Manual";
                dt.Columns.Add("Company_ID", typeof(int));
                dt.Columns.Add("Voucher_Numbering_Type", typeof(string));
                dt.Columns.Add("Voucher_Type", typeof(string));
                dt.Columns.Add("Prefix", typeof(string));
                dt.Columns.Add("With_Financial_Year", typeof(bool));
                dt.Columns.Add("Auto_Number_Size", typeof(int));

                //dt.Columns.Add("CreatedOn", typeof(string));
                //dt.Columns.Add("CreatedBy", typeof(int));
                //dt.Columns.Add("ModifiedOn", typeof(string));
                //dt.Columns.Add("ModifiedBy", typeof(int));
                //============
                if (TxtCashReceiptPrefix.Text != "")
                {
                    if (TxtCashPaymentPrefix.Text != "")
                    {
                        if (ChkCashPaymentFYear.Checked == true)
                        {
                            fyear = Convert.ToBoolean(1);
                        }
                        else
                        {
                            fyear = Convert.ToBoolean(0);
                        }

                        dt.Rows.Add(1, "Manual", LblCasPayment.Text, TxtCashPaymentPrefix.Text, fyear, TxtCashPaymentAutoNoSize.Text);
                    }
                    if (ChkCashReceiptFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }

                    dt.Rows.Add(1, "Manual", LblCashReceipt.Text, TxtCashReceiptPrefix.Text, fyear, TxtCashReceiptAutoNoSize.Text);
                }

                if (TxtBankPaymentPrefix.Text != "")
                {
                    if (ChkBankPaymentFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblBankPayment.Text, TxtBankPaymentPrefix.Text, fyear, TxtBankPaymentAutoNoSize.Text);
                }
                if (TxtBankReceiptPrefix.Text != "")
                {
                    if (ChkBankReceiptFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblBankReceipt.Text, TxtBankReceiptPrefix.Text, fyear, TxtBankReceiptAutoNoSize.Text);
                }
                if (TxtJVoucherPrefix.Text != "")
                {
                    if (ChkJVVoucherFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblJournalVoucher.Text, TxtJVoucherPrefix.Text, fyear, TxtJVVoucherAutoNoSize.Text);
                }
                if (TxtContraoucherPrefix.Text != "")
                {
                    if (ChkContraVoucherFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblContraVoucher.Text, TxtContraoucherPrefix.Text, fyear, TxtContraVoucherAutoNoSize.Text);
                }
                if (TxtPurOrderPrefix.Text != "")
                {
                    if (ChkPurOrderFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblPurOrder.Text, TxtPurOrderPrefix.Text, fyear, TxtPurOrderAutoNoSize.Text);
                }

                if (TxtSalesOrderPrefix.Text != "")
                {
                    if (ChkSalesOrderFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblSalesOrder.Text, TxtSalesOrderPrefix.Text, fyear, TxtSalesOrderAutoNoSize.Text);
                }
                if (TxtPurchReturnPrefix.Text != "")
                {
                    if (ChkPurchReturnFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblPurchReturn.Text, TxtPurchReturnPrefix.Text, fyear, TxtPurchReturnAutoNoSize.Text);
                }
                if (TxtSalesReturnPrefix.Text != "")
                {
                    if (ChkSalesReturnFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblSalesReturn.Text, TxtSalesReturnPrefix.Text, fyear, TxtSalesReturnAutoNoSize.Text);
                }
                if (TxtStockTranVoucherPrefix.Text != "")
                {
                    if (ChkStockTranVoucherFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblStockTranVoucher.Text, TxtStockTranVoucherPrefix.Text, fyear, TxtStockTranVoucherAutoNoSize.Text);
                }
                if (TxtStockInvVoucherPrefix.Text != "")
                {
                    if (ChkStockInvVoucherFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblStockInvVoucher.Text, TxtStockInvVoucherPrefix.Text, fyear, TxtStockInvVoucherAutoNoSize.Text);
                }
                if (TxtMatReceiveVoucherPrefix.Text != "")
                {
                    if (ChkMatReceiveVoucherFYear.Checked == true)
                    {
                        fyear = Convert.ToBoolean(1);
                    }
                    else
                    {
                        fyear = Convert.ToBoolean(0);
                    }
                    dt.Rows.Add(1, "Manual", LblMatReceiveVoucher.Text, TxtMatReceiveVoucherPrefix.Text, fyear, TxtMatReceiveVoucherAutoNoSize.Text);
                }
                UFMS_VoucherSetups vouchers = new UFMS_VoucherSetups();
                if (ChkWarningVouList.Checked == true)
                {
                    vouchers.Warning_Before_Last_Voucher_List = Convert.ToBoolean(1);
                }
                vouchers.Complete_Voucher_List_Warning_Message = TxtWarningMessage.Text;
                if (RadYearly.Checked)
                {
                    vouchers.Renumbering_Frequency = RadYearly.Text;
                }
                else if (RadMonthly.Checked)
                {
                    vouchers.Renumbering_Frequency = RadMonthly.Text;
                }
                else
                {
                    vouchers.Renumbering_Frequency = RadQuartly.Text;
                }
                if (RadYes.Checked)
                {
                    vouchers.Fix_Length_Numeric_Part = Convert.ToBoolean(1);
                }
                else
                {
                    vouchers.Fix_Length_Numeric_Part = Convert.ToBoolean(0);
                }
                vouchers.Company_ID = 1;
                vouchers.Voucher_Numbering_Type = NumberingType.ToString();
                UERPManagement.GetInstance.InsertVoucherSetupManual(dt, vouchers);
                Label5.Text = "Data Inserted Successfulley";
            }
            if (RadAutomatic.Checked == true)
            {
                UFMS_VoucherSetups newvouchers = new UFMS_VoucherSetups();
                newvouchers.Company_ID = 1;
                newvouchers.Duplicate_Voucher = DrpDuplicateVoucher.SelectedItem.Text;
                newvouchers.Blank_Voucher = DdlBlankVoucher.SelectedItem.Text;
                UERPManagement.GetInstance.InsertVoucherSetup(newvouchers);
                Label5.Text = "Data Inserted Successfulley";
            }
            return dt;
        }


-------------------------------------------------------------------
public void InsertVoucherSetupManual(DataTable dt, UFMS_VoucherSetups vouchers)
        {
           
          
            //==================================================
            // Add Voucher_Numbering_Type
            SqlCommand updateCommand = new SqlCommand("Ufms.KC_UpdateParty");
            updateCommand.CommandType = CommandType.StoredProcedure;
            updateCommand.Parameters.Add(GetParameter("@Company_ID", SqlDbType.Int, vouchers.Company_ID));
            updateCommand.Parameters.Add(GetParameter("@Warning_Before_Last_Voucher_List", SqlDbType.Bit, vouchers.Warning_Before_Last_Voucher_List));
            updateCommand.Parameters.Add(GetParameter("@Voucher_Numbering_Type", SqlDbType.VarChar, vouchers.Voucher_Numbering_Type));
            updateCommand.Parameters.Add(GetParameter("@Complete_Voucher_List_Warning_Message", SqlDbType.VarChar, vouchers.Complete_Voucher_List_Warning_Message));
            updateCommand.Parameters.Add(GetParameter("@Renumbering_Frequency", SqlDbType.VarChar, vouchers.Renumbering_Frequency));
            updateCommand.Parameters.Add(GetParameter("@Fix_Length_Numeric_Part", SqlDbType.Bit, vouchers.Fix_Length_Numeric_Part));
            ExecuteStoredProcedure(updateCommand);
            //==================================================
            //VoucherSetup
            foreach (DataRow dr in dt.Rows)
            {
                SqlCommand insertCommand = new SqlCommand("Ufms.KC_InsertVoucherSetup");
                insertCommand.CommandType = CommandType.StoredProcedure;
   
                insertCommand.Parameters.Add(GetParameter("@Company_ID", SqlDbType.VarChar, dr["Company_ID"].ToString()));
                insertCommand.Parameters.Add(GetParameter("@Voucher_Numbering_Type", SqlDbType.VarChar, dr["Voucher_Numbering_Type"].ToString()));  
                insertCommand.Parameters.Add(GetParameter("@Voucher_Type", SqlDbType.VarChar, dr["Voucher_Type"].ToString()));
                insertCommand.Parameters.Add(GetParameter("@Prefix", SqlDbType.VarChar, dr["Prefix"].ToString()));
                insertCommand.Parameters.Add(GetParameter("@With_Financial_Year", SqlDbType.Bit, dr["With_Financial_Year"].ToString()));
                insertCommand.Parameters.Add(GetParameter("@Auto_Number_Size", SqlDbType.Int, dr["Auto_Number_Size"].ToString()));

                //insertCommand.Parameters.Add(GetParameter("@Created_On", SqlDbType.DateTime, dr["Created_On"].ToString()));
                //insertCommand.Parameters.Add(GetParameter("@Created_By", SqlDbType.Int, dr["Created_By"].ToString()));
                //insertCommand.Parameters.Add(GetParameter("@Modified_On", SqlDbType.DateTime, dr["Modified_On"].ToString()));
                //insertCommand.Parameters.Add(GetParameter("@Modified_By", SqlDbType.Int, dr["Modified_By"].ToString()));

                ExecuteStoredProcedure(insertCommand);
            }
        }

No comments:

Post a Comment