Пример #1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                string ExcelFile        = "";
                string SelectedFileName = "";

                OpenFileDialog ofd    = new OpenFileDialog();
                DialogResult   result = ofd.ShowDialog(); // Show the dialog.
                if (result == DialogResult.OK)            // Test result.
                {
                    if (result == DialogResult.OK)        // Test result.
                    {
                        ExcelFile        = ofd.SafeFileName;
                        SelectedFileName = ofd.FileName;
                    }

                    objDataAccess.Upload("Temp_Item", SelectedFileName);

                    DataTable dtblImport = new DataTable();
                    dtblImport = objList.ListOfRecord("usp_Import_Item_List", null, "Import Item - LoadList");
                    if (ExcelFile.ToString() == "Item.xls")
                    {
                        for (int i = 0; i < dtblImport.Rows.Count; i++)
                        {
                            if (dtblImport.Rows[i]["ITEM"].ToString().Trim() != "" && dtblImport.Rows[i]["ITEM"].ToString() != null)
                            {
                                Int64 CAT_ID, UOM_ID, CLASS_ID, Godown_ID, Currency_ID;


                                DataTable dtMaxCode = new DataTable();
                                dtMaxCode = objList.ListOfRecord("usp_Select_Max_Code_Item", null, "MAX ITEM - LoadList");


                                if (dtMaxCode.Rows[0][0].ToString() == null || dtMaxCode.Rows[0][0].ToString().Trim() == "")
                                {
                                    CODE = "ITEM-00001";
                                }
                                else
                                {
                                    CODE = "ITEM-" + (Convert.ToInt16(dtMaxCode.Rows[0][0].ToString().Substring(5, 5).TrimStart('0')) + 1).ToString().PadLeft(5, '0');
                                }


                                DataTable           dtUOMId = new DataTable();
                                NameValueCollection ParaUOM = new NameValueCollection();
                                ParaUOM.Add("@i_UOM", dtblImport.Rows[i]["UOM"].ToString());
                                dtUOMId = objList.ListOfRecord("usp_Select_UOMID", ParaUOM, "Item Class - LoadList");
                                if (dtUOMId.Rows.Count > 0)
                                {
                                    UOM_ID = Convert.ToInt64(dtUOMId.Rows[0][0].ToString());
                                }
                                else
                                {
                                    UOM_ID = 0;
                                }

                                DataTable           dtCurrencyId = new DataTable();
                                NameValueCollection ParaCurrency = new NameValueCollection();
                                ParaCurrency.Add("@i_Currency", dtblImport.Rows[i]["CURRENCY"].ToString());
                                dtCurrencyId = objList.ListOfRecord("usp_Select_CurrencyID", ParaCurrency, "Item Class - LoadList");
                                if (dtCurrencyId.Rows.Count > 0)
                                {
                                    Currency_ID = Convert.ToInt64(dtCurrencyId.Rows[0][0].ToString());
                                }
                                else
                                {
                                    Currency_ID = 0;
                                }

                                string Othername = "";
                                //if (dtblImport.Rows[i]["OTHER_NAME"].ToString().Trim() != "" || dtblImport.Rows[i]["OTHER_NAME"].ToString() != null)
                                //{
                                //    Othername = dtblImport.Rows[i]["OTHER_NAME"].ToString();
                                //}
                                //else
                                //{
                                //    Othername = "";
                                //}
                                string Description  = "";
                                string PRODUCT_CODE = "";
                                string HSN_CODE     = "";


                                decimal OPENINGSTOCK = 0;
                                decimal REORDERLEVEL = 0;
                                string  LOCATION     = "";
                                string  RACKNO       = "";

                                if (dtblImport.Rows[i]["DESCRIPTION"].ToString().Trim() != "" || dtblImport.Rows[i]["DESCRIPTION"].ToString() != null)
                                {
                                    Description = dtblImport.Rows[i]["DESCRIPTION"].ToString();
                                }
                                else
                                {
                                    Description = "";
                                }
                                decimal Price = 0;
                                if (dtblImport.Rows[i]["Price"].ToString().Trim() != "")
                                {
                                    Price = Convert.ToDecimal(dtblImport.Rows[i]["Price"].ToString());
                                }
                                else
                                {
                                    Price = 0;
                                }
                                if (dtblImport.Rows[i]["PRODUCT_CODE"].ToString().Trim() != "" || dtblImport.Rows[i]["PRODUCT_CODE"].ToString() != null)
                                {
                                    PRODUCT_CODE = dtblImport.Rows[i]["PRODUCT_CODE"].ToString();
                                }
                                else
                                {
                                    PRODUCT_CODE = "";
                                }
                                if (dtblImport.Rows[i]["HSN_CODE"].ToString().Trim() != "" || dtblImport.Rows[i]["HSN_CODE"].ToString() != null)
                                {
                                    HSN_CODE = dtblImport.Rows[i]["HSN_CODE"].ToString();
                                }
                                else
                                {
                                    HSN_CODE = "";
                                }

                                DataTable           dtGodownId = new DataTable();
                                NameValueCollection ParaGD     = new NameValueCollection();
                                ParaGD.Add("@i_GODOWN", dtblImport.Rows[i]["GODOWN"].ToString());
                                dtGodownId = objList.ListOfRecord("usp_Select_GODOWNID", ParaGD, "Item Class - LoadList");
                                //if (dtGodownId.Rows.Count > 0)
                                //{
                                //    Godown_ID = Convert.ToInt64(dtGodownId.Rows[0][0].ToString());
                                //}
                                //else
                                //{
                                Godown_ID = 1;
                                //}

                                if (dtblImport.Rows[i]["OPENING STOCK"].ToString().Trim() != "" || dtblImport.Rows[i]["OPENING STOCK"].ToString() != null)
                                {
                                    if (dtblImport.Rows[i]["OPENING STOCK"].ToString() == "")
                                    {
                                    }
                                    else
                                    {
                                        OPENINGSTOCK = Convert.ToDecimal(dtblImport.Rows[i]["OPENING STOCK"].ToString());
                                    }
                                }
                                else
                                {
                                    OPENINGSTOCK = 0;
                                }

                                if (dtblImport.Rows[i]["REORDER LEVEL"].ToString().Trim() != "" || dtblImport.Rows[i]["REORDER LEVEL"].ToString() != null)
                                {
                                    if (dtblImport.Rows[i]["REORDER LEVEL"].ToString() == "")
                                    {
                                    }
                                    else
                                    {
                                        REORDERLEVEL = Convert.ToDecimal(dtblImport.Rows[i]["REORDER LEVEL"].ToString());
                                    }
                                }
                                else
                                {
                                    REORDERLEVEL = 0;
                                }

                                if (dtblImport.Rows[i]["LOCATION"].ToString().Trim() != "" || dtblImport.Rows[i]["LOCATION"].ToString() != null)
                                {
                                    LOCATION = dtblImport.Rows[i]["LOCATION"].ToString();
                                }
                                else
                                {
                                    LOCATION = "";
                                }

                                if (dtblImport.Rows[i]["RACK NO"].ToString().Trim() != "" || dtblImport.Rows[i]["RACK NO"].ToString() != null)
                                {
                                    RACKNO = dtblImport.Rows[i]["RACK NO"].ToString();
                                }
                                else
                                {
                                    RACKNO = "";
                                }

                                objItemBL.Insert(CODE,
                                                 dtblImport.Rows[i]["ITEM"].ToString(),
                                                 Othername,
                                                 Description,
                                                 UOM_ID,
                                                 Price, PRODUCT_CODE, HSN_CODE, "", 0,
                                                 OPENINGSTOCK,
                                                 Convert.ToDecimal(REORDERLEVEL), LOCATION, RACKNO, Convert.ToInt32(Godown_ID), "", Currency_ID
                                                 );
                            }
                        }

                        MessageBox.Show("Data Uploded Successfully..!!");
                        LoadList();
                    }
                    else
                    {
                        MessageBox.Show("Select Proper Item.xls File.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        public bool SetSave()
        {
            bool ReturnValue = false;

            try
            {
                if (_Mode == (int)Common.Constant.Mode.Delete)
                {
                    CommDelRec.DeleteRecord(_ItemID, "usp_Item_Delete", "frmItemEntry-SetSave");
                    if (CommDelRec.Exception == null)
                    {
                        if (CommDelRec.ErrorMessage != "")
                        {
                            lblErrorMessage.Text = CommDelRec.ErrorMessage;
                            txtItemName.Focus();
                            ReturnValue = false;
                        }
                        else
                        {
                            ReturnValue = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show(CommDelRec.Exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ReturnValue = false;
                    }
                }
                else
                {
                    if (txtprice.Text == "")
                    {
                        txtprice.Text = "0.00";
                    }

                    if (DataValidator.IsValid(this.grpData))
                    {
                        if (Convert.ToInt16(cmbgodown.SelectedValue) != 0)
                        {
                            if (_Mode == (int)Common.Constant.Mode.Insert)
                            {
                                string              XMLString = string.Empty;
                                long                Cnt       = 0;
                                DataTable           dtgodown  = new DataTable();
                                NameValueCollection para      = new NameValueCollection();
                                para.Add("@i_UserID", CurrentUser.UserID.ToString());
                                para.Add("@i_CompId", CurrentCompany.CompId.ToString());

                                dtgodown = CommList.ListOfRecord("usp_Godown_DDL", para, "Common - FillGodownCombo");
                                if (CommList.Exception != null)
                                {
                                    MessageBox.Show(CommList.Exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    XMLString = "<NewDataSet>";
                                    for (int i = 0; i < dtgodown.Rows.Count; i++)
                                    {
                                        XMLString = XMLString + "<Table>";
                                        XMLString = XMLString + "<GodownID>" + Convert.ToInt32(dtgodown.Rows[i]["GodownID"]) + "</GodownID>";
                                        XMLString = XMLString + "</Table> ";
                                        Cnt       = Cnt + 1;
                                    }
                                    XMLString = XMLString + "</NewDataSet>";
                                }
                                //string newFileName = CurrentUser.DocumentPath + txtItemCode.Text.ToString().Replace('/', '-') + "-" + txtDocName.Text.ToString().Replace('/', '-');
                                string newFileName = txtDocName.Text.ToString().Replace('/', '-');
                                objItemBL.Insert(txtItemCode.Text, txtItemName.Text, txtOtherName.Text, txtSpecification.Text,
                                                 Convert.ToInt64(cmbUOM.SelectedValue), Convert.ToDecimal(txtprice.Text), txtProductCode.Text, txtHSN.Text, XMLString, Cnt,
                                                 Convert.ToDecimal(txtOpeningStock.Text), Convert.ToDecimal(txtReorderLevel.Text), txtLocation.Text, txtRackNo.Text, (int)cmbgodown.SelectedValue,
                                                 newFileName, Convert.ToInt64(cmbCurrency.SelectedValue)
                                                 );
                            }
                            else if (_Mode == (int)Common.Constant.Mode.Modify)
                            {
                                string newFileName = txtDocName.Text.ToString().Replace('/', '-');

                                objItemBL.Update(_ItemID, _StockID, txtItemCode.Text, txtItemName.Text, txtOtherName.Text, txtSpecification.Text,
                                                 Convert.ToInt64(cmbUOM.SelectedValue), Convert.ToDecimal(txtprice.Text), txtProductCode.Text, txtHSN.Text,
                                                 Convert.ToDecimal(txtOpeningStock.Text), Convert.ToDecimal(txtReorderLevel.Text), txtLocation.Text, txtRackNo.Text, (int)cmbgodown.SelectedValue,
                                                 newFileName, Convert.ToInt64(cmbCurrency.SelectedValue)
                                                 );
                            }

                            if (objItemBL.Exception == null)
                            {
                                if (objItemBL.ErrorMessage != "")
                                {
                                    lblErrorMessage.Text = objItemBL.ErrorMessage;
                                    txtItemName.Focus();
                                    ReturnValue = false;
                                }
                                else
                                {
                                    //if (_Mode == (int)Common.Constant.Mode.Insert)
                                    //{
                                    //string newFileName = CurrentUser.DocumentPath + txtItemCode.Text.ToString().Replace('/', '-') + "-" + txtDocName.Text.ToString().Replace('/', '-');
                                    //objItemBL.InsertQuotationDocument(_ItemID, txtItemCode.Text.ToString().Replace('/', '-') + "-" + txtItemCode.Text.ToString().Replace('/', '-'));

                                    string newFileName = txtDocName.Text.ToString().Replace('/', '-');
                                    if (objItemBL.Exception == null)
                                    {
                                        if (objItemBL.ErrorMessage == "")
                                        {
                                            //File.Copy(SelectedFileName, newFileName, true);
                                        }
                                    }
                                    //}

                                    ReturnValue = true;
                                }
                            }
                            else
                            {
                                MessageBox.Show(objItemBL.Exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                ReturnValue = false;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please select  Godown First.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            cmbgodown.Focus();
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Utill.Common.ExceptionLogger.writeException("Item Register", exc.StackTrace);
                MessageBox.Show(Utill.Common.CommonMessage.ExceptionMesg, "Exception");
            }
            return(ReturnValue);
        }